Oracle笔记 八、PL/SQL跳转/判断/循环语句块
2015-10-12 22:16
579 查看
--goto跳转语句
--在goto后,跳转到相应的语句,然后执行该语句和后面所有语句
begin
dbms_output.put_line('goto开始了');
gotoc;
--不被执行
dbms_output.put_line('goto');
dbms_output.put_line('goto');
dbms_output.put_line('goto');
dbms_output.put_line('goto');
<<a>>
dbms_output.put_line('gotoaaa');
<<b>>
dbms_output.put_line('gotobbb');
<<c>>
dbms_output.put_line('gotoccc');
end;
--PL/SQL中的sql和rowcount属性:sql代表最近执行的sql语句,rowcount代表最近执行的sql语句影响的行数
declare
vCountnumber;
vDeptnodept2.deptno%type:=10;
begin
--selectcount(*)intovCountfromdept2;
--updatedept2setdname=dname||'~.~'wheredeptno=vDeptno;
--deletefromdept2wheredeptno=40;
insertintodept2select*fromdept;
dbms_output.put_line('count:'||vCount);
dbms_output.put_line(sql%rowcount||'行受影响');
end;
--PL/SQL执行sql语句
begin
executeimmediate'createtabletempasselect*fromdept';
end;
--动态sql,把sql语句放到变量中并传递参数
declare
sqlstrvarchar2(100);
begin
sqlstr:='insertintoscott.deptvalues(12,:1,:abc)';
--变量是按照占位符顺序插入的
executeimmediatesqlstrusing'教务部','武汉';
end;
select*fromscott.dept;
--动态sql,把查询结果赋值给变量
declare
dept_row_datascott.dept%rowtype;
sqlstrvarchar2(100);
begin
sqlstr:='select*fromscott.deptwheredeptno=11';
executeimmediatesqlstrintodept_row_data;
dbms_output.put_line(dept_row_data.deptno);
end;
--if语句
--select*fromemp;
declare
vSalemp.sal%type;
begin
selectsalintovSalfromempwhereempno=7566;
if(vSal<1200)then
dbms_output.put_line('小于1200');
elsif(vSal<2000)then
dbms_output.put_line('小于2000');
else
dbms_output.put_line('大于2000');
endif;
end;
--loop循环
declare
ibinary_integer:=10;
begin
loop
dbms_output.put_line(i);
i:=i-1;
exitwhen(i<1);
endloop;
end;
--while循环
declare
ibinary_integer:=1;
begin
whilei<11loop
dbms_output.put_line(i);
i:=i+1;
endloop;
end;
--for循环
begin
foriin1..10loop
dbms_output.put_line(i);
endloop;
foriinreverse1..10loop
dbms_output.put_line(i);
endloop;
end;
相关文章推荐
- Oracle笔记 六、PL/SQL简单语句块、变量定义
- Oracle笔记 七、PL/SQL 异常处理
- Oracle笔记 五、创建表、约束、视图、索引、序列、同义词、表空间
- Oracle笔记 四、增删改、事务
- Oracle笔记 三、function 、select
- Oracle笔记 二、常用dba命令行
- Oracle 死锁的检测查询及处理
- Oracle笔记 一、oracle的安装、sqlplus的使用
- Java 联系Oracle 数据库
- oracle之分组函数、数字函数、字符函数、转换函数和日期函数
- Hibernate在oracle中ID增长的两种方式
- oracle各种sql报错汇总
- Oracle RAC 11g 安装测试问题小结(还未测试成功)
- oracle回顾(一)
- oracle回顾(一)
- oracle group by rollup,decode,grouping,nvl,nvl2,nullif,grouping_id,group_id,grouping sets,RATIO_TO
- 老师oracle讲义第五天
- oracle学习第五天
- SAP连接外部ORACLE数据库
- oracle中的case when