Application of Oracle functions and stored procedures

Source: Internet
Author: User

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. -- 1. Create a function
  2. -- Create or replace function get_hello_msg return varchar2
  3. -- Begin
  4. -- Return 'Hello world ';
  5. -- End get_hello_msg;
  6. --/
  7. SQL>Create Or Replace FunctionGet_hello_msg
  8. ReturnVarchar2As
  9. Begin
  10. Return 'Hello world';
  11. EndGet_hello_msg;
  12. /
  13. The function has been created.
  14. -- 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 ';
  15. SQL>SetLinesize: 180;
  16. SQL>SelectObject_name, object_type, statusFromUser_objectsWhere Lower(Object_name) ='Get _ hello_msg';
  17. OBJECT_NAME OBJECT_TYPE STATUS
  18. Certificate --------------------------------------------------------------------------------------------------------------------------------------------------
  19. GET_HELLO_MSGFUNCTIONVALID
  20. -- 3. View function return values
  21. -- Set serverout on;
  22. -- Declare msg varchar2 (20 );
  23. -- Begin
  24. -- Msg: = get_hello_msg;
  25. -- Dbms_output_line (msg );
  26. -- End;
  27. --/
  28. SQL>SetServeroutOn;
  29. SQL>DeclareMsg varchar2 (20 );
  30. BeginMsg: = get_hello_msg; dbms_output.put_line (msg );End;
  31. /
  32. Hello world
  33. The PL/SQL process is successfully completed.
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • Next Page

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.