标签:循环语句 got 三星 weight 数值 case amp boolean varchar2
select * from goods; a char(10):=‘三星‘ --定长字符串 b varchar2(10):=‘三星‘; --可变字符串 c binary_integer:=‘10001‘; --带符号整数,为整数计算优化性能 d number(5,2):=‘123.45‘; --数值 e long --变长字符串 f date --日期 g boolean --布尔 h rowid --存放数据库行号 i Goods.Gname%type:=‘三星‘; --用%type定义与表相配的属性类型 ------------------------------------------------------if语句 declare c binary_integer:=‘10002‘; begin if c>10 then update Goods set Gnote=‘\(^o^)/~‘ where Gid=c; end if; end; ------------------------------------------------------if..else语句 declare a number(4,2):=‘13.45‘; d number(5,2):=‘123.45‘; begin if a>d then DBMS_OUTPUT.put_line(‘AAA‘); else DBMS_OUTPUT.put_line(‘BBB‘); end if; end; ------------------------------------------------------if..elsif..else语句 declare a varchar2(10):=‘823‘; b varchar2(10):=‘12a3456‘; c number:=‘132456798‘; begin if a<b and a>c then DBMS_OUTPUT.put_line(‘AAA‘); elsif a>b or a>c then DBMS_OUTPUT.put_line(‘BBB‘); --字符串比较是从下标第一个开始比 elsif a<c then DBMS_OUTPUT.put_line(‘CCC‘); else DBMS_OUTPUT.put_line(‘DDD‘); end if; end; ------------------------------------------------------case语句 declare a char(10):= upper(‘&p_grade‘); b varchar2(10); begin b:= case a when ‘A‘ then ‘123‘ when ‘B‘ then ‘456‘ when ‘C‘ then ‘789‘ else ‘NO‘ end; DBMS_OUTPUT.put_line(b||‘ABCD‘); end; ------------------------------------------------------loop循环 declare a number(10):=0; begin loop a:=a+1; DBMS_OUTPUT.put_line(‘a的当前值为‘||a); exit when a=10; end loop; end; ------------------------------------------------------for循环 declare a char(10):=1; begin for x in 1..10 loop DBMS_OUTPUT.put_line(‘a的当前值为‘||a); end loop; end; ------------------------------------------------------for循环使用关键字reverse(倒序循环) declare a varchar2(10):=10; begin for a in reverse 1..10 loop DBMS_OUTPUT.put_line(‘a的当前值为‘||a); end loop; end; ------------------------------------------------------while循环 declare a number:=1; begin while a<=10 loop DBMS_OUTPUT.put_line(‘a的当前值为‘||a); a:=a+1; end loop; end; ------------------------------------------------------用for循环添加属性 create table Demo (DID number(5),Dname varchar2(10)); select * from Demo; declare a number:=1; b varchar2(10):=‘Jack‘; begin for a in 1..10 loop insert into Demo(DID,DNAME) values (a,b); end loop; for a in 1..10 loop insert into Demo(DNAME) values (b); end loop; end; delete from Demo ------------------------------------------------------ declare a number:=1; begin loop DBMS_OUTPUT.put_line(‘a的当前值为‘||a); a:=a+1; if a>10 then goto loyer; end if; end loop; <<loyer>> null; --不需要处理任何数据 DBMS_OUTPUT.put_line(‘ABCD‘); end; ------------------------------------------------------
标签:循环语句 got 三星 weight 数值 case amp boolean varchar2
原文地址:http://www.cnblogs.com/loyer/p/7242225.html