Common pl/SQL judgment statements and plsql statements

Source: Internet
Author: User

Common pl/SQL judgment statements and plsql statements

Statement 1: IF-THEN

IF condition THEN

Execution statement

End if;

 

Statement 2: IF-THEN-ELSE

IF condition THEN

Execution statement

ELSE

Execute other statements

End if;

 

Statement 3: IF-THEN-ELSIF

IF condition 1 THEN

Execute Statement 1

ELSIF condition 2 THEN

Execute Statement 2

ELSE

Execute other statements

End if;


The SQL judgment statement is queried by PL/SQL based on the field value to display the corresponding Chinese Characters

Run: select decode (STATUS, 0, 'invalid', 1, 'saved ', 2, 'submitted for approval', 3, 'approval not passed', 4, 'approved ', 5, 'terminated') from table where a = 'a203'

How does PL/SQL determine whether data exists in the database?

Can you describe clearly?
1. Whether to determine whether there is any value in the database. Is there any rule for the determination? For example,
A) define a variable using a simple value assignment method and use exception:
Select ___ into vvariable from table where ...... This sentence is assigned when there is a value, and when there is no data, add another
Exception
When NO_DATA_FOUND then
The statement you want to output
End;

B) The value is still assigned, but count is used.
Select count (*, or the column name you want) into vvariable
From table
Where ......;

If vvariable = 0 then
Statement 1;
Else
Statement 2;
End if;
----------------------------------
The above two methods may be used in the stored procedure, and the other method is to use only SQL statements, which requires you to describe your problem in more detail.

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.