Home Database Mysql Tutorial MySQL and Oracle Difference Comparison 3 Functions

MySQL and Oracle Difference Comparison 3 Functions

Jan 17, 2017 am 11:48 AM

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 of this Website
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

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)
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Will R.E.P.O. Have Crossplay?
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

MySQL: An Introduction to the World's Most Popular Database MySQL: An Introduction to the World's Most Popular Database Apr 12, 2025 am 12:18 AM

MySQL is an open source relational database management system, mainly used to store and retrieve data quickly and reliably. Its working principle includes client requests, query resolution, execution of queries and return results. Examples of usage include creating tables, inserting and querying data, and advanced features such as JOIN operations. Common errors involve SQL syntax, data types, and permissions, and optimization suggestions include the use of indexes, optimized queries, and partitioning of tables.

Why Use MySQL? Benefits and Advantages Why Use MySQL? Benefits and Advantages Apr 12, 2025 am 12:17 AM

MySQL is chosen for its performance, reliability, ease of use, and community support. 1.MySQL provides efficient data storage and retrieval functions, supporting multiple data types and advanced query operations. 2. Adopt client-server architecture and multiple storage engines to support transaction and query optimization. 3. Easy to use, supports a variety of operating systems and programming languages. 4. Have strong community support and provide rich resources and solutions.

MySQL's Place: Databases and Programming MySQL's Place: Databases and Programming Apr 13, 2025 am 12:18 AM

MySQL's position in databases and programming is very important. It is an open source relational database management system that is widely used in various application scenarios. 1) MySQL provides efficient data storage, organization and retrieval functions, supporting Web, mobile and enterprise-level systems. 2) It uses a client-server architecture, supports multiple storage engines and index optimization. 3) Basic usages include creating tables and inserting data, and advanced usages involve multi-table JOINs and complex queries. 4) Frequently asked questions such as SQL syntax errors and performance issues can be debugged through the EXPLAIN command and slow query log. 5) Performance optimization methods include rational use of indexes, optimized query and use of caches. Best practices include using transactions and PreparedStatemen

How to create oracle dynamic sql How to create oracle dynamic sql Apr 12, 2025 am 06:06 AM

SQL statements can be created and executed based on runtime input by using Oracle's dynamic SQL. The steps include: preparing an empty string variable to store dynamically generated SQL statements. Use the EXECUTE IMMEDIATE or PREPARE statement to compile and execute dynamic SQL statements. Use bind variable to pass user input or other dynamic values ​​to dynamic SQL. Use EXECUTE IMMEDIATE or EXECUTE to execute dynamic SQL statements.

How to create cursors in oracle loop How to create cursors in oracle loop Apr 12, 2025 am 06:18 AM

In Oracle, the FOR LOOP loop can create cursors dynamically. The steps are: 1. Define the cursor type; 2. Create the loop; 3. Create the cursor dynamically; 4. Execute the cursor; 5. Close the cursor. Example: A cursor can be created cycle-by-circuit to display the names and salaries of the top 10 employees.

How to use triggers for oracle How to use triggers for oracle Apr 11, 2025 pm 11:57 PM

Triggers in Oracle are stored procedures used to automatically perform operations after a specific event (insert, update, or delete). They are used in a variety of scenarios, including data verification, auditing, and data maintenance. When creating a trigger, you need to specify the trigger name, association table, trigger event, and trigger time. There are two types of triggers: the BEFORE trigger is fired before the operation, and the AFTER trigger is fired after the operation. For example, the BEFORE INSERT trigger ensures that the age column of the inserted row is not negative.

How to connect to the database of apache How to connect to the database of apache Apr 13, 2025 pm 01:03 PM

Apache connects to a database requires the following steps: Install the database driver. Configure the web.xml file to create a connection pool. Create a JDBC data source and specify the connection settings. Use the JDBC API to access the database from Java code, including getting connections, creating statements, binding parameters, executing queries or updates, and processing results.

How to open a database in oracle How to open a database in oracle Apr 11, 2025 pm 10:51 PM

The steps to open an Oracle database are as follows: Open the Oracle database client and connect to the database server: connect username/password@servername Use the SQLPLUS command to open the database: SQLPLUS

See all articles