ORACLE 經常使用腳本(1)

1. 查看oracle的版本信息:  Select version FROM Product_component_version
  Where SUBSTR(PRODUCT,1,6)='Oracle';

2. 查看數據庫庫對象: select owner, object_type, status, count(*) count# from all_objects group by owner, object_type, status;

3. 查看數據庫的建立日期和歸檔方式: Select Created, Log_Mode, Log_Mode From V$Database;

4. 查看當前全部對象: select * from tab;

5. 建一個和a表結構同樣的空表:
 create table b as select * from a where 1=2;
 create table b(b1,b2,b3) as select a1,a2,a3 from a where 1=2;

6. 查看數據文件放置的路徑: select  tablespace_name,file_id,bytes/1024/1024,file_name from dba_data_files order by file_id;

7. 鏈接字符串
 select 列1||列2 from 表1;
 select concat(列1,列2) from 表1;

8. 查詢當前日期
 select to_char(sysdate,'yyyy-mm-dd,hh24:mi:ss') from dual;

9. 用戶間複製數據
 copy from user1 to user2 create table2 using select * from table1;

10. 視圖中不能使用order by,但可用group by代替來達到排序目的
 create view a as select b1,b2 from b group by b1,b2;

11. 經過受權的方式來建立用戶
 grant connect,resource to test identified by test;
 conn test/test
相關文章
相關標籤/搜索