Functions and stored procedures
In Oracle databases, you can use a single statement to add, delete, modify, and query a database. In addition, you can use multiple statements to form an I statement block and execute them together.
These statement blocks can be displayed and named and called by other applications. These named statement blocks are called functions and stored procedures.
Custom functions in Oracle;
Stored Procedures in Oracle;
Package functions and stored procedures-packages.
-- Function
-- A function is a common object in Oracle. Like other programming language functions, functions in Oracle must return a value. This is also an important feature that distinguishes functions from stored procedures.
-- Function introduction:
1. division of functions and functions
2. Function Parameters
3. function return value
Create a function
- -- 1. Create a function
- -- Create or replace function get_hello_msg return varchar2
- -- Begin
- -- Return 'Hello world ';
- -- End get_hello_msg;
- --/
- SQL>Create Or Replace FunctionGet_hello_msg
- ReturnVarchar2As
- Begin
- Return 'Hello world';
- EndGet_hello_msg;
- /
- The function has been created.
- -- 2. view the function information in the data dictionary. select object_name, object_type, status from user_objects where lower (object_name) = 'get _ hello_msg ';
- SQL>SetLinesize: 180;
- SQL>SelectObject_name, object_type, statusFromUser_objectsWhere Lower(Object_name) ='Get _ hello_msg';
- OBJECT_NAME OBJECT_TYPE STATUS
- Certificate --------------------------------------------------------------------------------------------------------------------------------------------------
- GET_HELLO_MSGFUNCTIONVALID
- -- 3. View function return values
- -- Set serverout on;
- -- Declare msg varchar2 (20 );
- -- Begin
- -- Msg: = get_hello_msg;
- -- Dbms_output_line (msg );
- -- End;
- --/
- SQL>SetServeroutOn;
- SQL>DeclareMsg varchar2 (20 );
- BeginMsg: = get_hello_msg; dbms_output.put_line (msg );End;
- /
- Hello world
- The PL/SQL process is successfully completed.