473,382 Members | 1,545 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,382 developers and data experts.

PL/SQL-CURSOR - 2

debasisdas
8,127 Expert 4TB
Using FOR LOOP in CURSOR----no need to open and close.
-----------------------------------------------------------------------------------------
Expand|Select|Wrap|Line Numbers
  1. DECLARE
  2. CURSOR DD IS SELECT * FROM EMP WHERE EMPNO=7788;
  3. BEGIN
  4. FOR D IN DD 
  5. LOOP
  6. INSERT INTO EMP10(ID ,NAME)VALUES(D.EMPNO,D.ENAME);
  7. END LOOP;
  8. COMMIT;
  9. END;
  10.  
If possible try with duplicate records.

Using simple LOOP in a CURSOR
----------------------------------------------------
Expand|Select|Wrap|Line Numbers
  1. DECLARE
  2. D EMP%ROWTYPE;
  3. CURSOR CC IS SELECT * FROM EMP WHERE EMPNO=&NO;
  4. BEGIN
  5. OPEN CC;
  6. LOOP
  7. FETCH CC INTO D;
  8. EXIT WHEN CC%NOTFOUND;
  9. INSERT INTO EMP1(ID ,NAME) VALUES (D.EMPNO,D.ENAME);
  10. END LOOP;
  11. CLOSE CC;
  12. COMMIT;
  13. END;
  14.  
the above code will copy the specified record from one table and insert to another table.
U can also commit here.

Using WHILE-LOOP in a CURSOR
-------------------------------------------------------
Expand|Select|Wrap|Line Numbers
  1. DECLARE
  2. D EMP%ROWTYPE;
  3. CURSOR CC IS SELECT * FROM EMP WHERE EMPNO=&NO;
  4. BEGIN
  5. OPEN CC;
  6. WHILE CC%FOUND  LOOP
  7. FETCH CC INTO D;
  8. INSERT INTO EMP1 VALUES(D.EMPNO,D.ENAME);
  9. END LOOP;
  10. CLOSE CC;
  11. END;
  12.  

Also check PL/SQL-CURSOR - 3
May 28 '07 #1
0 4307

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...
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...
1
by: Peter | last post by:
I've purchased VS.NET 2005 Standard and have tried to install SQL Server 2005 Express, but get the following error in the error log. Please could someone help me.... Microsoft SQL Server 2005...
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...
5
by: dbrother | last post by:
Access 2003 Win XP Pro SP3 Using SQL /ADO Recordsets in a Do Loop Hello, I'm using a random number generator based on an integer input from a user from a form that will get X number of random...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.