Oracle 常用語句

2021-09-25 04:38:48 字數 3942 閱讀 9876

連線本地oracle

sqlplus / as sysdba
2.連線遠端oracle

sqlplus fia_aims_jj_hxjj/fia_aims_jj_hxjj@
很多時候我們用擁有dba許可權的使用者 從oracle資料庫匯出資料,那麼再匯入新的資料庫時就還得需要dba許可權的使用者,下面是如何建立乙個新使用者並授予dba許可權命令。

1.用有dba許可權的使用者登入:sys使用者

sqlplus / as sysdba
2、建立表空間:

create tablespace oracle_test datafile 『g:\oracle11g_64bit\data\oracle_test.dbf』 size 500m autoextend on next 50m maxsize unlimited;
3.建立乙個新使用者:

create user user_one identified by 1234 default tablespace oracle_test;

注:oracle 12c建立使用者的時候要以c##開頭。

4.授予dba許可權: 

grant connect,resource,dba to user_one ;
ok,建立好了,就可以用user_one 這個使用者登入了,user_one 使用者擁有dba許可權。

select * from dba_users; 檢視資料庫裡面所有使用者,前提是你是有dba許可權的帳號,如sys,system

select * from all_users; 檢視你能管理的所有使用者!

select * from user_users; 檢視當前使用者資訊 !

5.刪除使用者 

drop user username cascade;
6.通過當前日期建立使用者:

declare 

v_date varchar2(8);--定義日期變數

v_sql varchar2(2000);--定義動態sql

v_tablename varchar2(20);--定義動態表名

begin

select to_char(sysdate,'yyyymmdd') into v_date from dual;--取日期變數

v_tablename := 't_'||v_date;--為動態表命名

v_sql := 'create user '||v_tablename||'  identified by 123456';--為動態sql賦值

dbms_output.put_line(v_sql);--列印sql語句

execute immediate v_sql;--執行動態sql

end;

執行結果:

1、用sysdba賬號登入資料庫,然後查詢到要更改的使用者資訊:

select user#,name from user$;
2、更改使用者名稱並提交:

update user$ set name='portal' where user#=88;

commit;

3、強制重新整理:

alter system checkpoint;

alter system flush shared_pool;

4、更新使用者的密碼:

alter user portal identified by 123;
1、匯入語句

imp username/password@ip/sid file="imp檔案路徑" log="輸出log路徑(可以沒有)" full=y ignore=y
2、匯出語句

資料匯出:

1 將資料庫test完全匯出,使用者名稱system 密碼manager 匯出到d:\daochu.dmp中

exp system/manager@test file=d:\daochu.dmp full=y

2 將資料庫中system使用者與sys使用者的表匯出

exp system/manager@test file=d:\daochu.dmp owner=(system,sys)

3 將資料庫中的表table1 、table2匯出

exp system/manager@test file=d:\daochu.dmp tables=(table1,table2) 

4 將資料庫中的表table1中的字段filed1以"00"打頭的資料匯出

exp system/manager@test file=d:\daochu.dmp tables=(table1) query=\" where filed1 like '00%'\"

11g預設建立乙個表時不分配segment,只有在插入資料時才會產生(當然也可以強制分配),以節省磁碟空間。

解決方法:

1、解決方法

查詢空表語句:

select 'alter table '||table_name||' allocate extent;' from user_tables where num_rows=0;
執行查詢結果,通過plsql在進行匯出。

更新語句

更新表中的所有屬性,前面加1

update dict_dept set ddtname = '1'  || ddtname
更新表中所有屬性,把1替換為空的字串

update dict_dept t set ddtname = replace(ddtname,'1','')
oracle序列建立和使用建立序列

語法 create sequence 序列名 [相關引數]

引數說明

increment by :序列變化的步進,負值表示遞減。(預設1)

start with:序列的初始值 。(預設1)

maxvalue:序列可生成的最大值。(預設不限制最大值,nomaxvalue)

minvalue:序列可生成的最小值。(預設不限制最小值,nominvalue)

cycle:用於定義當序列產生的值達到限制值後是否迴圈(nocycle:不迴圈,cycle:迴圈)。

cache:表示快取序列的個數,資料庫異常終止可能會導致序列中斷不連續的情況,預設值為20,如果不使用快取可設定nocache

create sequence seq_demo increment by 1 start with 1 nomaxvalue nocycle nocache;
修改、刪除序列

使用 alter 命令進行修改

使用 drop 命令刪除

序列的使用

currval 表示序列的當前值,新序列必須使用一次nextval 才能獲取到值,否則會報錯

nextval 表示序列的下乙個值。新序列首次使用時獲取的是該序列的初始值,從第二次使用時開始按照設定的步進遞增

查詢序列的值:

select seq_name.[currval,nextval] from dual;
檢視所有已建立的序列:

select * from user_sequences
sql語句中使用:

insert into table (id) values (seq_name.nextval)
文件會持更新........

oracle 常用語句

oracle 產看表空間 select total.name tablespace name free space,total space free space used space,total space from select tablespace name,sum bytes 1024 102...

oracle常用語句

drop tablespace crm online space including contents and datafiles 刪除表空間 drop user wuliu01 cascade 刪除使用者 exp orcl file d dmp 匯出資料庫 imp orcl file e alen...

oracle 常用語句

oracle 常用語句 查詢表的大小 select t.owner,t.segment name,sum t.blocks 8 1024 m as s,t.segment type from dba segments t where t.owner user name group by t.owne...