Create a UDF in source mode of DB2

Source: Internet
Author: User

The source method of the DB2 custom function is created in the coolsql Editor: 1. Obtain the day of the current time.

Create function fmt_dt (timestamp) returns varchar (32) source day (timestamp) test: select fmt_dt (current datetime) from SYSIBM. sysdummy1 print: 10 * SYSIBM. sysdummy1 is the system table

 

2. format the date:
create function ts_fmt(TS timestamp, fmt varchar(100)) returns varchar(100) return with tmp (dd,mm,yyyy,hh,mi,ss,ms) as (     select day(ts),month(ts),     year(ts), hour(ts), minute(ts),     second (ts), microsecond(ts) from SYSIBM.sysdummy1 ) select      case fmt       when 'yyyymmdd'           then yyyy||mm||dd       when 'mm/dd/yyyy' then mm||'/'||dd||'/'||yyyy       when 'yyyy-mm-dd' then yyyy || '-' || mm || '-' || dd       when 'yyyy-mm-dd hh:mi:ss.ms'            then yyyy || '-' || mm || '-'                || dd || ' ' || hh || ':' || mi                || ':'|| ss || '.' || ms       else 'date format' || coalesce(fmt,'')||' not recognized'       end from tmp test: select ts_fmt(current timestamp,'ssyyyymmdd') from SYSIBM.sysdummy1 print : 2013-7-10 17:38:18.909000 

 


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.