473,609 Members | 1,965 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

PL/SQL-CURSOR - 3

debasisdas
8,127 Recognized Expert Expert
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 4849

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

Similar topics

3
3343
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 about sql database and sql server, specially this article: http://www.aspfaq.com/show.asp?id=2195 will someone help me understand: 1. with *SQL Server*, do i keep my current Access 2000 database and ASP pages?
2
12653
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 ${SCHEMA_NM}/${SCHEMA_PASSWD}@${DB_NM} <<-ANALYZE_TABLE SET TERMOUT ON
10
6728
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 find an administration front-end to SQL, other than the VisualStudio, which is ok for creating databases and adding tables/columns. However when I go to generate create script, I'm told that I need client tools.
2
15216
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 Personal disk from the SQL Server 2000 Enterprise kit as this is reported here on the MSDN web site to be the version that is supported on Windows XP. In fact so many of you kind people confess to having succeeded in doing it. I have tried...
6
6763
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 the SQL Profile to watch the T-SQL-Command which Access ( who creates the commands?) creates and noticed:
0
4119
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 : 500 Mhz RAM : 192 MB Hard Disk : 6 GB
1
8044
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 records and validate added data. My question is..
4
7295
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 get the same error message: "An error occurred while creating one or more registry entries. Please see C:\WINDOWS\sqlstp.log for details. The problem could be caused by a low registry quota condition" I have tried to clean the registry and i...
6
2489
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 stored in the .py files and run in the .cgi files. I have the problem that I need to construct a row from two seprate SQL Querys, I have tried combining the two Querys but all that does is create a Query that returns nothing after a long period...
14
3018
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 anyone please help me with this as I want to install SQL server and also wouold be grateful, if you can suggest me any workaround to dealwith this problem.(Like should I install any new OS etc). Any help would be appreciated.
0
8145
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8095
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8588
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8556
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8236
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8410
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7030
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6068
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
1690
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.