Differences between MySQL and Oracle's triggers and stored procedure syntax

Source: Internet
Author: User

Corrected a script, encountered some of the differences between the two databases, recorded:

Trigger:

Difference Mysql ORACLE Description
Create statements different Create Trigger ' AA ' before INSERT on ' BB '
For each row
Create or replace trigger AA
before insert or update or delete on BB
For each row
1.Oracle can trigger the Insert,delete,update event on a trigger.
MySQL each trigger supports only one event. In other words, each trigger needs to be split into 3 MySQL trigger at present.
Referencing new and old data is different Access to new data : Neo AA
Get old data : oidbb
Getting new data : : NewAA
Get old data : : older. BB
1.oracle multiple pairs of colons

Stored procedures:

Difference Mysql ORACLE Description
Create statements different DROP PROCEDURE IF EXISTS ' sd_user_p_add_usr ';
CREATE PROCEDURE AA(
AA varchar (+))
Create or Replace procedure AA(
varchar AA) is

1.oracle creation is relatively concise, MySQL must first execute the drop

2.mysql first variable re-type, Oracle opposite, and does not have to limit length

3. If you are number or VARCHAR2, you do not need to define the length. Otherwise the compilation cannot pass

Exception handling not the same DECLARE EXIT HANDLER for Aaexception
BEGIN
...
END;
EXCEPTION
When OTHERS Then
ROLLBACK;
....
1.mysql You cannot customize exceptions, and you need to define them when using internal exceptions
Calls are stored in different ways Call procedure (); procedure (); 1. Different calling methods

So how to willful delete triggers:

Declare
V_num number;

BEGIN

Select COUNT (0) into V_num from user_triggers where trigger_name = ' AA '; (Note case)

If V_num > 0 Then
Execute immediate ' DROP TRIGGER AA ';
End If;

END;

Differences between MySQL and Oracle's triggers and stored procedure syntax

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.