Oracle Add Log Table

Source: Internet
Author: User

--Create a table

CREATE TABLEknet_domain_dns_forwarded (IDVARCHAR2( $BYTE)DEFAULTSys_guid () not NULL, KEYWORDVARCHAR2( theBYTE) not NULL, CNAMEVARCHAR2( +BYTE), URLVARCHAR2( +BYTE) not NULL, Create_date DATEDEFAULTSysdate not NULL, Update_date DATE, Audit_statusVARCHAR2( -BYTE), Audit_date DATE, Audit_reasonVARCHAR2( +BYTE), is_forwardedVARCHAR2( -BYTE)DEFAULT 'N' , CONSTRAINTKnet_domain_dns_forwarded_pkPRIMARY KEY(ID))CREATE TABLEKnet_domain_dns_forwarded_log (log_idVARCHAR2( $BYTE) not NULL, Log_time DATE not NULL, Log_opVARCHAR2( -BYTE) not NULL, IDVARCHAR2( $BYTE) not NULL, KEYWORDVARCHAR2( theBYTE) not NULL, CNAMEVARCHAR2( +BYTE), URLVARCHAR2( +BYTE) not NULL, Create_date DATE not NULL, Update_date DATE, Audit_statusVARCHAR2( -BYTE), Audit_date DATE, Audit_reasonVARCHAR2( +BYTE), is_forwardedVARCHAR2( -BYTE),CONSTRAINTKnet_domain_dns_forwarded__pkPRIMARY KEY(log_id))

--Create a sequence  
CREATE SEQUENCE Knet_domain_dns_forwarded_seq 1999999999999999 by 1 with 1 noorder nocycle;
--Create a trigger
Create or Replace TRIGGERDomain_dns_forwarded_tiger AfterInsert or Update or Delete onknet_domain_dns_forwarded forEach rowDeclare --Local Variables herebegin ifInserting Then INSERT intoKnet_domain_dns_forwarded_log (log_id,log_time,log_op,id,keyword,cname,url,create_date,update_date,audit_ status,audit_date,audit_reason,is_forwarded)VALUES(Trim (To_char (Knet_domain_dns_forwarded_seq.nextval,'000000000000009')), Sysdate,'1',: New.id,:new. Keyword,:new. Cname,:new. Url,:new. Create_date,:new. Update_date,:new. Audit_status,:new. Audit_date,:new. audit_reason,:new.is_forwarded); elsif updating Then INSERT intoKnet_domain_dns_forwarded_log (log_id,log_time,log_op,id,keyword,cname,url,create_date,update_date,audit_ status,audit_date,audit_reason,is_forwarded)VALUES(Trim (To_char (Knet_domain_dns_forwarded_seq.nextval,'000000000000009')), Sysdate,'2',: New.id,:new. Keyword,:new. Cname,:new. Url,:new. Create_date,:new. Update_date,:new. Audit_status,:new. Audit_date,:new. audit_reason,:new.is_forwarded); Else INSERT intoKnet_domain_dns_forwarded_log (log_id,log_time,log_op,id,keyword,cname,url,create_date,update_date,audit_ status,audit_date,audit_reason,is_forwarded)VALUES(Trim (To_char (Knet_domain_dns_forwarded_seq.nextval,'000000000000009')), Sysdate,'0',: Old.id,:old. Keyword,:old. Cname,:old. Url,:old. Create_date,:old. Update_date,:old. Audit_status,:old. Audit_date,:old. audit_reason,:old.is_forwarded); End if;EndDomain_dns_forwarded_tiger;

Oracle Add Log Table

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.