- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: ps/sql code for merge/copy/delete
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2004 05:22 PM
01-22-2004 05:22 PM
ps/sql code for merge/copy/delete
We have a DB, with a temp_table that is loaded with data every hour via sqlldr direct parallel method.There
is also a prod_table, with indexes & daily partitions, that needs to be loaded with the data from
the temp_table, and then the coppied/merged temp_table data must be deleted from the temp_table.
Can someone please help with a PL/SQL procedure/package/trigger code that can be used for the extraction/copy/merge/delete of
data from temp_table to prod_table.
Thanks in advance!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2004 06:01 PM
01-22-2004 06:01 PM
Re: ps/sql code for merge/copy/delete
begin
insert into prod_table select * from temp_table;
delete from temp_table;
end;
/
sks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2004 06:12 PM
01-22-2004 06:12 PM
Re: ps/sql code for merge/copy/delete
Thanks for the feedback.Will the delete only delete records that were inserted? Is the sql you provided the mist optimal method
or do you have any PL/SQL code which would be better?
Thanks in advance!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2004 06:31 PM
01-22-2004 06:31 PM
Re: ps/sql code for merge/copy/delete
the optimal method will depend on the number of records you are loading.
You did not state the database versions etc.
please provide more information.
regards
Yogeeraj
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2004 06:36 PM
01-22-2004 06:36 PM
Re: ps/sql code for merge/copy/delete
This is one of the method.
Delete will delete all the rows from temp_table.
This is what I could get from your original post.
sks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2004 07:01 PM
01-22-2004 07:01 PM
Re: ps/sql code for merge/copy/delete
Apologies, the temp_table will have minimum of 10 million records per day. Any advice on most
optimum PL/SQL?
Thanks in advance!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2004 07:25 PM
01-22-2004 07:25 PM
Re: ps/sql code for merge/copy/delete
2. Drop all indexes on prod_table before bulk load to hasten the loading.
3. Recreate the index subsequently.
sks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2004 07:36 PM
01-22-2004 07:36 PM
Re: ps/sql code for merge/copy/delete
The prod_table cannot have disabled/dropped indexes during the bulk load due to users querying it.
Besides rebuilding/recreating an index on a VLOB table will take hrs in which time users will not be able
to run queries.We require a solution that will ensure fast data loads; fast prod_table loads via copy/merge and also fast querying during
copy/merge? Your assistance is most appreciated!
Thanks in advance!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2004 08:19 PM
01-22-2004 08:19 PM
Re: ps/sql code for merge/copy/delete
since you are using partitioned tables, this opens up the interesting possibility of:
yd@MYDB.MU> alter table t
2 exchange partition p_0012
3 with table NEW_DATA
4 without validation
5 /
and you could easily swap a new set of data in there at the drop of a hat (and not lose grants, etc)....
You could also turn this table with a single partition into a multi-partitioned table without a dump and reload (or using the dbms redefinition package in 9i)
Also, to rebuild the indexes you can simply use:
ALTER TABLE table_name MODIFY PARTITION part_name REBUILD UNUSABLE LOCAL INDEXES
Hope this helps!
regards
Yogeeraj
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2004 08:45 PM
01-22-2004 08:45 PM
Re: ps/sql code for merge/copy/delete
After this batch insert same rows also need to be deleted from temp_table.
sks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2004 08:56 PM
01-22-2004 08:56 PM
Re: ps/sql code for merge/copy/delete
We are looking for a pl/sql code which does the following:
a cursor containing the records selected from the temp_table, after fecthing each row, each row must be
inserted into the prod_table after which the procedure must terminate. Any ideas how to PL/SQL code the above?
Thanks in advance!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2004 09:01 PM
01-22-2004 09:01 PM
Re: ps/sql code for merge/copy/delete
You did not mention your database version.
If you have 9i DB release 2, you can also sync up the flat file with the database table using this single command:
merge into EMP e1
using EXTERNAL_TABLE e2
on ( e2.empno = e1.empno )
when matched then
update set e1.sal = e2.sal
when not matched then
insert ( empno, ename, job, mgr, hiredate, sal, comm, deptno )
values ( e2.empno, e2.ename, e2.job, e2.mgr, e2.hiredate, e2.sal, e2.comm,
e2.deptno )
/
commit;
that'll update the records in the EMP table from the flat file if they exist OR it will insert them.
Doing a direct path load would simply be:
insert /*+ append */ into emp select * from external_table;
Hope this helps!
regards
Yogeeraj
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2004 09:49 PM
01-22-2004 09:49 PM
Re: ps/sql code for merge/copy/delete
declare
i number := 0;
v_row temp_table%ROWTYPE;
cursor C1 is SELECT * FROM temp_table;
begin
OPEN C1;
LOOP
FETCH C1 INTO v_row;
EXIT WHEN C1%NOTFOUND;
insert into prod_table (f1) values (v_row.f1);
i := i + 1;
if i > 10000 then
commit;
i := 0;
end if;
END LOOP;
CLOSE C1;
delete from temp_table;
end;
/
sks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2004 10:13 PM
01-22-2004 10:13 PM
Re: ps/sql code for merge/copy/delete
Thanks for the assistance! If there are 39 columns how would one specify that in your code? And can
your code be included in a procedure?
Thanks in advance!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2004 10:30 PM
01-22-2004 10:30 PM
Re: ps/sql code for merge/copy/delete
insert into prod_table (f1, f2, ...) values (v_row.f1, v_row.f2, ...);
where .... is for more fields.
I am just checking the other part.
sks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2004 10:48 PM
01-22-2004 10:48 PM
Re: ps/sql code for merge/copy/delete
The above PL/SQL was saved as a procedure & when executed the estimated duration for a single daily
partition is 40 hrs? Is the code at its optimum?
Thanks in advance!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2004 11:00 PM
01-22-2004 11:00 PM
Re: ps/sql code for merge/copy/delete
I don't think so as rows are inserted into prod_table one by one using cursor. And we are loading lot of rows in the cursor which is in memory.
So the better soultion is what I posted first
begin
insert into prod_table select * from temp_table;
delete from temp_table;
end;
/
Above insert can be changed to following if fields names are different.
insert into prod_table (f1, f2) select f1,f2 from temp_table;
sks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2004 11:04 PM
01-22-2004 11:04 PM
Re: ps/sql code for merge/copy/delete
I am closing for the day. I am off for 3 days.
All the best. I learnt a lot while solving this post.
Regards.
sks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-23-2004 12:41 AM
01-23-2004 12:41 AM
Re: ps/sql code for merge/copy/delete
Please allow me to add the following...
You can optimize on the "best way" suggested by sks above by breaking the statement into several parts and launch them in parallel.
But this would imply some prior knowledge of the data in the temporary table.
i.e.
begin
insert into prod_table select * from temp_table;
delete from temp_table;
end;
/
would be:
Script1
begin
insert into prod_table select * from temp_table where
delete from temp_table where
end;
/
begin
insert into prod_table select * from temp_table where
delete from temp_table where
end;
/
....
....
begin
insert into prod_table select * from temp_table where
delete from temp_table where
end;
/
===========================================
where
hope this helps too!
regards
Yogeeraj
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-23-2004 09:29 AM
01-23-2004 09:29 AM
Re: ps/sql code for merge/copy/delete
I have a thought. It would require some changes to your temp table, and it would make changes to your application more difficult, but...
What about adding an additional field into your temp_table (and prod if need be, it would simplify things) that you could put a distinct identifier that would correspond to a load number.
You could generate a controlfile with a constant load number set and load the tables, and then know exactly what you are moving when you run the procedure or load.
Example:
insert into prod_table as select colB,colB from temp_table where loadnum = '1';
delete from temp_table where loadnum = '1';
This would make it so that you don't need to worry about another load infringing on data that you want to delete.
Thanks,
Brian
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-26-2004 03:55 PM
01-26-2004 03:55 PM
Re: ps/sql code for merge/copy/delete
alter table prod_table nologging;
insert /* +append */ into prod_table select * from temp_table;
alter table prod_table logging;
Once nologging attribute is set on a table, redo entry generation will be suppressed.
sks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-26-2004 05:38 PM
01-26-2004 05:38 PM
Re: ps/sql code for merge/copy/delete
Concerning Sanjay's post, i comment that "redo entry generation will NOT be suppressed" but rather minimised.
There are indexes on the table and since indexes cannot be "appended" to, they are modified. These modifications must be logged. The redo/undo for the table itself is not generated, the redo/undo for the INDEXES always is.
regards
Yogeeraj
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-26-2004 06:03 PM
01-26-2004 06:03 PM
Re: ps/sql code for merge/copy/delete
We have created the below procedure:
BEGIN
insert into prod_table select * from temp_table where loaded = 'N';
commit;
update temp_table set loaded = 'Y' where loaded = 'N';
delete from temp_table where loaded = 'Y';
commit;
END;
/
This proc works fine & is also included in a job which is scheduled to run every 30 minutes. The prolem
now is that sqlldr, which loads the data in the temp_table continuously, is killed by the procedure
& the below errors are logged to the sqlldr log file:
ORA-00604: error occurred at recursive SQL level 1
ORA-00054: resource busy and acquire with NOWAIT specified
Any ideas how we could resolve these conflicts?
Thanks in advance!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-26-2004 06:26 PM
01-26-2004 06:26 PM
Re: ps/sql code for merge/copy/delete
There are two methods in SQL*loader-
1. Direct Path Load - Other users can't make changes to tables.
2. Conventional Load - Other users can make changes to tables.
How temp_table is populated in your case? I also need to study more on SQL*Loader.
Regards.
sks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-26-2004 06:45 PM
01-26-2004 06:45 PM
Re: ps/sql code for merge/copy/delete
We are using direct load method for sqlldr as its more faster that conventional!
Thanks in advance.