找數(shù)據(jù)庫(kù)中所有字段 以對(duì)應(yīng)的表
select C.column_name,C.TABLE_NAME from dba_tab_columns C where owner='' 查每個(gè)科目class 分?jǐn)?shù)scro前三名 select id, name, class, scro from (select row_number() over(partition by class order by scro desc) cnt, id, name, class, scro from student) a where a.cnt <= 3; 查找排序后的前三行 select * from (select rw.*, rownum from (select * from student d where d.class = 'b' order by d.scro desc) rw where rw.id >= 1 order by rw.class desc) n where rownum <= 3 表復(fù)制 insert into table_a (id,name,age) select b.id,b.name,b.age from table_b; --刪除表數(shù)據(jù)的觸發(fā)器 CREATE OR REPLACE PROCEDURE delete_data IS BEGIN delete from test ; COMMIT; EXCEPTION WHEN NO_DATA_FOUND THEN NULL; WHEN OTHERS THEN RAISE; END delete_data; --定時(shí)刪除 每隔5分鐘執(zhí)行一次的計(jì)劃 DECLARE X NUMBER; BEGIN SYS.DBMS_JOB.SUBMIT ( job => X ,what => 'delete_data;' ,next_date => to_date('25/08/2008 00:00:00','dd/mm/yyyy hh24:mi:ss') ,interval => 'sysdate+1/24/12' ,no_parse => FALSE ); SYS.DBMS_OUTPUT.PUT_LINE('Job Number is: ' || to_char(x)); COMMIT; END; --查看當(dāng)前oracle計(jì)劃 select job,next_date,next_sec,failures,broken from user_jobs; --刪除一個(gè)job begin dbms_job.remove(46);--46為job號(hào) end; --給新表插入舊表對(duì)應(yīng)字段的所有數(shù)據(jù) insert into aaa(id,name) select b.id,b.name from bbb; 文章搜索: 【點(diǎn)擊打包該文章】 【到本站論壇,與同行交流】 select * from all_users; ##查看所有用戶(hù) select name from v$database; ##查看當(dāng)前數(shù)據(jù)庫(kù) database test; ##進(jìn)入test數(shù)據(jù)庫(kù) select * from v$instance; ##查看所有的數(shù)據(jù)庫(kù)實(shí)例 shutdown immediate ##關(guān)閉數(shù)據(jù)庫(kù) alter user sys identified by new_password; ##更改用戶(hù)密碼 select username,password from dba_users; ##查看當(dāng)實(shí)例中的用戶(hù)和密碼 show parameter control_files; ## 查看控制文件; select member from v$logfile; ##查看日志文件 show parameter ; ## 查看數(shù)據(jù)庫(kù)參數(shù) select * from user_role_privs; ##查看當(dāng)前用戶(hù)的角色 select username,default_tablespace from user_users; ##查看當(dāng)前用戶(hù)的缺省表空間 alter user system identified by [password] ##修改用戶(hù)的密碼 ALTER USER "SCOTT" ACCOUNT UNLOCK ##解鎖SCOTT用戶(hù) show parameter processes; ##查看最大會(huì)話數(shù) 查看當(dāng)前庫(kù)的所有數(shù)據(jù)表: SQL> select TABLE_NAME from all_tables; select * from all_tables; SQL> select table_name from all_tables where table_name like ‘u’; TABLE_NAME———————————————default_auditing_options 查看表結(jié)構(gòu):desc all_tables; 創(chuàng)建用戶(hù)并賦予權(quán)限 ###----------------------------創(chuàng)建用戶(hù)并賦予權(quán)限------------------------------------####- create user mpss identified by "mpss12" default tablespace TS_MPSS_DATA temporary tablespace TEMP; 給用戶(hù)賦予權(quán)限 grant connect to mpss; grant resource,create session to mpss; 開(kāi)發(fā)角色 grant create procedure to dbuser,; #這些權(quán)限足夠用于開(kāi)發(fā)及生產(chǎn)環(huán)境 給用戶(hù)授權(quán) grant dba to spms;--授予DBA權(quán)限 grant unlimited tablespace to lxg;--授予不限制的表空間 grant select any table to lxg;--授予查詢(xún)?nèi)魏伪? grant select any dictionary to lxg;--授予 查詢(xún) 任何字典 刪除用戶(hù) drop user mpss cascade; 建表空間 ###---------------------------------建表空間------------------------------------####- ================建立表空間============================ CREATE TABLESPACE "TS_MPSS_DATA" LOGGING DATAFILE '/mpss/data/ts_mpss_data.dbf' SIZE 1024M EXTENT MANAGEMENT LOCAL SEGMENT SPACE MANAGEMENT AUTO ===================================================== =================建立臨時(shí)表空間============================ CREATE TEMPORARY TABLESPACE "SWVIP" TEMPFILE '/app/oracle/oradata/ sworacle/SWVIP.dbf' SIZE 5M EXTENT MANAGEMENT LOCAL UNIFORM SIZE 1M ===================================================== create tablespace TS_MPSS_DATA datafile '/mpss/data/ts_mpss_data.bdf ' size 1024m autoextend on ; ###autoextend on 自動(dòng)擴(kuò)展 ###------------------------------------------------------------------------------------####- 查看表空間 ###----------------------------查看表空間大小------------------------------------####- SELECT D.TABLESPACE_NAME "Name", TO_CHAR(((((A.BYTES - DECODE(F.BYTES, NULL, 0, F.BYTES)) / 1024 / 1024)) /(A.BYTES / 1024 / 1024))*100,'99,990.9') "used(%)", TO_CHAR((DECODE(F.BYTES, NULL, 0, F.BYTES) / 1024 / 1024),'999,990.9') "Free (M)" FROM SYS.DBA_TABLESPACES D, SYS.SM$TS_AVAIL A, SYS.SM$TS_FREE F WHERE D.TABLESPACE_NAME = A.TABLESPACE_NAME AND F.TABLESPACE_NAME (+) = D.TABLESPACE_NAME; ###--------------------------------------------------------------------------------------####- SELECT D.TABLESPACE_NAME,SPACE "SUM_SPACE(M)",BLOCKS SUM_BLOCKS,SPACE-NVL(FREE_SPACE,0) "USED_SPACE(M)", ROUND((1-NVL(FREE_SPACE,0)/SPACE)*100,2) "USED_RATE(%)",FREE_SPACE "FREE_SPACE(M)" FROM (SELECT TABLESPACE_NAME,ROUND(SUM(BYTES)/(1024*1024),2) SPACE,SUM(BLOCKS) BLOCKS FROM DBA_DATA_FILES GROUP BY TABLESPACE_NAME) D, (SELECT TABLESPACE_NAME,ROUND(SUM(BYTES)/(1024*1024),2) FREE_SPACE FROM DBA_FREE_SPACE GROUP BY TABLESPACE_NAME) F WHERE D.TABLESPACE_NAME = F.TABLESPACE_NAME(+) UNION ALL --if have tempfile SELECT D.TABLESPACE_NAME,SPACE "SUM_SPACE(M)",BLOCKS SUM_BLOCKS, USED_SPACE "USED_SPACE(M)",ROUND(NVL(USED_SPACE,0)/SPACE*100,2) "USED_RATE(%)", NVL(FREE_SPACE,0) "FREE_SPACE(M)" FROM (SELECT TABLESPACE_NAME,ROUND(SUM(BYTES)/(1024*1024),2) SPACE,SUM(BLOCKS) BLOCKS FROM DBA_TEMP_FILES GROUP BY TABLESPACE_NAME) D, (SELECT TABLESPACE_NAME,ROUND(SUM(BYTES_USED)/(1024*1024),2) USED_SPACE, ROUND(SUM(BYTES_FREE)/(1024*1024),2) FREE_SPACE FROM V$TEMP_SPACE_HEADER GROUP BY TABLESPACE_NAME) F WHERE D.TABLESPACE_NAME = F.TABLESPACE_NAME(+) ; 查看表空間物理文件的名稱(chēng)及大小; ###--------------------表空間物理文件的名稱(chēng)及大小------------------------####- select tablespace_name, file_id, file_name, round(bytes/(1024*1024),0) total_space from dba_data_files order by tablespace_name; ###------------------------------------------------------------------------------------####- 查看數(shù)據(jù)文件放置的路徑 ###------------------------------------------------------------------------------------####- SQL> col file_name format a50 SQL> select tablespace_name,file_id,bytes/1024/1024,file_name from dba_data_files order by file_id; ###------------------------------------------------------------------------------------####- 查看數(shù)據(jù)庫(kù)庫(kù)對(duì)象 select owner, object_type, status, count(*) count# from all_objects group by owner, object_type, status; 用系統(tǒng)管理員,,查看當(dāng)前數(shù)據(jù)庫(kù)有幾個(gè)用戶(hù)連接: SQL> select username,sid,serial# from v$session; 擴(kuò)表空間 ###------------------------------------------------------------------------------------####- alter tablespace G000 add datafile '/dev/vgbilling/rg000_lv03' SIZE 7500m; 給表G000增加一個(gè)7500m的邏輯卷'/dev/vgbilling/rg000_lv03' ###------------------------------------------------------------------------------------####- 檢查被長(zhǎng)時(shí)間鎖的對(duì)象 ###------------------------------------------------------------------------------------####- SQL>select a.session_id,a.process,a.locked_mode,b.object_name,b.object_type,b.status from v$locked_object a,dba_objects b where a.object_id=b.object_id; ###------------------------------------------------------------------------------------####- 文章出處:http://www./course/7_databases/oracle/Oracleshl/200899/141376.html sys用戶(hù)登陸 創(chuàng)建表空間: SQL> create tablespace lmsstemp datafile 'F:\ORADATA\LMSS\LMSSTEMP01.DBF' SIZE 1 024M extent management local; 給表空間增加數(shù)據(jù)文件 alter tablespace lmsstemp add datafile 'F:\ORADATA\LMSS\LMSSTEMP02.DBF' SIZE 1 024M; 更改表空間為自動(dòng)擴(kuò)展 SQL> alter database datafile 'F:\ORADATA\LMSS\LMSSTEMP01.DBF' autoextend on; 查看表空間信息 SQL> select file_name,tablespace_name,autoextensible from dba_data_files; 授權(quán): create any table to leon -- Create the user (用sys執(zhí)行) create user xx identified by xx123 default tablespace lmss temporary tablespace TEMP profile DEFAULT; -- Grant/Revoke role privileges (用sys執(zhí)行) grant connect to xx; --創(chuàng)建視圖給hy用戶(hù)(用leon用戶(hù)) create or replace view view_tableName as select column,。,。。 from table; -- Grant/Revoke object privileges grant select, update on RES_XIM_CARD to hy; --創(chuàng)建同義詞 create synonym RES_XIM_CARD for YY.RES_XIM_CARD ; |
|
來(lái)自: 布蘭道 > 《我的圖書(shū)館》