ORACLE自增函數,一般函數

來源:互聯網
上載者:User

標籤:class   fun   出現   sysdate   限制   serve   TE   逗號   取整   

1.UNIX時間與普通時間互相轉換

1.ORACLE先建立函數方法,再直接使用,MySQL直接使用方法UNIX_TIMESTAMP,FROM_UNIXTIME

oracle_to_unix(create_date)
create or replace function oracle_to_unix(in_date in date) return number isbegin  return((in_date - to_date(‘19700101‘, ‘yyyymmdd‘)) * 86400 -         to_number(substr(tz_offset(sessiontimezone), 1, 3)) * 3600);end oracle_to_unix;
unix_to_oracle(create_date)
create or replace function unix_to_oracle(in_number number) return date isbegin  return (to_date(‘19700101‘,‘yyyymmdd‘) + in_number/86400  + to_number(substr(tz_offset(sessiontimezone),1,3))/24);end unix_to_oracle;
Exp:
SELECT *  FROM (SELECT mobile,               /*UNIX_TIMESTAMP(create_date) as create_date,*/               /*to_timestamp(create_date, ‘yyyy-mm-dd hh24:mi:ss‘) as create_date,*/               /*to_timestamp(create_date) as create_date,*/               oracle_to_unix(create_date)  as create_date,               code,               code_status,               uuid        /*top (1)*/          FROM R_CHECK_CODE         WHERE code_status = ‘0‘           and mobile = ‘138******‘        /*and rownum<=1*/         order by create_date desc) s where rownum <= 1
2.顯示資料數量限制

MYSQL:

   select * from tbl limit 100;

ORACLE:

  select * from tbl where rownum<=100;

SQL SERVER:

  select top 100 * from tbl

3.小數取整

ORACLE:取整函數trunc():

  trunc(12.354),傳回值12

  trunc(12.354,1),傳回值12.3

  trunc(12.354,-1),傳回值10

MYSQL:數值處理函數floor與round

  floor:函數只返回整數部分,小數部分捨棄。

  round:函數四捨五入,大於0.5的部分進位,不到則捨棄。與floor不同。

4.擷取目前時間

ORACLE:sysdate  加括弧容易出現錯誤:缺少逗號

MySQL:sysdate()

ORACLE自增函數,一般函數

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.