oracle常用語句 函式

2021-08-28 13:36:36 字數 1745 閱讀 2015

一、常用語句

1、更新:update 表名 set [欄位1]=[value1],[欄位2]=[value2] where [條件]

2、插入:insert into 表名 ([欄位1],[欄位2],[欄位3]) values([value1],[value2],[value3])

3、刪除資料:delete from 表名 where 條件  ——刪除記錄並不能釋放oracle裡被占用的資料塊表空間. 它只把那些被刪除的資料塊標成unused

truncate table 表名  ——可以釋放占用的資料塊表空間,但是不可回退

刪除表結構:drop table 表名 ——drop語句將刪除表的結構,被依賴的約束(constrain),觸發器(trigger),索引(index); 依賴於該錶的儲存過程/函式將保留,但是變為invalid狀態

區別:truncate 會釋放占用空間,而drop 和 delete不會。

速度:drop>truncate>dalete

4、建立檢視

create or replace view 檢視名 as sql語句

二、常用函式

日期轉字串

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

字串轉日期

select to_date('2018-01-01 13:14:20','yyyy-mm-dd hh24:mi:ss') from dual

trunc()函式處理日期

select trunc(sysdate) from dual;--2018/9/30 上午 12:00:00(00:00:00),返回當前時間

select trunc(sysdate,'y|yy|yyy|yyyy') from dual;--2018/1/1,返回當年第一天

select trunc(sysdate,'mm') from dual;--2018/9/1,返回當月的第一天

select trunc(sysdate,'d') from dual;--2018/9/30,返回當前星期的第一天,即星期天

select trunc(sysdate,'dd') from dual;--2018/9/30,返回當前日期,今天是2017/2/13

select trunc(sysdate ,'hh24') from dual;--2018/9/30 14:00:00,返回本小時的開始時間

select trunc(sysdate ,'mi') from dual;--2018/9/30 14:17:00,返回本分鐘的開始時間

trunc函式處理number型別數字

select trunc(123.567,2) from dual;--123.56,將小數點右邊指定位數後面的截去;

select trunc(123.567,-2) from dual;--100,第二個引數可以為負數,表示將小數點左邊指定位數後面的部分截去,即均以0記;

select trunc(123.567) from dual;--123,預設截去小數點後面的部分;

查詢當天的資料

select * from where time>=trunc(sysdate)

查詢當一天的資料

select * from where time>=trunc(sysdate-1)

order排序

select t.name from 表名 order by decode(t.name,'a','1','b','2','c','3',t.name)

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