Oracle/PLSQL CURSOR FOR Loop

Oracle/PLSQL: CURSOR FOR Loop

The syntax for the CURSOR FOR Loop is:

FOR record_index in cursor_name
LOOP
      {.statements.}
END LOOP;

You would use a CURSOR FOR Loop when you want to fetch and process every record in a cursor. The CURSOR FOR Loop will terminate when all of the records in the cursor have been fetched.

译:当你每次想通过cursor来对每条记录进行取及操作时,就可以使用CURSOR FOR Loop。当cursor中所有的记录都取后,CURSOR FOR Loop就会终止。

Here is an example of a function that uses a CURSOR FOR Loop:

CREATE OR REPLACE Function TotalIncome
    ( name_in IN varchar2 )
    RETURN varchar2
IS
    total_val number(6);

cursor c1 is
      select monthly_income
      from employees
      where name = name_in;

BEGIN

total_val := 0;

FOR employee_rec in c1
LOOP
    total_val := total_val + employee_rec.monthly_income;
END LOOP;

RETURN total_val;

END;

In this example, we‘ve created a cursor called c1. The CURSOR FOR Loop will terminate after all records have been fetched from the cursor c1.

译:在这个示例中,我们建立了一个名为c1的cursor。当所有c1中的记录都取后,CURSOR FOR Loop就会终止。

再分享一下我老师大神的人工智能教程吧。零基础!通俗易懂!风趣幽默!还带黄段子!希望你也加入到我们人工智能的队伍中来!https://blog.csdn.net/jiangjunshow

原文地址:https://www.cnblogs.com/skiwdhwhssh/p/10341714.html

时间: 2024-08-28 18:32:04

Oracle/PLSQL CURSOR FOR Loop的相关文章

Oracle PLSQL Demo - 07.LOOP循环,以EXIT WHEN退出[EXIT in LOOP]

declare v_sal number := 6000; begin loop v_sal := v_sal + 1; dbms_output.put_line(v_sal); exit when v_sal = 8000; end loop; end;

Oracle PLSQL Demo - 06.LOOP循环,以IF判断退出[IF in LOOP]

declare v_sal number := 6000; begin loop v_sal := v_sal + 1; dbms_output.put_line(v_sal); if v_sal = 8000 then exit; end if; end loop; end;

Oracle中Cursor的用法

关键字 ?概念 ?类型 ?异常处理 一 概念 游标是SQL的一个内存工作区,由系统或用户以变量的形式定义.游标的作用就是用于临时存储从数据库中提取的数据块.在某些情况下,需要把数据从存放在磁 盘的表中调到计算机内存中进行处理,最后将处理结果显示出来或最终写回数据库.这样数据处理的速度才会提高,否则频繁的磁盘数据交换会降低效率. 二  类型   Cursor类型包含三种: 隐式Cursor,显式Cursor和Ref Cursor(动态Cursor). 1. 隐式Cursor: 1).对于Selec

Oracle/PLSQL WHERE CURRENT OF Statement

Oracle/PLSQL: WHERE CURRENT OF Statement If you plan on updating or deleting records that have been referenced by a Select For Update statement, you can use the Where Current Of statement. 译:如果你想删除或者更新被Select For Update引用的记录,你可以使用Where Current Of语句.

Oracle&PLSQL 安装及乱码问题解决

1,先到Oracle网站下载Instant Client ,如果有老版本,就不用下载了 下载回是一个压缩文件,解压之后的文件夹叫:D:/instantclient_11_2.放在你喜欢的目录即可.例如:D:/instantclient_11_2 2. 2.在D:/instantclient_11_2目录下新建目录network,在network目录下再新建admin目录,在admin目录下新建文件tnsnames.ora,使用文本编辑器打开写入如下内容: MWDB=(DESCRIPTION = 

oracle Plsql 运行update或者delete时卡死问题解决的方法

oracle Plsql 运行update或者delete时 遇到过Plsql卡死问题或者导致代码运行sql的时候就卡死. 在开发中遇到此问题的时候,本来把sql复制出来,在plsql中运行,Sql本身拼写无误,可是出现plsql卡死的情况, 在代码中,运行sql的地方打断点debug,发现运行sql,仍然没有响应.经过网上查资料,推測导致这样的情况的原因是 可能在PLSQL Developer运行update时没有commit,oracle将该条记录锁住了. 能够通过下面办法解决: 先查询锁定

MyEclipse+Weblogic+Oracle+PLSQL配置注意事项

Weblogic配置详情:<Weblogic安装与配置图文详解>Oracle+PLSQL配置详情:<PL/SQL访问远程Oracle服务器(多种方式)>MyEclipse配置:<Eclipse在开发Web项目时的配置优化>,<教你破解MyEclipse到2016年[图文详解]>虽然总结过以上开发环境的配置及优化,但是在使用的过程中依旧出现了或多或少.大大小小的问题,统一记录一下.1.MyEclipse导入工程.File-->Import-->Ge

Oracle/PLSQL: LENGTH Function-from cyber

Oracle/PLSQL: LENGTH Function This Oracle tutorial explains how to use the Oracle/PLSQL LENGTH function with syntax and examples. Description The Oracle/PLSQL LENGTH function returns the length of the specified string. Syntax The syntax for the LENGT

Oracle/PLSQL: LPAD Function-from cyber

Oracle/PLSQL: LPAD Function This Oracle tutorial explains how to use the Oracle/PLSQL LPAD function with syntax and examples. Description The Oracle/PLSQL LPAD function pads the left-side of a string with a specific set of characters (when string1 is