Home  >  Article  >  Database  >  MySQL and Oracle Difference Comparison 3 Functions

MySQL and Oracle Difference Comparison 3 Functions

黄舟
黄舟Original
2017-01-17 11:48:011284browse

MySQL and Oracle Difference Comparison Function Three

Function

Number Category ORACLE MYSQL Comment

1 Numeric function round(1.23456,4) round(1.23456,4) Same as:
ORACLE: select round(1.23456,4) value from dual
MYSQL: select round(1.23456,4) value

2 abs(-1) abs( -1) Function: Take the absolute value of the current data
Usage: The usage of oracle and mysql is the same
mysql: select abs(-1) value
oracle: select abs(-1) value from dual

3 ceil(-1.001)) ceiling(-1.001) Function: Return the smallest integer not less than X
Usage:
mysqls: select ceiling(-1.001) value
oracle: select ceil(-1.001) value from dual

4 floor(-1.001) floor(-1.001) Function: Return the maximum integer value not greater than X
Usage:
mysql: select floor (-1.001) value
oracle: select floor(-1.001) value from dual

5 Max(expr)/Min(expr) Max(expr)/Min(expr) Function: Return the minimum or maximum value of expr. MIN() and MAX() can accept a string argument; in this
case, they will return the minimum or maximum string passed down.
Usage:
ROACLE: select max(user_int_key) from sd_usr;
MYSQL: select max(user_int_key) from sd_usr;

6 String function ascii(str) ascii(str) Function :Returns the ASCII code value of the leftmost character of the string str. If str is an empty string,
The return value is 0. If str is a NULL, the return value is also NULL.
Usage:
mysql:select ascii('a') value
oracle:select ascii('a') value from dual

7 CHAR(N,...) CHAR(N,...) Function: CHAR() interprets parameters in integer type and returns the characters
given by the ASCII code value represented by the integer. string. NULL values ​​will be ignored.
Usage:
mysql:select char(97) value
oracle:select chr(97) value from dual

8 REPLACE( str,from_str,to_str) REPLACE(str,from_str,to_str) Function: All occurrences of the string from_str in the string str are replaced by to_str, and then the string is returned.
Usage:
mysql: SELECT REPLACE ('abcdef', 'bcd', 'ijklmn') value
oracle: SELECT Replace('abcdef', 'bcd', 'ijklmn') value from dual


9 INSTR('sdsq','s',2) INSTR('sdsq','s') The number of parameters is different
ORACLE: select INSTR('sdsq','s',2) value from dual (Required to start from position 2)
MYSQL: select INSTR('sdsq','s') value (start from the default position 1)

10 SUBSTR('abcd',2,2) substring ('abcd',2,2) Function names are different:
ORACLE: select substr('abcd',2,2) value from dual
MYSQL: select substring('abcd',2,2) value

11 instr('abcdefg','ab') locate('ab','abcdefg') The function names are different:
instr -> locate (note: the location of the substring of locate and the total string To exchange)
ORACLE: SELECT instr('abcdefg', 'ab') VALUE FROM DUAL
MYSQL: SELECT locate('ab', 'abcdefg') VALUE

12 length(str ) char_length() function names are different:
ORACEL: SELECT length('AAAASDF') VALUE FROM DUAL
MYSQL: SELECT char_length('AAAASDF') VALUE

13 REPLACE('abcdef', ' bcd', 'ijklmn') REPLACE('abcdef', 'bcd', 'ijklmn') Same as:
ORACLE: SELECT REPLACE('abcdef', 'bcd', 'ijklmn') value from dual
MYSQL : SELECT REPLACE('abcdef', 'bcd', 'ijklmn') value

14 LPAD('abcd',14, '0') LPAD('abcd',14, '0') Same as:
ORACLE: select LPAD('abcd',14, '0') value from dual
MYSQL: select LPAD('abcd',14, '0') value from dual

15 UPPER (iv_user_id) UPPER(iv_user_id) Same as:
ORACLE: select UPPER(user_id) from sd_usr;
MYSQL: select UPPER(user_id) from sd_usr;

16 LOWER(iv_user_id) LOWER(iv_user_id) Same as:
ORACLE: select LOWER(user_id) from sd_usr;
MYSQL: select LOWER(user_id) from sd_usr;

##17 Control flow function nvl(u.email_address, 10) IFNULL(u.email_address, 10)

or
ISNULL(u.email_address) Function names are different (select according to different functions):
ORACLE: select u.email_address , nvl(u.email_address, 10) value from sd_usr u (if u.email_address=NULl, replace its value with 10 in DB)
MYSQL: select u.email_address, IFNULL(u.email_address, 10) value from sd_usr u (if u.email_address=NULl, the displayed result is 10, instead of replacing its value with 10 in the DB)
select u.email_address, ISNULL(u.email_address) value from sd_usr u (if u. If email_address is NULL, it will display 1, otherwise it will display 0)

18 DECODE(iv_sr_status,g_sr_status_com, ld_sys_date, NULL) None, please use IF or CASE statement instead.

IF Statement format: (expr1, expr2, expr3) Description:
1. decode(condition, value 1, translation value 1, value 2, translation value 2,... value n, translation value n, default value)
The meaning of this function is as follows:
IF condition = value 1 THEN
RETURN (translation value 1)
ELSIF condition = value 2 THEN
RETURN (translation value 2)
... ...
ELSIF condition = value n THEN
RETURN (translation value n)
ELSE
RETURN (default value)
END IF

2. mysql If syntax Description
Function: If expr1 is TRUE (expr1 <> 0 and expr1 <> NULL), the return value of IF() is expr2;
Otherwise, the return value is expr3. The return value of IF() is a numeric value or a string value, depending on the context in which it is located.
Usage:
mysql: SELECT IF(1>2,2,3);


19 Type conversion function TO_CHAR(SQLCODE) date_format/ time_format Function names are different

SQL> select to_char(sysdate,'yyyy-mm-dd') from dual;

SQL> select to_char(sysdate,'hh24-mi-ss') from dual;
mysql> select date_format(now(),' %Y-%m-%d');
mysql> select time_format(now(),'%H-%i-%S');

20 to_date(str,format) STR_TO_DATE( str,format) Function names are different:

ORACLE: SELECT to_date('2009-3-6','yyyy-mm-dd') VAULE FROM DUAL

MYSQL: SELECT STR_TO_DATE('2004-03-01' , '%Y-%m-%d') VAULE

21 trunc(-1.002) cast(-1.002 as SIGNED) Function names are different:

The date value truncated by the TRUNC function for the specified element .

ORACLE: select trunc(-1.002) value from dual
MYSQL:select cast(-1.002 as SIGNED) value
MYSQL:
Character set conversion: CONVERT(xxx USING gb2312)
Type The conversion is the same as SQL Server, but the type parameters are a little different: CAST(xxx AS type), CONVERT(xxx, type), the type must use the following types:

Available types
Binary, with The effect of binary prefix: BINARY
Character type, can take parameters: CHAR()
Date: DATE
Time: TIME
Date and time type: DATETIME
Floating point number: DECIMAL
Integer : SIGNED
Unsigned integer : UNSIGNED

22 TO_NUMBER(str) CAST("123" AS SIGNED INTEGER) Function names are different

ORACLE:SELECT TO_NUMBER('123') AS VALUE FROM DUAL;

MYSQL: SELECT CAST("123" AS SIGNED INTEGER) as value;
SIGNED INTEGER: signed integer

23 Date function SYSDATE now() / SYSDATE() Different writing methods:

ORACLE:select SYSDATE value from dual

MYSQL:select now() value
select sysdate() value

24 Next_day(sysdate,7) Customize a function: F_COMMON_NEXT_DAY(date,int) The function names are different:

ORACLE: SELECT Next_day(sysdate,7) value FROM DUAL

MYSQL: SELECT F_COMMON_NEXT_DAY(SYSDATE(), 3) value from DUAL;
(3: refers to the index value of the week) return The specified date immediately following the next week

25 ADD_MONTHS(sysdate, 2) DATE_ADD(sysdate(), interval 2 month) Function names are different:

ORACLE: SELECT ADD_MONTHS(sysdate, 2) as value from DUAL;

MYSQL: SELECT DATE_ADD(sysdate(), interval 2 month) as value from DUAL;

26 Subtract 2 dates (D1-D2) DATEDIFF(date1,date2) Function: Return the number of days between two dates.
Usage:
mysql: SELECT DATEDIFF('2008-12-30','2008-12-29') AS DiffDate
oracle: Directly subtract two dates (such as d1-d2=12.3 )

27 SQL function SQLCODE There is no corresponding function in MYSQL, but SQLException in JAVA. The getErrorCode() function can obtain the error number. Oracle's built-in functions SQLCODE and SQLERRM are specially used in the OTHERS processor to return Oracle's error code and error message respectively.
MYSQL: You can get the error code, error status and error message from JAVA

28 SQLERRM There is no corresponding function in MYSQL, but SQLException in JAVA. The getMessage() function can obtain the error message. Oracle's built-in functions SQLCODE and SQLERRM are specially used in the OTHERS processor to return Oracle's error code and error message respectively.
MYSQL: You can get the error code, error status and error message from JAVA

29 SEQ_BK_DTL_OPT_INT_KEY.NEXTVAL Automatic growth column In MYSQL, it is an automatic growth column. The following method is used to obtain the latest ID:
START TRANSACTION ;
INSERT INTO user(username,password)
VALUES (username,MD5(password));
SELECT LAST_INSERT_ID() INTO id;
COMMIT;

30 SUM(enable_flag ) SUM(enable_flag) Same as:
ORCALE: SELECT SUM(enable_flag) FROM SD_USR;
MYSQL: SELECT SUM(enable_flag) FROM SD_USR;

31 DBMS_OUTPUT.PUT_LINE(SQLCODE) None in MYSQL The corresponding method is to print in the console for testing and has no impact on migration. dbms_output.put_line can only display 255 characters per line. If it exceeds, an error will be reported


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn