Storage functions for Oracle objects

Source: Internet
Author: User

Storage Functions

Create or replace function Name of function (name in type, name out type, ...) return Data Type is

result variable data type ;

begin

return ( result variable );

end[ Name of function ];

The difference between stored procedures and stored functions

In general, the difference between a procedure and a function is that a function can have a return value, whereas a procedure does not return a value.

but procedures and functions can be outspecifies one or more output parameters. We can use outparameters, which are implemented in procedures and functions to return multiple values. In general, there is a return value with a stored function, multiple return values with stored procedures. Example: Using a stored function to query a specified employee's annual salary
1Create or Replace function Empincome (ENOinchEmp.empno%type)returnNumber is2  3Psal emp.sal%type;4  5Pcomm emp.comm%type;6  7 begin8  9   SelectT.sal into Psal fromEMP TwhereT.empno =Eno;Ten   One   returnPsal * A+ NVL (Pcomm,0); A   -End

Use stored procedures to replace the example above
1  2Create or Replace procedure EMPINCOMEP (EnoinchEmp.empno%type, income outNumber is3  4Psal emp.sal%type;5  6Pcomm emp.comm%type;7  8 begin9  Ten   SelectT.sal, T.comm into Psal, Pcomm fromEMP TwhereT.empno =Eno; One   AIncome: = psal* A+NVL (Pcomm,0); -   -End EMPINCOMEP;

Call:
1  2 Declare 3  4   income number; 5  6 begin 7  8   EMPINCOMEP (7369, income); 9  Ten   dbms_output.put_line (income);  One   the end;

Storage functions for Oracle objects

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.