Oracle Note 11, PL/SQL functions, and triggers

Source: Internet
Author: User

--Create a function
Create or Replace function Add_sal (ssal number)
       return number
Is
Begin
  if (Ssal >) Then
    return ssal + 51;
  elsif (Ssal >) Then
    return ssal + 111;
  Else
    return ssal + 222;
  End If;
End
Select Sal, Add_sal (SAL) from EMP;
--Trigger
CREATE TABLE Deptlog (
       UName varchar2 (20),
       Action Varchar2 (20),
       DTime Date
);
--Create a trigger
--for each row can trigger multiple entries, and how many times your language affects how many records will be triggered
Create or Replace Trigger TRIG_DEPT2
  After insert or delete or update on dept2/* for each row*/
Begin
  If inserting then
    INSERT into Deptlog values (user, ' Insert ', sysdate);
  elsif updating Then
    INSERT into Deptlog values (user, ' Update ', sysdate);
  elsif deleting Then
    INSERT into Deptlog values (user, ' delete ', sysdate);
  
End
SELECT * from Dept2;
SELECT * from Deptlog;
INSERT into DEPT2 values (, ' software ', ' CIC ');
Update dept2 Set loc = ' Go ' where deptno in (30);
Delete Dept2 where deptno = 55;
--Trigger
Create or Replace Trigger Trig_emp
  After update on dept for each row
Begin
  Update emp Set Emp.deptno =: New.deptno where Emp.deptno =: old.deptno;
End
Update Dept Set deptno = one     where deptno = 10;
SELECT * from EMP;
---statement-level triggers
Create or Replace Trigger TRG_INS_DEPT2
Before insert
On Dept2
Begin
     If user not in (' SCOTT ') then      
       Raise_application_error (-20001, ' only Scott can modify the table! ');
     End If;
End
disabling, enabling triggers
Alter TRIGGER tgr_name Disable | Enable
ALTER TABLE tableName Disable ALL Trigger | Enable all trigger;

Oracle Note 11, PL/SQL functions, and triggers

Related Article

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.