1. SQL data storage by condition
普通的 INSERT INTO 插入:
INSERT INTO card(cardno, cardnum) VALUES(‘1111‘, ‘100‘);INSERT INTO card(cardno, cardnum) VALUES(‘2222‘, ‘200‘);
Inserting a condition into SQL
insert INTO Card (Cardno, Cardnum) select ' 111 ' , ' " from DUAL where not exists (select cardno from Card where Cardno = ' 111 ' ); INSERT into card (Cardno, cardnum) SELECT ' 222 ', ' + ' from DUAL where not EXISTS(SELECT cardno from card WHERE Cardno = ' 222 ');
2. Condition control
IF 语句CASE 语句IF 语句根据条件执行一系列语句,有三种形式:IF-THEN、IF-THEN-ELSE 和 IF-THEN-ELSIF
DECLARE x VARCHAR2(10);BEGIN x:=‘&x‘; IF LOWER(x)=‘yTHEN DBMS_OUTPUT.PUT_LINE(‘Yes!‘); ELSIF LOWER(x)=‘nTHEN DBMS_OUTPUT.PUT_LINE(‘No!‘); ELSE DBMS_OUTPUT.PUT_LINE(‘Error‘); ENDIF;END;
The case statement is used to compare multiple values against a single variable or an expression
Calculates the value of a selector before executing a case statement
begin Case ' &grade ' when ' A ' then dbms_ OUTPUT. Put_Line (' excellent '); when ' B ' then dbms_output. Put_Line (excellent '); when ' C ' then dbms_output. Put_Line (' good '); when ' D ' then dbms_output. Put_Line (' General '); when ' F ' then dbms_output. Put_Line (' poor '); else Dbms_output. Put_Line (' No such result '); end case ; end ;
3. Loop control for repeating a series of statements
Loop control statements include:
LOOP, exit, and exit when
Three types of loop control:
Loop-Unconditional Loop
While-looping by condition
For-loop fixed number of times
LOOP sequence_of_statementsENDLOOP;WHILELOOP sequence_of_statementsENDLOOP;FORIN [REVERSE] value1..value2LOOP sequence_of_statementsENDLOOP;
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
MySQL Classic SQL collection