1. Create stored procedure statement is different
oracle
create or replace procedure P_ADD_FAC(
id_fac_cd IN ES_FAC_UNIT.FAC_CD%TYPE) as
copy
mysql
DROP PROCEDURE IF EXISTS `SD_USER_P_ADD_USR`;
create procedure P_ADD_FAC(
id_fac_cd varchar(100))
copy
1. If there is a stored procedure with the same name when creating a stored procedure, the old stored procedure will be deleted. Oracle uses create or replace. Mysql uses to delete the old stored procedure first, and then create a new stored procedure. 2. The oracle stored procedure can Defined in the package, can also be defined in the Procedures. If defined in the package, a package can contain multiple stored procedures and methods. If defined in the Procedures, multiple stored procedures cannot be defined in the stored procedure. Mysql stored procedure Multiple stored procedures cannot be defined in . 3. The string type in oracle can use varchar2. Mysql needs to use varchar 4. The length of parameter varchar in Oracle is not necessary, but the length of parameter varchar in Mysql is necessary, such as varchar(100)
2, the creation function statement is different
oracle
CREATE OR REPLACE FUNCTION F_ROLE_FACS_GRP(
ii_role_int_key IN SD_ROLE.ROLE_INT_KEY%TYPE
) RETURN VARCHAR2
copy
mysql
DROP FUNCTION IF EXISTS `SD_ROLE_F_ROLE_FACS_GRP`;
CREATE FUNCTION `SD_ROLE_F_ROLE_FACS_GRP`(
ii_role_int_key INTEGER(10)
) RETURNS varchar(1000)
copy
1. When creating a function, if there is a function with the same name, the old function will be deleted. Oracle uses create or replace. Mysql uses to delete the old function first, and then create a new function. 2. The oracle function can be defined in the package, or Can be defined in Functions. If defined in a package, a package can contain multiple stored procedures and functions. If defined in Functions, each function can only define one function. Mysql Functions cannot define multiple functions. 3. The oracle return value uses return. The Mysql return value uses returns.
3. The input parameters are written differently
oracle
1. procedure P_ADD_FAC(
id_fac_cd IN ES_FAC_UNIT.FAC_CD%TYPE)
2. function func_name(
gw_id in(out) varchar2 )
copy
mysql
1.create procedure P_ADD_FAC(
(in) id_fac_cd varchar(100))
2.create function func_name(
gw_id varchar(100))
copy
- Oracle stored procedure parameters can be defined as the field type of the table. Mysql stored procedure does not support this definition method. It is necessary to define the actual type and length of the variable.
- The oracle parameter type in/out/inout is written after the parameter name. The Mysql parameter type in/out/inout is written before the parameter name.
- The oracle parameter type in/out/inout must be written. If the Mysql parameter type is in, it can be omitted. If it is out or inout, it cannot be omitted. Note: The parameter specified in mysql as IN, OUT, or INOUT is only legal for PROCEDURE of. (FUNCTION parameters are always considered as IN parameters) The RETURNS clause can only be specified for FUNCTION, which is mandatory for functions. It is used to specify the return type of the function, and the function body must contain a RETURN value statement.
4. How to declare the package
oracle
create or replace package/package body package name
copy
mysql
Split into multiple stored procedures or functions
Oracle can create packages, which can contain multiple stored procedures and methods. Mysql does not have the concept of packages, and can create stored procedures and methods separately. Each stored procedure or method needs to be placed in a file. Example 1: Method naming SD_FACILITY_PKG.F_SEARCH_FAC to mysql SD_FACILITY_F_SEARCH_FAC in oracle Example 2: Process name SD_FACILITY_PKG.P_ADD_FAC to mysql SD_FACILITY_P_ADD_FAC in oracle
5. The stored procedure return statement is different
oracle
return;
copy
mysql
LEAVE proc; (proc 代表最外层的begin end)
copy
Oracle stored procedures and methods can use return to exit the current process and method. Mysql stored procedures can only use leave to exit the current stored procedure. Return cannot be used. Mysql methods can use return to exit the current method.
6. Stored procedure exception handling is different
oracle
EXCEPTION
WHEN OTHERS THEN
ROLLBACK ;
ov_rtn_msg := c_sp_name||'('|| li_debug_pos ||'):'||
TO_CHAR(SQLCODE)||': '||SUBSTR(SQLERRM,1,100);
copy
mysql
DECLARE EXIT HANDLER FOR SQLEXCEPTION
BEGIN
ROLLBACK ;
set ov_rtn_msg = concat(c_sp_name,'(', li_debug_pos ,'):',
TO_CHAR(SQLCODE),': ',SUBSTR(SQLERRM,1,100));
END;
copy
oracle: Internal exceptions do not need to be defined. After EXCEPTION is written at the end of the stored procedure or function, the following part is the part of exception handling. Oracle can define custom exceptions. Custom exceptions need to use the raise keyword to throw an exception before Can be caught in EXCEPTION.
mysql: Mysql internal exceptions also need to be defined first, and the exception function needs to be implemented at the same time. Currently mysql does not support custom exceptions.
7. The location of the declaration variable of the procedure and the function is different
oracle
声明变量在begin…end体之前
copy
mysql
声明变量在begin...end体内,begin之后其他任何内容之前
copy
8. NO_DATA_FOUND exception handling
oracle
EXCEPTION
WHEN NO_DATA_FOUND THEN
oi_rtn_cd := 1;
ov_rtn_msg := SD_COMMON.P_GET_MSG('DP-CBM-01100a-016',
li_sub_rtn_cd,
lv_sub_rtn_msg
);
copy
mysql
使用FOUND_ROWS()代替NO_DATA_FOUND. 详见注释.
copy
In oracle: NO_DATA_FOUND is an attribute of the cursor. When the select does not find the data, the exception of no data found will appear, and the program will not execute downward.
Mysql: There is no NO_DATA_FOUND attribute. But use the FOUND_ROWS() method to get the data queried by the select statement. If the value obtained by FOUND_ROWS() is 0, it will enter the exception handling logic.
9. Different ways of calling stored procedures in stored procedures
oracle
Procedure_Name(参数);
copy
mysql
Call Procedure_Name(参数);
copy
To call a stored procedure from a MYSQL stored procedure, you need to use the Call pro_name (parameter). Oracle calls a stored procedure and directly writes the stored procedure name.
10 Different ways of throwing exceptions
oracle
RAISE Exception_Name;
copy