Oracle常用SQL及命令

2021-09-01 23:32:11 字數 2473 閱讀 6875

1.啟動和關閉監聽lsnrctl start 和 lsnrctl stop

2.啟動和關閉資料庫  startup 和shutdown

3.啟動sqlplus   sqlplus /nolog  退出  quit

4.登陸oracle conn/connect username/password [as sysdba]

5.新建或者修改檢視 create or replace view v_*** as select a,b,c from t_***;

6.重新命名列 alter table t_*** rename column ***_1 to ***_2;

7.刪除使用者 drop user *** cascade;

8.建立使用者並指定表空間 create user *** identified by default tablespace ts_*** temporary tablespace ts_xx;

如果該使用者需要在該錶空間建立表等操作還需要授權。  grant unlimited tablespace to ***;否則會報ora-01950: 對錶空間『ts_***』無許可權

9.授權給使用者***:  grant connect/dba/resource to ***;取消授權使用者:revoke connect/dba/resource from ***;

10.指定.sql檔案 start "d:/***.sql" 或者 @"d:/***.sql"

11.授權給使用者  grant create session,create any table,create any index, create any view, create any procedure ,

alter any table, alter any procedure,

drop any table, drop any procedure, drop any view, drop any index, drop any procedure,

select any table, insert any table, update any table, delete any table to ***;

12.檢視所用使用者 select * from dba_users;

select * from all_users;

select * from user_users;

13.建立表並指定表空間 create table lm_city 

id  number,

city_id number,

city_name varchar2(50),

city_name_pinyin varchar2(100),

update_time timestamp default sysdate

tablespace zw1840;

14.在某個表中建立唯一索引:create unique index index_*** on t_***(column_***);

15.在某個表中建立主鍵:  alter table t_*** add constraint pk_*** primary key (column_***);乙個表只能有乙個主鍵,也只能有乙個long型別字段。(主鍵和unique都會順帶建立unique索引)

16.在某個表中新增外來鍵:  alter table t_*** add constraint fk_*** foreign key (column_***) references tn_*** (column_xx) [on delete set null/cascade];

17.在某個表中新增unique: alter table t_*** add constraint uk_*** unique (column_***);

18.預設時間sysdate;  date to char: to_char(date,'格式'),e.g. to_char(sysdate,'yyyy-mm-dd hh24:mi:ss');char to date to_date(txt,'格式')

19.修改某個表某一列的預設值: alter table t_*** modify column_*** default ***; e.g. alter table lm_city modify update_time detault sysdate;

20.某個表中增加一列:alter table t_*** add col_*** number(20);

21.檢視乙個表的表結構describe t_***; describe 為命令,不是sql關鍵字,如在command window 下面執行 describe user_source。

22.使用者建立的儲存過程或者函式均在該使用者下的user_source表中。檢視儲存過程的** select text from user_source where name = 'sp_***';

22.更改某一字段的型別:alter table t_*** modify col_*** type;需要說明的是,clob和varchar不能直接更改,需要新增中間字段,重新命名的方式實現。

oracle常用的sql命令

檢視使用者和預設表空間的關係 select username,default tablespace from dba users 檢視當前使用者能訪問的表 select from user tables oracle查詢使用者表 select from user all tables oracle查...

oracle常用sql及函式總結

一.dao層入庫到資料庫系統和當前時間不一致的問題 to char sysdate,yyyy mm dd hh24 mi ss 總結 yyyy 表示 年份,mm 表示 月份,dd 表示 天,hh24 表示 小時,mi 表示 分鐘 ss 表示 秒,to char sysdate,yyyy mm dd ...

常用SQL命令

create table 表名 列名 資料型別 長度 列名 資料型別 長度 主鍵 create table 表名 列名 資料型別 長度 primary key,自增主鍵 create table 表名 列名 資料型別 長度 primary key auto increment,非空約束 create...