In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
Select statement
1. If...then statement
Syntax:
If
< condition_expression >Thenplsql_sentenceend if
Condition_expression: represents a conditional expression whose value is true, and the program executes the PL/SQL statement under if
If its value is false, the program skips the statement below if and executes the statement after end if directly.
The statement to execute when plsql_sentence:condition_expression is true.
2. If...then...else statement
Syntax:
If
< condition_expression >Thenplsql_sentence_1;elseplsql_sentence_2;end if
3.if...then...elsif statement
Syntax:
If
< condition_expression1 >Thenplsql_sentence_1;elsif
< condition_expression2 >Thenplsql_sentence_2;...elseplsql_sentence_n;end if
4. Case statement
Syntax:
Case
< selector >When then plsql_sentence_1;when then plsql_sentence_2;...when then plsql_sentence_n; [else plsql_sentence;] end case
Selector: a variable that stores the value to be detected, often called a selector.
The value of the selector needs to match the value of the expression in the when clause.
Expression_1: the expression in the first when clause, which is usually a constant when the value of the selector is equal to the value of the expression
The program executes the plsql_setence_1 statement.
Expression_2: the expression in the second when clause, which is usually a constant when the value of the selector is equal to the value of the expression
The program executes the plsql_setence_2 statement.
Expression_n: the expression in the nth when clause, which is usually a constant when the value of the selector is equal to the value of the expression
The program executes the plsql_setence_n statement.
Plsql_sentence: a PL/SQL statement that the program executes when there is no when constant that matches the selector
The else statement in which it is located is optional.
Example:
Specify a quarter value, then use the case statement to determine the month information it contains and output it.
Code:
Declareseason int:=3;aboutlnfo varchar2 (50); begincase seasonwhen 1 thenaboutlnfo: = season | | 'quarter includes 1Magic, February and March'; when 2 thenaboutinfo: = season | | 'quarter includes May and June'; when 3 thenaboutinfo: = season | | 'quarter includes July, August, September'; when 4 thenaboutinfo: = season | | 'quarter includes October, November and December'; elseaboutinfo: = season | | 'illegal season'; end case;dbms_output.put_line (aboutinfo); end |
Results: 3 quarters, including 7, 8, 8, September.
Loop statement
1. Loop statement
Syntax:
Loopplsql_sentence;exit when end_condition_expend loop
Plsql_sentence: the PL/SQL statement in the body of the loop. Be executed at least once.
End_condition_exp: loop end condition expression, when the expression is true, the program will exit the loop body, otherwise the program will execute again.
Example:
Use the loop statement to find the sum of the first 100 natural numbers and output them to the screen.
SQL > set serveroutput on;SQL > declaresun_i int:=0;i int:=0;beginloopi:=i+1;sum_i:=sum_i + 1 * * exit when I = 100 *-when the loop is repeated 100 times, the program exits the loop body. End loop;dbms_output.put_line ('the first 100 natural numbers and:' | | sum_i); end;/
2. While statement
Syntax:
While condition_expression loopplsql_sentence;end loop
Condition_expression: represents a conditional expression, but when its value is true, the program executes the loop body.
Otherwise, the program exits the loop body, and the program determines whether the expression is true before executing the loop body each time.
Plsql_sentence: the plsql statement within the loop.
Example:
Use the while statement to find the sum of the first 100 natural numbers and output them to the screen.
Declare sum_i int:=0;i int:=0;beginwhile i
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.