Use triggers to back up table data

Source: Internet
Author: User

The function is very simple. If a field has more points, one more parameter will cause problems.
For example:
Too partition columns.

Recently I have read the web js optimization. js conventions for internal variables start with _, for example, _ name, _ age.
Trigger writes are relatively small, and temporary variables do not support _ myVar. Unfortunately.
1. Compilation errors
Error: PLS-00103: Encountered the symbol "_" when expecting one of the following:

Text: _ TMP_PROJECT_ID NUMBER (16, 0 );

ORA-00947: not enough values
Multiple column names with less inserted VALUES. For example, (A, B, C) VALUES (A, B)

3. ORA-00913: How is too struct values opposite?
For example, (A, B, C) VALUES (A, B, C, D)
Reference

Create or replace trigger TRI_AAA
Before update or delete
On AAA
For each row

Declare
ERR VARCHAR2 (100 );
-- Original table Field
TMP_PROJECT_ID NUMBER (16, 0 );
TMP_COMPANY_ID NUMBER (16, 0 );
TMP_CREATE_DATETIME DATE;
...
TMP_GROUP_ID NUMBER (16, 0 );
-- Add a field
-- TMP_USER_OPT VARCHAR2 (64 );
-- TMP_USER_OPT_DATETIME DATE;
PRAGMA AUTONOMOUS_TRANSACTION;
Begin
TMP_PROJECT_ID: =: OLD. PROJECT_ID;
TMP_COMPANY_ID: =: OLD. COMPANY_ID;
TMP_CREATE_DATETIME: =: OLD. CREATE_DATETIME;
...
TMP_GROUP_ID: =: OLD. GROUP_ID;
If updating then
Insert into AAA_LOG (PROJECT_ID, COMPANY_ID, CREATE_DATETIME,..., TMP_GROUP_ID, 'update', SYSDATE );
Commit;
Elsif deleting then
Insert into AAA_LOG (PROJECT_ID, COMPANY_ID, CREATE_DATETIME,..., TMP_GROUP_ID, 'update', SYSDATE );
Commit;
End if;

EXCEPTION
WHEN TOO_MANY_ROWS THEN
Insert into TAB_PUB_ERROR (userid, error, triname, tabfountain, tabend, edate)
VALUES (0, 'too _ MANY_ROWS ', 'tri _ aaa', 'aaa', 'aaa', sysdate );
COMMIT;
WHEN NO_DATA_FOUND THEN
Insert into TAB_PUB_ERROR (userid, error, triname, tabfountain, tabend, edate)
VALUES (0, 'no _ DATA_FOUND ', 'tri _ aaa', 'aaa', 'aaa', sysdate );
COMMIT;
WHEN OTHERS THEN
Err: = SUBSTR (SQLERRM (SQLCODE), 1,100 );
Insert into TAB_PUB_ERROR (userid, error, triname, tabfountain, tabend, edate)
VALUES (0, err, 'tri _ aaa', 'aaa', 'aaa', sysdate );
COMMIT;
End;

Author: "westsince2001"
 

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.