Examples of Oracle creating functions and calling stored procedures and calling functions (differences)

Source: Internet
Author: User

To create a function:

format:Create or Replace function func ( parameter parameter type )

Return number

Is

Begin

-------- business logic ---------

End;

--Create a functionCreate or Replace functionFunc (DNO Number)return  Number isT_max Number;begin   Select Max(SAL) intoT_max fromEMP TwhereDeptno=DNO; returnT_max;End ;--examples of calling stored procedures and calling functions (differences)DeclareT_maxsal Number;begint_maxsal:=FuncTen);  Dbms_output.put_line (t_maxsal); Dbms_output.put_line (func (Ten));End;Create or Replace procedure proc(DNOinch  Number, maxsal out Number) isT_maxsal Number;begin  Select Max(SAL) intoT_maxsal fromEmpwhereDeptno=DNO; Maxsal:=t_maxsal;End;DeclareT_sal Number:= 0;begin   proc(Ten, t_sal); Dbms_output.put_line (t_sal);End;Create or Replace functionFunc (A NumberA Number)return  Number isT_result Number:= 0;beginT_result:=A+b; returnT_result;End;beginDbms_output.put_line (func (Ten, -));End;
--delete functionDrop functionfunc;
--Delete stored proceduresDrop procedure proc;--Create a package (you can write stored procedures and functions in the package)Create or ReplacePackage PackprocedureProadd (A NumberB Number)procedureProsub (A NumberB Number)Endpack;beginPack.proadd (3,1); Pack.prosub (3,2);End;

Note: The above call refers to the SQL window called in the Plsql

Examples of Oracle creating functions and calling stored procedures and calling functions (differences)

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.