您的位置:首页 > 数据库 > Oracle

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;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: