Oracle Auto-increment function, general function

Source: Internet
Author: User

1.UNIX time and normal time conversion to each other

1.ORACLE first create a function method, then directly use, MySQL direct use method unix_timestamp,from_unixtime

Oracle_to_unix (Create_date)
Create or Replace functionOracle_to_unix (in_dateinchDatereturn  Number  isbegin  return((in_date-To_date ('19700101','YYYYMMDD'))* 86400 -To_number (substr (Tz_offset (sessiontimezone),1,3))* 3600);EndOracle_to_unix;
Unix_to_oracle (Create_date)
Create or Replace functionUnix_to_oracle (In_number Number)returnDate isbegin  return(To_date ('19700101','YYYYMMDD')+In_number/86400  +To_number (substr (Tz_offset (Sessiontimezone),1,3))/ -);EndUnix_to_oracle;
Exp:
SELECT *   from(SELECTMobile,/*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) ascreate_date, code, code_status, UUID/*Top (1)*/           fromR_check_codeWHERECode_status= '0'            andMobile= '138******'        /*and rownum<=1*/         Order  byCreate_datedesc) swhereRowNum<= 1
2. Display Data quantity limit

Mysql:

SELECT * from TBL limit 100;

ORACLE:

SELECT * from TBL where rownum<=100;

SQL SERVER:

Select Top * from TBL

3. Fractional rounding

ORACLE: Rounding function trunc ():

Trunc (12.354), return value 12

Trunc (12.354,1), return value 12.3

Trunc (12.354,-1), return value 10

MYSQL: Numeric processing function floor and round

Floor: The function returns only the integer part, and the fractional part is discarded.

Round: Function rounding, part rounding greater than 0.5, discarding if not. different from floor.

4. Get the current time

Oracle:sysdate parentheses are prone to errors: missing commas

Mysql:sysdate ()

Oracle Auto-increment function, general function

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.