Helps you quickly understand stored functions, stored procedures, and triggers

Source: Internet
Author: User

Help you quickly understand stored functions, stored procedures, triggers 1. create stored procedures 1. create procedure isertEmp as begin insert into emp values (9888, 'www ', 'sdf ', null, 9888, 20); commit; end;/2. create or replace the stored procedure create or replace procedure isertEmp as begin insert into emp values (, 'www ', 'sdf ', null, 20); commit; end; /3. Stored procedure case -- stored procedure case SQL> create or replace procedure raiseSalary (empid in number) as pSal emp. sal % type; begin select sal into pSal from emp where empno = empid; update emp set sal = sal * 1.1 where empno = empid; dbms_output.put_line ('employee ID: '| empid | 'salary raise pre' | psal | 'salary raise Post' | psal * 1.1); end; /4. Call a stored procedure-method 1 of calling a stored procedure: SQL> set serveroutput on; -- enable the Service SQL> begin raiseSalary (7521); end;/employee ID: 7521 before salary increase 1250 after salary increase 1375 PL/SQL procedure successfully completed Method 2: SQL> set serveroutput on; SQL> exec raiseSalary (7521); employee ID: 7521 before salary increase 1375 after salary increase 1512.5 PL/SQL procedure successfully completed 2. storage function 1. create a storage function querySal (cno in number) return number as psal number; pcomm number; begin select sal, comm into psal, pcomm from emp where empno = cno; return psal * 12 + pcomm; end; /2. create or replace the storage function create or replace function querySal (cno in number) return number as psal number; pcomm number; begin select sal, comm into psal, pcomm from emp where empno = cno; return psal * 12 + pcomm; end;/3. Case create or replace function queryEmpSalary (empid in number) return number as pComm number; pSal number; begin select sal, comm into pSal, pComm from emp where empno = empid; return pSal * 12 + pComm; end;/4. function call if a field is empty, however, if you want this field to display 0nvl (field name, 0), this field is displayed as 0 declare v_sal number; begin v_sal: = queryEmpSalary (7521); dbms_output.put_line ('salary is: '| v_sal); end;/salary is: 18650 trigger 1. create or replace trigger tig before insert on emp begin dbms_output.put_line ('executed before insert'); end; /Trigger created2. Trigger effect insert into emp values (1234, 'hhh ', 'asd', null, limit, 40); executed before insertion

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.