Oracle Stored Procedure usage notes

Source: Internet
Author: User

(1) Pay attention to the following points when writing a stored procedure:
1> Value assignment: =
Logic equal to =
2> comments a single line of code --
Annotate the code block /*---*/
3> string connector |
4> declare variables in the variable declaration area: Between is and begin
5> there are three methods to declare variables:
1) Single Variable
Mo_flag number: = 0;
Content table. Content % type;
2) array
Type data_type is table of varchar2 (10) index by binary_integer; -- reference format: data_type (I)
Type rule_type is record (data_id table. ID % type,
Data_name table. name % Type
); -- Reference format: rule_type (I). data_id
6> a frequently used built-in function Decode:
Decode (ID, 1, 'southlake ',
2, 'san Francisco ',
3, 'new Jersey ',
4, 'seattle ',
'Non-domestic ')
When ID is 1, return southlake; If ID is 2, Return San Francisco; in turn, if none, return non-domestic

(2) PL/SQL Block Structure
1> trigger
Create or replace trigger trigger_name
After | before insert | update | delete on table_name
For each row
Declare
(Declaration part)
Begin
(Program body)
Exception
(Exception Handling)
End;
2> Stored Procedure
Create or replace procedure name (parameter) is
(Declaration part)
Begin
(Program body)
Exception
(Exception Handling)
End;
3> Functions
Create or replace function func_name (parameter) return data_type is
(Declaration part)
Begin
(Program body)
Exception
(Exception Handling)
End;

Note: declare is required when declaring variables in triggers. It is not required when declaring stored procedures and functions.

(3) Pay attention to the following applications during application and debugging:
1> set serveroutput on buffer 20000;
Use dbms_output.put_line ('strin _ content'); you can output information in the stored procedure and debug the stored procedure;
The information can only be displayed on the screen after the serveroutput variable is set to on.
2> execute procedure_name;
Execute a stored procedure
3> select function () from dual;
Execute a function using an SQL statement
4> dbms_job.submit (job, 'test _ warn_proc; ', sysdate, 'sysdate + 30/(24*60 )');
Indicates that the job is executed every 30 minutes, dbms_job.submit (Task Number, stored procedure to be executed, next execution time, interval)
Sysdate + x/24 is executed every x hours.
Sysdate + x/(24*60) is executed every X minutes.
Sysdate + x/(24*60*60) Run Once every X seconds
5> when an error message is reported, the line numbers are described as follows:
The count of the row number starts with the keyword declare. If not, the row number of the begin statement is 1.

 

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.