日期:2014-05-16  浏览次数:20503 次

oracle 常用命令(适合初学者)

?? 1:查询表及用户
???? select table_name from all_tables;//所有的表名
?  select table_name from user_all_tables;//当前用户的所有的表
?  一下是转贴的sql语句的帖子.
?  select * from user_objects;   //查询所有的表
?  select * from dba_tables;   //查询所有的表
?  select * from all_tables;   //查询所有的表
?  select * from user_users   //查出一个用户
?  select * from all_users   //查询所有用户
?  select * from dba_users   //查询所有用户
?  select name,dbid from v$database;   //查询数据库名和它的ID
?  select * from sys.user_tab_columns; //查询表名 ,并显示列名
?  describe 表名   //查询表结构
?  select * from sys.user_tab_columns where table_name=表名 //查询指定表名的字段
? 2: 查询数据库参数
?  show parameter db;
? 3:查询数据库的实例名
?  select instance_name from v$instance;
? 4: 数据库域名
?  数据库安装结束后,如果要知道正在运行额数据库是否有域名以及数据库域名名称可以用
?  select value from v$parameter where name='db_domain'
?  show parameter domain
? 5:数据库服务名
?  如果数据库有域名,则数据库服务名就是全局数据库名,如果该数据库没有定义域名,则数据库服务名与数据库名相同
?  show parameter service_name
? 6:显示当前用户
?  show user
? 7:直接登陆
?  sqlplus "/as sysdba"
? 8:当前ORACLE系统时间
?  select sysdate from dual;
?? 9:查询数据库字典v$nls_parameter产看字符集相关参数
?  select * from v$nls_parameters;
?  //*************
oracle基本操作语句(适合初学者)
?  oracle操作语句:
  1.创建表
?  create table 表名(
?  列名1 类型,
?  列名2 类型
?  );
  2.修改类属性
?  alter table 表名 modify(列名 类型);
  3.添加列
?  alter table 表名 add(列名 类型);
  4.添加主键约束和非空约束
?  alter table 表名 add constraint pk_表名 primary key(列名);
?  alter table 表名 modify(列名 not null);
  5.删除主键约束
?  alter table 表名 drop primary key;
?  alter table 表名 drop constraint pk_表名;
  6.失效约束
?  alter table 表名 disable primary key;
?  alter table 表名 disable constraint pk_表名;
  7.有效约束
?  alter table 表名 enable primary key;
?  alter table 表名 enable constraint pk_表名;
  8.删除列
?  alter table 表名 drop column 列名;
  9.设置某列不可用,然后删除
?  alter table 表名 set unused(列名);
?  alter table 表名 drop unused columns;
? 10.修改表名
?  rename 表名1 to 表名2
?  alter 表名1 rename to 表名2;
?? 11.截断表
?  truncate table 表名;
? 12.截断表保留行空间
?  truncate table 表名 resue storage;
? 13.查看表结构
?  desc table 表名;
? 14.删除表
?  drop table 表名;
? 15.插入记录
?  例:insert into 表名 values(内容1,内容2,内容3,内容4);
? 16.带参数对话方式插入行
?  例:insert into 表名 values(&列名1,&列名2);
?  insert into 表名 values(内容1,内容2);
? 17.插入某几列记录
?  insert into 表名(列名1,列名2) values(内容1,内容2);
? 18.为列插入空值(其列不能为not null)
?  insert into 表名 values(内容1,null,null);
? 19.创建表(包括主键及外键设置)方法一
?  create table 表名(
?  列名1 类型
?  constraint pk_表名 primary key,
?  列名2 类型 not null,
?  列名3 类型
?  constraint fk_表名 reference 表名(列名),
?  列名3 类型
?  constraint ck_表名 check(列名3 in(''内容1'',''内容2'',''内容3''))
?  );
? 20.查询所有行
?  select * from 表名;
? 21.查询某几列
?  select 列名1,列名2 from 表名;
? 22.重复行消除
?  select distict 列名 from 表名;
? 23.where语句查询
?  select * from 表名 where 条件 order by 列名;
?  (注:如number类型查出自动按升序排列,如要按降序排列,则select * from 表名 where 条件 order by 列名 desc;)
?? 24.创建表,方法二
?  create table 表名(
?  列名1 类型 primary key,
?  列名2 类型 not null,
?  列名3 类型 check(列名3 in('''','''','''')),
?  列名4 类型 refernce 表名(列名)
?  );
? 25.修改 列=‘?’的数据
?  update 表名 set (列=?) where 列=‘?’;
? 26.删除行
?  delete from 表名 where 条件;
? 27.事务处理
?  --事务处理
?  update 表名
?  set 列名(日期) = ''30-5月-98''
?  where 条件;
?  savepoint mark1;
?  delete from 表名 where 条件;
?  savepoint mark2;
?  rollback to savepoint mark1;
?  rollback;
? 28.建立用户user1,密码为password
?  授予用户connect,resource的权限
?  connect角色用于登录
?  resource角色用于建表等.
?  connect system/manager
?  create user user1 identified by password;
?  grant connect,resource to password;
? 29.数据控制语言
?  alter user scott account unlock identified by tiger;?//将scott用户解锁并修改密码。

???????connect scott/tiger?????????????????? 连接scott用户。

???????
? 30.把对表1查询和修改的权限授予user1
?  grant select,update on 表1 to