Solved

FORALL in Oracle

Posted on 2011-09-27
3
336 Views
Last Modified: 2012-05-12


I have the following sample data and I just want to swap only the membereligids for the same fname,lname and dob
keeping the rest of the data as it is. The issue is there is unique constraint on the column Membereligids.

Please see the attached sample data

I am not sure how I can develop logic using CURSORS/FORALL. Can someone guide me ?

Eg: Fname - Amit
 Lname - Kumar
  has two records with the same DOB but with different membereligids. I want to swap only 40681910,40813962

Sample-data.xls
0
Comment
Question by:d27m11y
3 Comments
 
LVL 31

Expert Comment

by:awking00
ID: 36711091
Are they always just duplicates or can there also be triplicates, for example?
0
 
LVL 16

Accepted Solution

by:
Swadhin Ray earned 500 total points
ID: 37181802
Assuming there will be always duplicity based on your sample data provided.

Check the code as below:

 
--Sample table 
create table swap 
(
id number,
name varchar2(40),
dob date,
gid number
);

-- insert query 
insert into swap values(1,'NAME1','19-NOV-1959',101);
insert into swap values(2,'NAME1','19-NOV-1959',102);
insert into swap values(3,'NAME2','19-OCT-1959',103);
insert into swap values(4,'NAME2','19-OCT-1959',104);
COMMIT;


--update query
UPDATE swap a
   SET gid = (SELECT gid
                FROM swap b
               WHERE b.NAME = a.NAME AND a.ROWID <> b.ROWID);

Open in new window

0
 

Author Closing Comment

by:d27m11y
ID: 37200670
helpful!
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

Working with Network Access Control Lists in Oracle 11g (part 1) Part 2: http://www.e-e.com/A_9074.html So, you upgraded to a shiny new 11g database and all of a sudden every program that used UTL_MAIL, UTL_SMTP, UTL_TCP, UTL_HTTP or any oth…
Background In several of the companies I have worked for, I noticed that corporate reporting is off loaded from the production database and done mainly on a clone database which needs to be kept up to date daily by various means, be it a logical…
This video shows information on the Oracle Data Dictionary, starting with the Oracle documentation, explaining the different types of Data Dictionary views available by group and permissions as well as giving examples on how to retrieve data from th…
This video shows syntax for various backup options while discussing how the different basic backup types work.  It explains how to take full backups, incremental level 0 backups, incremental level 1 backups in both differential and cumulative mode a…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now