Oracle user-defined functions

Source: Internet
Author: User

A user-defined function is a code block stored in a database. It can return the value to the calling program. The call is like a system function, such as a max (value) function. value is called a parameter. There are three types of function parameters. In parameter type: indicates the parameter input to the function. Out parameter type: indicates that the parameter is assigned a value in the function and can be passed to the function calling program. In out parameter type: indicates that a parameter can be either passed or assigned a value. 1. Syntax format: Create or replace function function_name/** // * function name */
(
Parameter_name1, mode1 datatype1,/** // * Parameter definition section */
Parameter_name2, mode2 datatype2,
Parameter_name3, mode3 datatype3
...
)
Return return_datatype/** // * defines the return value type */
Is/
Begin
Function_body/** // * function body part */
Return scalar_expression/** // * return statement */
End function_name;

Description: function_name: User-Defined Function Name. The function name must comply with the rules defined by the identifier. For its owner, the name is unique in the database. Parameter: User-defined parameter. You can define one or more parameters. Mode: parameter type. Datatype: Data Type of user-defined parameters. Return_type: indicates the data type returned by the user. The function returns the value of the scalar_expression expression. The function_body function is composed of PL/SQL statements. 2. Sample Function Code: Create or replace function t01001_count
Return number
Is
Count_t01001 number;
Begin
Select count (*) into count_t01001 from t01001;
Return (count_t01001 );
End t01001_count; -- Remember to score the number.

Call:
Declare
I number;
Begin
I: = t010010000count ();
Dbms_output.put_line (to_char (I ));
End; -- Remember to score the number

Note: (1) if the function does not have a parameter, no parentheses should be placed after the function name; (2) Remember to write the function name after the end when creating the 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.