- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: pl/sql proc - delete records
Operating System - HP-UX
1748177
Members
4300
Online
108758
Solutions
Forums
Categories
Company
Local Language
back
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Discussions
back
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
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Topic Options
- 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
09-24-2008 07:34 AM
09-24-2008 07:34 AM
pl/sql proc - delete records
Hello all,
iam not much familiar on pl/sql scripting.could you please give me an idea for to write pl/sql script for the below requirement in easier method
Keep two recent records of each employee id ,delete rest of the records.
Attached table structure with this thread.
In the table structure,need to keep two recent records of each column 'EMPLID' using the date column 'AS_OF_DATE'
total count of records of the table - around 1 million.
Thanks,
Nirmal
iam not much familiar on pl/sql scripting.could you please give me an idea for to write pl/sql script for the below requirement in easier method
Keep two recent records of each employee id ,delete rest of the records.
Attached table structure with this thread.
In the table structure,need to keep two recent records of each column 'EMPLID' using the date column 'AS_OF_DATE'
total count of records of the table - around 1 million.
Thanks,
Nirmal
1 REPLY 1
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-27-2008 01:26 AM
09-27-2008 01:26 AM
Re: pl/sql proc - delete records
Hello,
some comments:
The structure appears to be a copied SAP table (concluded from column MANDT).
If yes, validate the following:
1) Within SAP usually all/most Columns should carry real values and no NULL-values.
Your structure does not show any NOT-NULL constraints, so be sure to validate, that this copy-table does not have null values that could do any damage to your required result.
2) Column MANDT is used in SAP to seperate data. Make sure, that either MANDT contains a single uniqe value, or if you need to group by or select a specific MANDT (which value ?) in addition. otherwise you might get mixed up values of diffrent clients (MANDT) with no logical sense if you do no diversification with the value of MANDT.
3) It is always very expensive and complicate to delete most of the rows of a table. Instead of delete-ing many rows and keep few, copy a few rows to a new table, "truncate" source and copy back.
This is easier to handle in terms of LOCKs, redo, undo and memory.
4) can you have more than one row result for
(MANDT)+EMPLID+AS_OF_DATE ? Which one do you like to keep if this is the case ?
select EMPLID,AS_OF_DATE ...
group by EMPLID,AS_OF_DATE
having count(*) > 1;
or (if MANDT is relevant)
select MANDT,EMPLID,AS_OF_DATE ...
group by MANDT,EMPLID,AS_OF_DATE
having count(*) > 1;
Should give you the result, if you have to do additional diversification.
5) To select the required data, you could use
oracle analytical functions.
select
...list_all_colums...,
ROW_NUMBER() OVER(PARTITION BY EMPLID ORDER BY AS_OF_DATE DESC) group_num
from ...
where
-- /* may be */ MANDT = '001' AND
group_num <=2;
If this result fits your needs create the result table.
create table result_table
as select ...all_required_columns...
from ( select ... as before )
Hope this gives you a starting point to solve the problem.
Volker
some comments:
The structure appears to be a copied SAP table (concluded from column MANDT).
If yes, validate the following:
1) Within SAP usually all/most Columns should carry real values and no NULL-values.
Your structure does not show any NOT-NULL constraints, so be sure to validate, that this copy-table does not have null values that could do any damage to your required result.
2) Column MANDT is used in SAP to seperate data. Make sure, that either MANDT contains a single uniqe value, or if you need to group by or select a specific MANDT (which value ?) in addition. otherwise you might get mixed up values of diffrent clients (MANDT) with no logical sense if you do no diversification with the value of MANDT.
3) It is always very expensive and complicate to delete most of the rows of a table. Instead of delete-ing many rows and keep few, copy a few rows to a new table, "truncate" source and copy back.
This is easier to handle in terms of LOCKs, redo, undo and memory.
4) can you have more than one row result for
(MANDT)+EMPLID+AS_OF_DATE ? Which one do you like to keep if this is the case ?
select EMPLID,AS_OF_DATE ...
group by EMPLID,AS_OF_DATE
having count(*) > 1;
or (if MANDT is relevant)
select MANDT,EMPLID,AS_OF_DATE ...
group by MANDT,EMPLID,AS_OF_DATE
having count(*) > 1;
Should give you the result, if you have to do additional diversification.
5) To select the required data, you could use
oracle analytical functions.
select
...list_all_colums...,
ROW_NUMBER() OVER(PARTITION BY EMPLID ORDER BY AS_OF_DATE DESC) group_num
from ...
where
-- /* may be */ MANDT = '001' AND
group_num <=2;
If this result fits your needs create the result table.
create table result_table
as select ...all_required_columns...
from ( select ... as before )
Hope this gives you a starting point to solve the problem.
Volker
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
News and Events
Support
© Copyright 2024 Hewlett Packard Enterprise Development LP