Home » SQL & PL/SQL » SQL & PL/SQL » Where not exists
Where not exists [message #18531] Mon, 04 February 2002 12:54 Go to next message
Rm69
Messages: 39
Registered: January 2002
Member
l've got a procedure that runs to populate table a.Within the same procedure l'm inserting the same data into a history table b. The first run will be okay but if l want to make sure that the records that l insert into table b are not duplicates how will l do that?

Create or replace proc .....
as

begin

end;

insert into...

select ....

from table a;

end;
Re: Where not exists [message #18545 is a reply to message #18531] Tue, 05 February 2002 03:10 Go to previous messageGo to next message
Suresh Vemulapalli
Messages: 624
Registered: August 2000
Senior Member
select col1 from tab1
group by col1 having count(*)>1;

above query returns duplicate values.
Re: Where not exists [message #18574 is a reply to message #18545] Tue, 05 February 2002 20:56 Go to previous message
Rm69
Messages: 39
Registered: January 2002
Member
l think l phrased my question wrong. The source is table A. l populate table a using the procedure. Within the same procedure
l then insert the records that l've just inserted in Table A into Table B.This is done on a daily basis and the
only way this data. So my selection should be data thats just been inserted in Table A but does not exist in Table so that l do not insert duplicates in Table B which is just a history table.

My run date is a sysdate which tells me when the run was done and change_date is an actual value passed to a parameter.
My history table should ignore any records from table A so that l have a clean table with no dups

Create or replace proc .....
as

begin
......... just selecting records,summing,count etc...then
end;

INSERT INTO Tab_B_history(
col1 ,
col1,
col1,
Run_date,
change_date)

select
col1 ,
col1,
col1,
Run_date,
change_date

from Tab_A

;
end;
Previous Topic: Executing PL/SQL code from a file
Next Topic: SQL intro-SQL tutorial just for warmers
Goto Forum:
  


Current Time: Tue Sep 28 11:13:59 CDT 2021