Oracle 常用語句列表

2021-08-11 19:37:49 字數 1828 閱讀 6837

1.複製表結構及其資料

create

table table_name_new as

select * from table_name_old

2.只複製表結構

create

table table_name_new as

select * from table_name_old where

1=2;

3.只複製表資料

如果兩個表結構一樣:

insert

into table_name_new select * from table_name_old

如果兩個表結構不一樣:

insert

into table_name_new(column1,column2...) select column1,column2... from table_name_old

4.如何統計兩個表的記錄總數?

select (select

count(id) from aa)+(select

count(id) from bb) 總數 from dual;

--總數那是沒有單引號的,雙引號可以。

5.返回大於等於n的最小整數值?

select

ceil(n) from dual;

6.返回當前月的最後一天?

select last_day(sysdate) from dual;
7.如何查詢重覆記錄?

select * from table_name where rowid!=(select

max(rowid) from table_name where table_name.col1=d.col1 and table_name.col2=d.col2);

8.如何刪除重覆記錄?

delete

from table_name where rowid!=(select

max(rowid) from table_name d where table_name.col1=d.col1 and table_name.col2=d.col2);

9.表

檢視使用者下所有的表 

select * from user_tables;

檢視名稱包含log字元的表

select object_name,object_id from user_objects

where instr(object_name,'log')>0;

檢視某錶的建立時間

select object_name,created from user_objects where object_name=upper('&table_name');

檢視某錶的大小

select sum(bytes)/(1024*1024) as "size(m)" from user_segments

where segment_name=upper('&table_name');

檢視放在oracle的記憶體區里的表

select table_name,cache from user_tables where instr(cache,'y')>0;

10.序列號

檢視序列號,last_number是當前值

select * from user_sequences;

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...