Call of oracle stored procedures and functions

Source: Internet
Author: User


Call oracle stored procedures and functions -- create or replace procedure pro_add (num1 number, num2 number, r out number) asbeginr: = num1 + num2; end; www.2cto.com create or replace procedure pro_minus (num1 number, num2 number, r out number) asbeginr: = num1-num2; end; -- create function create or replace function fcn_add (num1 number, num2 number) return number is r number; beginr: = num1 + num2; return r; end; create or replace function fcn_minus (num1 number, num2 number) return number isbeginreturn num1-num2; end; www.2cto.com create or replace function fcn_minus1 (num1 number, num2 number) return number isr number; r1 number; begin r: = num1-num2; r1: = num2-num1; if r-r1> 0 thenreturn r; elsereturn r1; end if; end; -- call the Stored Procedure declaren1 number; n2 number; r number; fr number; beginn1: = 3; n2: = 2; pro_add (n1, n2, r); dbms_output.put_line ('add result: '| r); -- 1 You can use this method to obtain the returned value of the stored procedure pro_minus (n1, n2, r ); -- 2 You can also use this method to obtain the returned values of stored procedures: pro_minus (num1 => n1, num2 => n2, r => r ); -- If 1 is used, all parameters need to be passed in this way -- if 2 is used, all parameters need to be written in the same way -- the second method is used. the result of the correlation dbms_output.put_line ('subtraction: '| r); end; www.2cto.com -- call functiondeclaren1 number; n2 number; r number; begin www.2cto.com -- to obtain the return value of a function, you only need to call it in the normal way. n1: = 3; n2: = 5; r: = fcn_add (num1 => n1, num2 => n2); dbms_output.put_line ('add result: '| r); r: = fcn_minus (num1 => n1, num2 => n2); dbms_output.put_line ('result of using fcn_minus subtraction: '| r); r: = fcn_minus1 (num1 => n1, num2 => n2 ); dbms_output.put_line ('result of using fcn_minus1 subtraction: '| r); end; Author: tengdazhang770960436

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.