Simple implementation of several ORACLE functions in MYSQL

Source: Internet
Author: User


We do not need to migrate data from ORACLE to MYSQL. Below I have written three simple MYSQL functions. For your reference. Is it time? [SQL] DELIMITER $ USE 'ytt' $ DROP FUNCTION IF exists' is _ date' $ CREATE DEFINER = 'root' @ 'localhost' FUNCTION 'is _ date '( f_in CHAR (19 )) returns tinyint (4) BEGIN -- Created by david. yang 2012/8/9. IF UNIX_TIMESTAMP (f_in) = 0 then return 0; else return 1; end if; END $ DELIMITER; www.2cto.com determines IF it is a number? [SQL] DELIMITER $ USE 'ytt' $ DROP FUNCTION IF exists' is _ number' $ CREATE DEFINER = 'root' @ 'localhost' FUNCTION 'is _ number '( f_in VARCHAR (255 )) returns tinyint (4) label1: BEGIN -- Created by david. yang 2012/8/9. DECLARE cnt int unsigned default 0; DECLARE I INT UNSIGNED DEFAULT 1; DECLARE j INT UNSIGNED DEFAULT 0; SET cnt = LENGTH (f_in); loop1: WHILE I <cnt do set j = ASCII (SUBSTR (f_in, I, 1); IF j <48 OR j> 57 then return 0; LEAVE label1; end if; SET I = I + 1; END WHILE loop1; RETURN 1; END $ www.2cto.com DELIMITER; MYSQL Implementation of ORACLE to_date function. [SQL] DELIMITER $ USE 'ytt' $ DROP FUNCTION IF exists' to _ date' $ CREATE DEFINER = 'root' @ 'localhost' FUNCTION 'to _ date '( f_date VARCHAR (30 ), f_format VARCHAR (30) returns varchar (30) CHARSET utf8 BEGIN -- '20-08-2011 22:55:02 ', 'dd-mm-yyyy hh24: mi: ss' -- '02-11-2011 ', 'dd-mm-yyyy' -- Created by david. yang 2012/8/9. DECLARE I _year CHAR (4); www.2cto.com DECLARE I _month CHAR (2); DECLARE I _day CHAR (2); DECLARE I _time CHAR (8); SET I _year = SUBSTR (f_date, 7, 4 ); SET I _month = SUBSTR (f_date, 4,2); SET I _day = LEFT (f_date, 2); if length (f_date) = 10 then set I _time = ''; else set I _time = RIGHT (f_date, 8); end if; return concat (I _year, '-', I _month, '-', I _day, '', I _time ); END $ DELIMITER;

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.