oracle数据库常用sql
2014-02-28 11:45
483 查看
######测试(避免执行整个文件),拼写要正确,关键字不区分大小写,内容区分大小写
--查看服务名
show parameter service_names;
--查看数据库实例名,
select instance_name from v$instance;
show parameter instance_name;
--查看数据库名
select name from v$database;
show parameter db_name;
--查看表结构、视图结构(在plsql下无法使用)
desc pm_user;
在sql下:select * from user_tab_columns where table_name='大写表名'
--查看当前登录用户
show user;
--查看当前用户的所有表
select * from tab;
--用sysdba帐号登录,查看所有user
select username from all_users;
--查看指定表空间下的所有表
select * from user_tables t where t.TABLESPACE_NAME = 'PM';
--查看当前用户的所有序列
select SEQUENCE_OWNER,SEQUENCE_NAME from dba_sequences where sequence_owner = 'PM';
--创建表
create table pm_consultation
( consultation_id number(19) not null,
consultation_code varchar2(50),
constraint pk_consultation_id primary key (consultation_id)
);
--添加表字段
alter table pm_consultation add(consultor_phone varchar2(20),replier_phone varchar2(20));
--删除表字段
alter table pm_consultation drop column consultor_phone;
--修改表字段
alter table pm_user rename column d_dept_level to dept_level;
--添加字段唯一约束
alter table vlan_info add constraint vlanTag_unique unique(vlanTag);
--删除字段唯一约束
alter table vlan_info drop constraint vlanTag_unique cascade;
--创建sequence,建议统一使用seq结尾
create sequence PM_USER_SEQ
minvalue 1
maxvalue 999999999999999999999
start with 1
increment by 1
nocache;
--sequence查看下一个值、sequence使用
select pm_user_seq.nextval from dual;
--删除sequence
DROP SEQUENCE PM_USER_SEQ;
--删除表
drop table pm_user;
--drop删除表是没有真正的删除,只是放到回收站
select * from recyclebin where type='TABLE';
--清空回收站
PURGE RECYCLEBIN;
--查询表的索引
select index_name,status,index_type,table_name from user_indexes where table_name='GBM_SEARCH_INDEX';
用sys帐号创建directory,并赋权给用户
select * from dba_directories;
create or replace directory pcloud_dmp as '/home/oracle';
GRANT READ,WRITE ON DIRECTORY pcloud_dmp TO pcloud;
--查看服务名
show parameter service_names;
--查看数据库实例名,
select instance_name from v$instance;
show parameter instance_name;
--查看数据库名
select name from v$database;
show parameter db_name;
--查看表结构、视图结构(在plsql下无法使用)
desc pm_user;
在sql下:select * from user_tab_columns where table_name='大写表名'
--查看当前登录用户
show user;
--查看当前用户的所有表
select * from tab;
--用sysdba帐号登录,查看所有user
select username from all_users;
--查看指定表空间下的所有表
select * from user_tables t where t.TABLESPACE_NAME = 'PM';
--查看当前用户的所有序列
select SEQUENCE_OWNER,SEQUENCE_NAME from dba_sequences where sequence_owner = 'PM';
--创建表
create table pm_consultation
( consultation_id number(19) not null,
consultation_code varchar2(50),
constraint pk_consultation_id primary key (consultation_id)
);
--添加表字段
alter table pm_consultation add(consultor_phone varchar2(20),replier_phone varchar2(20));
--删除表字段
alter table pm_consultation drop column consultor_phone;
--修改表字段
alter table pm_user rename column d_dept_level to dept_level;
--添加字段唯一约束
alter table vlan_info add constraint vlanTag_unique unique(vlanTag);
--删除字段唯一约束
alter table vlan_info drop constraint vlanTag_unique cascade;
--创建sequence,建议统一使用seq结尾
create sequence PM_USER_SEQ
minvalue 1
maxvalue 999999999999999999999
start with 1
increment by 1
nocache;
--sequence查看下一个值、sequence使用
select pm_user_seq.nextval from dual;
--删除sequence
DROP SEQUENCE PM_USER_SEQ;
--删除表
drop table pm_user;
--drop删除表是没有真正的删除,只是放到回收站
select * from recyclebin where type='TABLE';
--清空回收站
PURGE RECYCLEBIN;
--查询表的索引
select index_name,status,index_type,table_name from user_indexes where table_name='GBM_SEARCH_INDEX';
用sys帐号创建directory,并赋权给用户
select * from dba_directories;
create or replace directory pcloud_dmp as '/home/oracle';
GRANT READ,WRITE ON DIRECTORY pcloud_dmp TO pcloud;
相关文章推荐
- Oracle安装(3)快速搭建Data Gurad之物理standby
- schema in oracle
- Oracle SQL性能优化(转)
- 【转载】Oracle:connect_by_isleaf,start with...connect by prior
- oracle中prior的用法,connect by prior,树形目录
- Oracle 11g R2 for Win7旗舰版(64位)的安装步骤
- Oracle修改表结构语句
- windows server 2008 x86 sp2安装oracle10g(10.2.0.4) 报错
- [oracle]删除一张表中重复数据,保留其id字段最小的sql
- oracle恢复删除的表和数据
- [转]oracle 11g 忘记 默认用户密码
- oracle pl/sql 入门+ 数组使用+游标+动态SQL
- linux设定自启动服务(oracle为例)
- Oracle新建用户、角色、授权
- Oracle新建用户、角色、授权
- Oracle数据导入导出imp/exp命令
- oracle 存储过程
- oracle同时添加多个字段-案例
- Oracle数据库导入导出
- Oracle INS-3205 (解决oracle在安装过程中出现的问题)