ORACLE常用操作指南积累


字段修改

1、假设字段数据为空,则不管改为什么字段类型,可以直接执行: alter table tb modify (name nvarchar2(20)); 2、假设字段有数据,则改为nvarchar2(20)可以直接执行: alter table tb modify (name nvarchar2(20)); 3.新增字段 alter table 表名 add 新增字段名 (类型+长度); 案例 alter table DAILY_SALES_REVENUE add first_code VARCHAR2(10) ;

在某列后新增字段 Oracle在表中指定位置增加字段: 1. 新建别名表test2, 在指定位置添加列(占位置:d as pName)。 create table test2 as select d as pName, d from test 2. 清空新增字段的值。 update test2 set pName=null 3. 修改字段的类型。 alter table test2 modify(pName varchar2(20)) 4. 删除原来的表test。 drop table test 5. 重命名表为test。 rename test2 to test

1. 更新字段名称 alter table table_name rename column column_old to column_new; 2. 添加字段 alter table table_name add COLUMN_NAME varchar(10); 3. 删除字段 alter table table_name drop column COLUMN_NAME; 4. 添加字段并赋值 alter table table_name add COLUMN_NAME NUMBER(1) DEFAULT 1; 5. 修改字段值 update table_name set filedname = value where filedname = value; 6. 修改字段数据类型 alter table table_name modify filedname varchar2(20);

复制备份一个表

1:创建一个表new_table和old_table表结构一样(没有old_table的记录) create table new_table as select * from old_table where 1=0; 2:创建一个表new_table和old_table表结构一样(有old_table的记录) create table new_table as select * from old_table; 3:复制一个表数据到另一个表 insert into new_table select * from old_table;

各类查询

-- 查询 表被那个地方使用过 SELECT * from user_source a where upper(text) like '%表名%';   所有用户及其权限命令   1、查看所有用户 select * from dba_user; select * from all_users; select * from user_users; 2、查看用户系统权限 select * from dba_sys_privs; select * from all_sys_privs; select * from user_sys_privs; 3、查看用户对象权限 select * from dba_tab_privs; select * from all_tab_privs; select * from user_tab_privs; 4、查看所有角色 select * from dba_roles; 5、查看用户所拥有的角色 select * from dba_role_privs; select * from user_role_privs; 6、查看当前用户的缺省表空间 select username,default_tablespace from user_users; 7、查看某个角色的具体权限 grant connect,resource,create session,create view to TEST; 8、查看RESOURCE具有那些权限 用SELECT * FROM DBA_SYS_PRIVS WHERE GRANTEE='RESOURCE       索引操作

单索引 create index 索引名称 on table(column) 删除索引 drop index 索引名称 复合索引 create index WBSINDEX ON project_info(wbs,is_delete) 查询某张表中所有索引 select * from ALL_INDEXS where table_name = project_info 查询某张表加了索引的列 select * from ALL_IND_COLUMN where table_name = project_info

删除唯一索引 第一步 删除表与索引之间的联系 ALTER TABLE TABLENAME DROP CONSTRAINT PK_TABLENAME ; 第二步 执行删除索引语句 DROP INDEX PK_TABLENAME ; 第三步 若要重新创建索引则执行 create unique index PK_TABLENAME on TABLENAME (ID,NAME);