使用Oracle SQL Developer 编写运行 PL/SQL 块(转)


[sql]
1.declare sRight varchar2(60); 
2.        icount number(4); 
3.begin  
4.  for curTable in (select colname as  svalue from table1 where col2='test')  
5.  loop 
6.    select count(colname) into icount from mtdv2doc where right=curTable.svalue; 
7.    if icount>2 then 
8.      dbms_output.put_line(curTable.svalie); 
9.    end if; 
10.  end loop; 
11.end; 

说明:

   1. 定义变量部分放在declare之后

   2. 以begin开始,以end结束

   3. for /loop /end loop 用来循环

   4. if    /then/ end if 条件语句

    5. dbms_output.put_line() 打印数据到控制台




接下来就是如何在Oracle SQL Developer 执行这段,并看到效果了。

1.输入 用户名/密码 登录某个 database. 在worksheet中输入一下 code

2. 在下方Output 的tab中, 切换到 "DBMS Output"

3. 点击一个类似消息的图标, 控制台输出 set serveroutput on.


4.  运行代码块, 下方就会输出了。


5. 点击类似小笔的图标可以清楚控制台的内容

猜你喜欢

转载自frank1998819.iteye.com/blog/1483255