search
HomeDatabaseMysql TutorialMySQL and Oracle Difference Comparison 3 Functions

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
图文详解mysql架构原理图文详解mysql架构原理May 17, 2022 pm 05:54 PM

本篇文章给大家带来了关于mysql的相关知识,其中主要介绍了关于架构原理的相关内容,MySQL Server架构自顶向下大致可以分网络连接层、服务层、存储引擎层和系统文件层,下面一起来看一下,希望对大家有帮助。

mysql的msi与zip版本有什么区别mysql的msi与zip版本有什么区别May 16, 2022 pm 04:33 PM

mysql的msi与zip版本的区别:1、zip包含的安装程序是一种主动安装,而msi包含的是被installer所用的安装文件以提交请求的方式安装;2、zip是一种数据压缩和文档存储的文件格式,msi是微软格式的安装包。

mysql怎么去掉第一个字符mysql怎么去掉第一个字符May 19, 2022 am 10:21 AM

方法:1、利用right函数,语法为“update 表名 set 指定字段 = right(指定字段, length(指定字段)-1)...”;2、利用substring函数,语法为“select substring(指定字段,2)..”。

mysql怎么替换换行符mysql怎么替换换行符Apr 18, 2022 pm 03:14 PM

在mysql中,可以利用char()和REPLACE()函数来替换换行符;REPLACE()函数可以用新字符串替换列中的换行符,而换行符可使用“char(13)”来表示,语法为“replace(字段名,char(13),'新字符串') ”。

mysql怎么将varchar转换为int类型mysql怎么将varchar转换为int类型May 12, 2022 pm 04:51 PM

转换方法:1、利用cast函数,语法“select * from 表名 order by cast(字段名 as SIGNED)”;2、利用“select * from 表名 order by CONVERT(字段名,SIGNED)”语句。

MySQL复制技术之异步复制和半同步复制MySQL复制技术之异步复制和半同步复制Apr 25, 2022 pm 07:21 PM

本篇文章给大家带来了关于mysql的相关知识,其中主要介绍了关于MySQL复制技术的相关问题,包括了异步复制、半同步复制等等内容,下面一起来看一下,希望对大家有帮助。

mysql怎么判断是否是数字类型mysql怎么判断是否是数字类型May 16, 2022 am 10:09 AM

在mysql中,可以利用REGEXP运算符判断数据是否是数字类型,语法为“String REGEXP '[^0-9.]'”;该运算符是正则表达式的缩写,若数据字符中含有数字时,返回的结果是true,反之返回的结果是false。

带你把MySQL索引吃透了带你把MySQL索引吃透了Apr 22, 2022 am 11:48 AM

本篇文章给大家带来了关于mysql的相关知识,其中主要介绍了mysql高级篇的一些问题,包括了索引是什么、索引底层实现等等问题,下面一起来看一下,希望对大家有帮助。

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.