--返回n1除n2的餘數,如果n2=0則返回n1的值
select mod(2,5) from dual;
--round(n1[,n2]) 返回四捨五入小數點右邊n2位後n1的值,n2預設值為0,如果n2為負數就捨入到小數點左邊相應的位上
select round(23.56),round(23.56,1),round(23.56,-1) from dual;
--trunc(n1[,n2] 返回截尾到n2位小數的n1的值,n2預設設定為0,當n2為預設設定時會將n1截尾為整數,如果n2為負值,就截尾在小數點左邊相應的位上。
select trunc(23.56),trunc(23.56,1),trunc(23.56,-1) from dual;
--指定字串內字元變為小寫/大寫
select lower('what is this') from dual
select upper('this is what') from dual;
--返回指定長度=n的字串
select lpad('what is this',5),lpad('what is this',25),lpad('what is this',25,'-') from dual;
select rpad('what is this',5),rpad('what is this',25),rpad('what is this',25,'-') from dual;
--去除空格
select trim(' what is this ') from dual;
select trim('w' from 'what is this w w') from dual;
select trim(leading 'w' from 'what is this w w') from dual;
select trim(trailing 'w' from 'what is this w w') from dual;
select trim(both 'w' from 'what is this w w') from dual; --跟第乙個一樣
--從字串c1左側擷取掉與指定字串c2相同的字元並返回 沒有搞明白
select ltrim('wwhhhhhat is this w w','ah') from dual;
select rtrim('wwhhhhhat is this w w','w h') from dual;
--替換
select replace('wwhhhhhat is this w w','w','-') from dual;
select translate('what is this',' ','-') from dual;
select translate('what is this','-','') from dual;
select translate('what is this',' ',' ') from dual;
select translate('what is this','ait','-*') from dual;
--神奇的函式啊,該函式返回字串引數的語音表示形式,對於比較一些讀音相同,但是拼寫不同的單詞非常有用
select soundex('dog'),soundex('boy') from dual;
--擷取字串
select substr('what is this',5,3) from dual;
select substr('what is this',-5,3) from dual;
select substr('what is this',1,-33) from dual;
--字元型函式返回數字值
select instr('abcdefg','e',-3),instr('abcdefg','e',3) from dual;
select length('abcdefg') from dual;
--日期
select add_months(sysdate,12),add_months(sysdate,-12) from dual;
alter session set nls_date_format = 'mm-dd-yyyy' ;
select current_date from dual
select sysdate,current_date from dual;
select last_day(sysdate) from dual;
select next_day(sysdate,2) from dual;
select next_day(sysdate,4) from dual;
select months_between(sysdate, sysdate), months_between(sysdate, add_months(sysdate, -1)),
months_between(sysdate, add_months(sysdate, 1))
from dual;
select round(sysdate,'hh24') from dual;
select round(sysdate) from dual;
select trunc(sysdate,'hh24') from dual;
select trunc(sysdate) from dual;
--轉換函式
select to_char('aabbcc') from dual;
select to_char(sysdate,'yyyy-mm-dd hh24:mi:ss') from dual;
select to_char(-100, 'l99g999d99mi') from dual;
select to_date(5373483, 'j') from dual;
select to_date('2007-8-23 23:25:00', 'yyyy-mm-dd hh24:mi:ss') from dual;
select to_char(to_date('9999-12-31','yyyy-mm-dd'),'j') from dual;
select to_number('-100.00', '9g999d99') from dual;
--輔助函式greatest
select decode('a2','a1','true1','a2','true2','default') from dual;
select greatest(15,5,75,8) "greatest" from dual;
select least(15,5,75,8) least from dual;
select nullif('a','b'),nullif('a','a') from dual;
select nvl(null, '12') from dual;
select nvl2('a', 'b', 'c') isnull,nvl2(null, 'b', 'c') isnotnull from dual;
select sys_context('userenv', 'session_user') from dual;
select ceil(18.2) from dual;
select chr(95) from dual;
select ascii('_') from dual;
select concat('aa','bb') from dual;
select initcap('what is this') from dual;
select nls_initcap('中華minzhu') from dual
select current_timestamp(3) from dual;
select localtimestamp(3) from dual;
select systimestamp(4) from dual;
select dbtimezone from dual;
select to_timestamp('2007-8-22', 'yyyy-mm-dd hh:mi:ss') from dual;
select user from dual;
select vsize('abc中華') from dual
ORACLE常用函式的使用方法
oracle常用函式的使用方法 1.字串函式 1 length 獲取字元長度 select length 中國 from platform metainfo tables where table name xmbm 2 lengthb 獲取位元組長度 select lengthb 中國 from p...
Oracle 常用的函式
常用的偽列有rowid和rownum select rowid,orders.from orders orders表的結果 create table orders c1 number 5 not null,c10 number 20 not null,c20 varchar2 20 not null...
Oracle常用的函式
1 判斷表是否存在 create or replace function public f is table exist v table en name character varying 8000 char returns integer as i count int default 0 begi...