Oracle常用指令碼 Script

來源:互聯網
上載者:User

1、查看當前所有對象

SQL> select * from tab;

2、建一個和a表結構一樣的空表

SQL> create table b as select * from a where 1=2;

SQL> create table b(b1,b2,b3) as select a1,a2,a3 from a where 1=2;

3、察看資料庫的大小,和空間使用方式

SQL> col tablespace format a20
SQL> select b.file_id檔案ID,
b.tablespace_name  資料表空間,
b.file_name 物理檔案名稱,
b.bytes 總位元組數,
(b.bytes-sum(nvl(a.bytes,0))) 已使用,
sum(nvl(a.bytes,0)) 剩餘,
sum(nvl(a.bytes,0))/(b.bytes)*100 剩餘百分比
from dba_free_space a,dba_data_files b
where a.file_id=b.file_id
group by b.tablespace_name,b.file_name,b.file_id,b.bytes
order by b.tablespace_name
/
dba_free_space --資料表空間剩餘空間狀況
dba_data_files --資料檔案空間佔用情況

4、查看現有復原段及其狀態

SQL> col segment format a30
SQL> SELECT SEGMENT_NAME,OWNER,TABLESPACE_NAME,SEGMENT_ID,FILE_ID,STATUS FROM DBA_ROLLBACK_SEGS;

5、查看資料檔案放置的路徑

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;

6、顯示當前串連使用者

SQL> show user

7、把SQL*Plus當計算機

SQL> select 100*20 from dual;

8、連接字串

SQL> select 列1||列2 from 表1;
SQL> select concat(列1,列2) from 表1;

9、查詢當前日期

SQL> select to_char(sysdate,'yyyy-mm-dd,hh24:mi:ss') from dual;

10、使用者間複製資料

SQL> copy from user1 to user2 create table2 using select * from table1;

11、視圖中不能使用order by,但可用group by代替來達到排序目的

SQL> create view a as select b1,b2 from b group by b1,b2;

12、通過授權的方式來建立使用者

SQL> grant connect,resource to test identified by test;

SQL> conn test/test


相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.