No. |
Category |
Oracle |
MySQL |
Note |
1 |
The statement for creating a stored procedure is different. |
Create or replace procedure p_add_fac ( Id_fac_cd in es_fac_unit.fac_cd % type) is |
Drop procedure if exists 'sd _ user_p_add_usr '; Create procedure p_add_fac ( Id_fac_cd varchar (100 )) |
1. If a stored procedure with the same name exists during the creation of the stored procedure, the old stored procedure will be deleted. Oracle uses create or replace. MySQL deletes the old stored procedure before creating a new stored procedure. 2. oracle stored procedures can be defined in a package or procedures. if it is defined in a package, a package can contain multiple stored procedures and methods. if it is defined in procedures, multiple stored procedures cannot be defined in the stored procedure. Multiple stored procedures cannot be defined in the MySQL stored procedure. 3. varchar2. MySQL needs to use varchar 4. The length of the varchar parameter in Oracle is not required, The length of the varchar parameter in MySQL is required, for example, varchar (100) |
2 |
Different function creation statements |
Create or replace function f_role_facs_grp ( Ii_role_int_key in sd_role.role_int_key % Type ) Return varchar2 |
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) |
1. If a function with the same name exists during function creation, the old function will be deleted. Oracle uses create or replace. MySQL deletes the old function first, and then creates a new function. 2. oracle functions can be defined in a package or in functions. if defined in a package, a package can contain multiple stored procedures and functions. if it is defined in functions, each function can only define one function. MySQL functions cannot define multiple functions. 3. Return the Oracle return value using return. The MySQL return value is returns. |
3 |
The input parameters are written differently. |
Procedure p_add_fac ( Id_fac_cd in es_fac_unit.fac_cd % type) |
Create procedure p_add_fac ( (IN) id_fac_cd varchar (100 )) |
1. Oracle stored procedure parameters can be defined as the Field Type of the table. MySQL stored procedures do not support this definition method. You need to define the actual type and length of the variable. 2. The Oracle parameter types in/out/inout are written after the parameter name. MySQL parameter types in/out/inout are written before the parameter name. 3. Oracle parameter types in/out/inout must be written. MySQL parameter type can be omitted if it is in. If it is out or inout, it cannot be omitted. Note: In, out, or inout is valid only for procedure. (Function parameters are always considered as in parameters.) The returns clause can only be used to specify the function. This is mandatory for the function. It is used to specify the return type of the function, and the function body must contain a return value statement.
|
Function func_name ( Gw_id in (out) varchar2) |
Create Function func_name ( Gw_id varchar (100 )) |
4 |
Package declaration method |
Create or replace package/package body package name |
Split into multiple stored procedures or functions |
Oracle can create packages that contain multiple stored procedures and methods. MySQL does not have the package concept. You can create stored procedures and methods separately. Each stored procedure or method must be stored in a file. Example 1: Method naming Sd_facility_pkg.f_search_fac in Oracle To MySQL sd_facility_f_search_fac Example 2: Process naming Sd_facility_pkg.p_add_fac in Oracle To MySQL sd_facility_p_add_fac
|
5 |
Different Stored Procedure return statements |
Return; |
Leave proc; (Proc represents the in end of the outermost layer) |
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 procedures. return cannot be used. MySQL method can exit the current method using return. |
6 |
Exception Handling in stored procedures is different |
Exception When others then Rollback; Ov_rtn_msg: = c_sp_name | '(' | li_debug_pos | '):' | To_char (sqlcode) | ':' | substr (sqlerrm, 1,100 ); |
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; |
ORACLE: Internal exceptions do not need to be defined. After an exception is written at the end of a stored procedure or function, the subsequent part is the exception handling part. oracle can define custom exceptions. Custom exceptions can be captured only when an exception is thrown using the raise keyword.
MySQL: MySQL internal exceptions also need to be defined first. At the same time, exceptions must be implemented. Currently, MySQL does not support custom exceptions. |
7 |
The positions of declared variables for procedures and functions are different. |
Declare variables in begin... Before end |
Declare variables in the begin... end body, before any other content after begin |
|
8 |
No_data_found Exception Handling |
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 ); |
Use found_rows () instead of no_data_found. For more information, see note. |
ORACLE: No_data_found is an attribute of the cursor. If no data is found in the SELECT statement, no data found exception will occur, and the program will not run down.
MySQL: There is no no_data_found attribute, but the data queried by the SELECT statement is obtained using the found_rows () method. If the value obtained by found_rows () is 0, the exception handling logic is entered. |
9 |
Different Methods for calling stored procedures in Stored Procedures |
Procedure_name (parameter ); |
Call procedure_name (parameter ); |
For MySQL stored procedures to call stored procedures, call pro_name (parameter) is required ). Oracle calls the stored procedure and directly writes the stored procedure name. |
10 |
The exception throwing method is different. |
Raise prediction_name; |
See Remarks |
See section 2.5 MySQL Exception Handling in <2009002-otmpps-difficult Questions-0001.doc> |