Determines whether the record is empty in the oracle trigger

Source: Internet
Author: User

I started to write a trigger to determine the value of the MASTER_SESS_ID FIELD IN THE SSO_SP_LIST table and
Whether the record with the same value as the MASTER_SESS_ID field of the deleted record in the table is empty. I select the MASTER_SESS_ID field of the record and put the variable v (field MASTER_SESS_ID type) to judge if v is not null, if the result v is null, an error occurs when the trigger is executed.

So I changed the variable to an integer and asked it to return the count value of the record to determine whether the value is greater than 0. OK. The trigger ran as I thought.

Trigger with the original error:

Create or replace trigger TIG_BEF_DELETE_SSO_MASTERS
BEFORE DELETE
ON SSO_MASTERS_INF

FOR EACH ROW
DECLARE
V SSO_SP_LIST.MASTER_SESS_ID % TYPE
BEGIN
UPDATE SSO_MASTERS_HIS SET SSO_MASTERS_HIS.TIME_EXIT = sysdate where SSO_MASTERS_HIS.MASTER_SESS_ID =: OLD. MASTER_SESS_ID;
SELECT MASTER_SESS_ID into v from SSO_SP_LIST WHERE SSO_SP_LIST.MASTER_SESS_ID =: OLD. MASTER_SESS_ID;

IF V IS NOT NULL THEN
Delete from SSO_SP_LIST WHERE MASTER_SESS_ID =: OLD. MASTER_SESS_ID;
UPDATE SSO_SP_LIST_HIS SET TIME_SP_EXIT = sysdate where MASTER_SESS_ID =: OLD. MASTER_SESS_ID;
End if;
End TIG_BEF_DELETE_SSO_MASTERS;

Modified trigger

Create or replace trigger TIG_BEF_DELETE_SSO_MASTERS
BEFORE DELETE
ON SSO_MASTERS_INF

FOR EACH ROW
DECLARE
V int;
BEGIN
UPDATE SSO_MASTERS_HIS SET SSO_MASTERS_HIS.TIME_EXIT = sysdate where SSO_MASTERS_HIS.MASTER_SESS_ID =: OLD. MASTER_SESS_ID;
SELECT count (*) into v from SSO_SP_LIST WHERE SSO_SP_LIST.MASTER_SESS_ID =: OLD. MASTER_SESS_ID;

If v> 0 THEN
Delete from SSO_SP_LIST WHERE MASTER_SESS_ID =: OLD. MASTER_SESS_ID;
UPDATE SSO_SP_LIST_HIS SET TIME_SP_EXIT = sysdate where MASTER_SESS_ID =: OLD. MASTER_SESS_ID;
End if;
END TIG_BEF_DELETE_SSO_MASTERS;

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.