oracle的常用函式

2022-09-11 19:24:13 字數 1901 閱讀 1802

mod(y,x)取餘

select mod(9,2) from dual;  ---- 1

round(x,y)四捨五入,trunc(x,y)擷取函式,並不會產生進製

1

--四捨五入 , 值為23.4

2select

round(23.39,1) from

dual;3--

擷取函式 ,值為23.3

4select trunc(23.39,1) from dual;

oracle中預設的時間格式dd-mm-yyyy,oracle常用的日期和時間函式

to_char()-- 把日期或者數字轉換為字串

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

to_date()-- 把字串轉換為日期型別

select to_date('2018/7/7','yyyy/mm/dd') from dual;

add_months()-- 在當前日期增加相應月份後的日期,即使兩個日期的月份不同,oracle自動換算,轉換後的日期幾號不變

select add_months(sysdate,3) from dual;

當前日期是2018/7/7,增加3個月之後,日期變為2018/10/7

months_between()-- 兩個日期之間的月份數

--2018/1/1到2018/7/7的月份數,值為6

select trunc(months_between(sysdate, to_date('2018/1/1', 'yyyy-mm-dd')))

from dual;

last_day()-- 當前日期所在月份的最後一天

select last_day(sysdate) from dual;

next_day()-- 從當前日期得到未來星期幾的日期

select next_day(sysdate,'星期一') from dual;

lower()  , upper()  , initcap()

1

--全部轉化為小寫,結果smith

2select

lower('

smith

') from

dual; 3--

全部轉化為大寫,結果smith

4select

upper('

smith

') from

dual;5--

轉換為首字母大寫,其餘字母小寫,結果smith

6select initcap('

smith

') from dual;

length()-- 字串的長度

select length('smith') from dual; -- 5

concat()-- 字串拼接函式

select concat('hello ','would') from dual -- hello would

chr()-- 將ascii碼轉換為字元

select chr(65) from dual; -- a

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

Oracle常用的函式

1 把date資料轉為特定輸出型的字串 2 處理數字型資料 9相當於萬用字元 最終值是 日期 月數量,資料型別也是date型。一般月數量為負數,舉個例子 從employ表查詢列出來公司就職時間超過24年的員工名單,但是表中只有就職起始日期,所以需要用到這個函式了。select name,startd...