-- 去重: distinct
--利用當前emp表復制一份新表(包含資料):
create table emp2 as select * form emp;
-- 利用當前emp表復制一份新表(只復制表結構):
create teble emp3 as select * from emp where 1=2;
--表別名,拼接操作 'A' || B --> 將A拼接到B的前面:
select 'E' || e.empno eno , e.ename myName from emp e;
--replace() 替換操作:
select replace('hello','1','中') from dual;
--length() 回傳長度 :
select length('hellow world') from dual;
--substr() 截取字串:
select substr('123456') from fual;
--instr() :
select instr('hello world ','w','1','2') from dual; (查找hello world 第2次出現w的數字位置)
--round() 不保留小數
select round(1000.1) from dual; -- 1000
--保留小數round ( 引數 , 保留幾位小數 ):
select round(998.982, 2) from dual ; -- 998.98
--截取小數: trunc(n)
--向上取整: cell(n)
--向下取整: floor(n)
--取余: mod(m,n) ==>m對n取余
-- 日期函式
select sysdate from dual;
-- months_between回傳兩個日期間的月數
select months_between(sysdate,hiredate) from emp;
select hiredate from emp;
-- add_months() 回傳所加月數后的最后日期
select add_months(sysdate,3) from dual;
-- next_day回傳下一個星期的星期幾
select next_day(sysdate,'星期一') from dual;
-- last_day() 回傳日期中的最后一天
select last_day(sysdate)from dual;
/*
轉換函式
*/
-- to_char
select to_char(sysdate,'YYYY') from dual;
select to_char(e.hiredate,'YYYY-mm-dd hh24:mi:ss dy') from emp e;
-- 數字轉換
select to_char(123456,'999999')from dual; -- 123456
select to_char(123456,'99')from dual; -- ###
select to_char(123456,'L999999')from dual; -- ¥123456
select to_char(123456,'$999999')from dual; -- $123456
select to_char(123456,'0999999')from dual; -- 0123456
-- to_date 將字符轉換為日期,多用于更新表
update emp e set e.hiredate=to_date('2008-08-12','yyyy-mm-dd')
-- to_number 將數字的字串型別轉換為數字型別
select to_number('09') + to_number('10') from dual; -- 19
-- nvl() nvl2() coalese
Oracle中的 nvl() ,nvl2(), coalese()函式
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/140290.html
標籤:其他
下一篇:途牛旅游專案環境搭建
