473,394 Members | 1,718 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes and contribute your articles to a community of 473,394 developers and data experts.

PL/SQL-CURSOR - 3

debasisdas
8,127 Expert 4TB
Sample example to show FOR UPDATE CURSOR
-----------------------------------------------------------------------------
Expand|Select|Wrap|Line Numbers
  1. DECLARE
  2. CURSOR EMPREC IS SELECT * FROM EMP FOR UPDATE OF SAL;
  3. MYREC EMPREC%ROWTYPE;
  4. NUM NUMBER(4);
  5. BEGIN
  6. OPEN EMPREC;
  7. LOOP
  8. FETCH EMPREC INTO MYREC;
  9. EXIT WHEN EMPREC%NOTFOUND;
  10. NUM:=EMPREC%ROWCOUNT;
  11. UPDATE EMP SET SAL=4000 WHERE CURRENT OF EMPREC;
  12. END LOOP;
  13. CLOSE EMPREC;
  14. DBMS_OUTPUT.PUT_LINE(NUM ||'   RECORDS UPDATED');
  15. END;
  16.  
Sample example to show PARAMETARISED CURSOR
-----------------------------------------------------------------------------------
Expand|Select|Wrap|Line Numbers
  1. DECLARE
  2. RR EMP%ROWTYPE;
  3. CURSOR C1 (MDEPTNO NUMBER,MJOB VARCHAR) IS 
  4. SELECT * FROM EMP WHERE DEPTNO=MDEPTNO AND JOB=MJOB;
  5. BEGIN
  6. OPEN C1(20,'CLERK');
  7. LOOP
  8. FETCH C1 INTO RR;
  9. EXIT WHEN C1%NOTFOUND;
  10. DBMS_OUTPUT.PUT_LINE(RR.ENAME);
  11. END LOOP;
  12. CLOSE C1;
  13. END;
  14.  
parameter can be passed to a cursor
so the cursor partially acts like a IN mode procedure.
PARAMETER is passed at the time of OPENing the cursor.

SAMPLE PROGRAM SO SHOW USE OF CURSOR WITHIN CURSOR
================================================== ==
Expand|Select|Wrap|Line Numbers
  1. declare
  2. cursor c1 is select deptno from dept order by deptno;
  3. cursor c2 (mm dept.deptno%type) is select ename from emp where deptno=mm;
  4. begin
  5. for mrec in c1 loop
  6. for mrec1 in c2(mrec.deptno) loop
  7. dbms_output.put_line(mrec1.ename);
  8. end loop;
  9. end loop;
  10. end;
  11.  

Also Check PL/SQL-CURSOR - 4
May 28 '07 #1
0 4829

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: cooldv | last post by:
i am running a website on Windows 2000 server with ASP 3 webpages and Access 2000 database. (with a hosting company) traffic is slow at this time but expect to grow. lately i have been reading...
2
by: Peter | last post by:
I run most of my SQL scripts via kornshell on AIX. I use the "here-document" to run some of the smaller ones. Example: #!/bin/ksh # Analyze the table. sqlplus...
10
by: Dagwood | last post by:
Good morning: At least it's morning where I am. :) I have a rather newbie question I'm afraid. I have VisualStudio.NET, and have installed it along with SQL server. However I can't seem to...
2
by: Ken Lindner | last post by:
I have a need to become familiar with SQL Server 2000 for work. Needless to say I am new to SQL Server any version, but not IT in general. My employer has provided me with the SQL Server 2000...
6
by: Andreas Lauffer | last post by:
I changed from Access97 to AccessXP and I have immense performance problems. Details: - Access XP MDB with Jet 4.0 ( no ADP-Project ) - Linked Tables to SQL-Server 2000 over ODBC I used...
0
by: AlessanBar | last post by:
Hello Friends !! I have a strange problem, and I need to know what would be the source of this. I have a laptop computer with the following configuration: Pentium III Brand : Toshiba Speed :...
1
by: annie | last post by:
Hi all, I have recently ported my Access 2000 app to SQL Server, keeping the Access client as the front end using linked tables. I am also using triggers on my SQL tables to trap orphan...
4
by: coosa | last post by:
Hi, I was installing SQL Server on my machine and during installation my PC freezed. It happens frequently on my machine. So i tried after restarting to install it again and since then i always...
6
by: Fuzzydave | last post by:
I am back developing futher our Python/CGI based web application run by a Postgres DB and as per usual I am having some issues. It Involves a lot of Legacy code. All the actual SQL Querys are...
14
by: Developer | last post by:
Hello All, i have recently installed VS2005 and was trying to install SQL sever 2000. I have Win XP' SP2. But when I tried installing, it only installed client tools and not the database. Can...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.