Han shunping: Oracle PL/SQL Lecture Notes II

Source: Internet
Author: User

This is the 25th lecture, mainly about the basic understanding of blocks and processes.

1. One of the simplest blocks:
Set serveroutput on -- open the output option. If it is off, put_line () has no output.
Begin
Dbms_output.put_line ('hello ');
End;
Note: dbms_output is a package provided by Oracle. Contains procedures and functions. Put_line is a process of dbms_output.

The simplest part two:
Declare
V_ename varchar2 (5); -- defines string variables
V_sal number (7,2)
Begin
Select ename, Sal into v_ename, v_sal from EMP where empno = 7788;
Dbms_output.put_line ('user name is: '| v_ename );
End;

The simplest part 3:
Problem introduction:
A post from chianunix
Select cdzj into CZ from T1 where Cn = 1;
For example, in the preceding SELECT statement, if no_data_found is not found when CN = 1 is not found, the following statements cannot be executed. I want to make the CN value 0 when CN = 1 is not found, then you can continue executing the following statements. Do you know if you have any solutions?
Method: capture and process exceptions.
Declare
V_ename varchar2 (5); -- defines string variables
V_sal number (7,2)
Begin
Select ename, Sal into v_ename, v_sal from EMP where empno = 7788;
Dbms_output.put_line ('user name is: '| v_ename );
Exception
When no_data_found then
Dbms_output.put_line ('Friend, your input is incorrect ');
End;

2 Process
Definition: programs that perform specific operations
One case:
Modify Employee Salary Based on employee name
Create procedure sp_think (spname varchar2, newsal number) -- specify the type and the size is not required.
Is
Begin
Update EMP set sal = newsal where ename = spname;
End;
/
Call:
Exec sp_think ('Scott, 5000 );
Note: If a stored procedure is called in sqlplus or toad, it will survive, that is, a test. a meaningful way is to call the process in the main language such as Java.

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.