The PL/SQL exercise function

Source: Internet
Author: User

1, you must return a value
2. Can only be called in an expression

Sql> Create or Replace functionfun12   return  Number  3   is  4V_sum_sal Emp.sal%type; 5    6   begin  7     Select sum(SAL) intoV_sum_sal fromEmpwhereDeptno=Ten; 8     returnv_sum_sal; 9   End; Ten  /FunctionCreatedsql>SQL> Declare    4V_sumsal Emp.sal%type; 5    6  begin  7    8V_sumsal:=fun1; 9Dbms_output.put_line (v_sumsal);Ten    One  End;

Functions with Parameters:

In:

Sql> Create or Replace functionfun12(V_deptnoinch  Number)  3   return  Number  4   is  5V_sum_sal Emp.sal%type; 6    7   begin  8     Select sum(SAL) intoV_sum_sal fromEmpwhereDeptno=V_deptno; 9     returnv_sum_sal;Ten   End;
 sql>  declare  2  v_sumsal emp.sal%    Type  3   4  begin  5  6  v_sumsal: =  fun1 (10  );  7   Dbms_output.put_  Line (v_sumsal);  8   9  end ; 

Out:

Sql> Create or Replace functionfun22    3(V_empno Number, V_ename outvarchar2, v_sal out Number)  4    5   return  Number  6    7    is  8    9   begin Ten    One     SelectEname,sal intoV_ename,v_sal fromEmpwhereEmpno=V_empno; A     returnv_sal; -   End;  -  /FunctionCreatedsql> Declare  2    3V_salary Emp.sal%type; 4V_ename Emp.ename%type; 5V_sal Emp.sal%type; 6    7   begin  8V_salary:=Fun2 (7369, v_ename,v_sal); 9Dbms_output.put_line ('Salary is:'||v_salary); Ten    One   End;

The PL/SQL exercise function

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.