PL/SQL :: Writing A Query To Delete Duplicates From A Table

Aug 16, 2012

I have data some thing like this.

NO NAME LOC SAL
------------------------------------------------------------------
1 A HYD 100
2 B BGL 200
1 A HYD 200
1 A HYD 150

I want to delete duplicate records (group by no,name,loc) but only max(qty) record should be retained. So I need output like this.

NO NAME LOC SAL
------------------------------------------------------------------
1 A HYD 200
2 B BGL 200

View 3 Replies


ADVERTISEMENT

SQL & PL/SQL :: Delete Duplicates From Table Without Using Rowid?

Mar 30, 2010

I am trying to delete duplicates from table without using rowid.

here is data:-

create table test(col1 number(3),col2 varchar2(20));
insert into test values(100,'rocky');
insert into test values(100,'rocky');

[Code]....

I know i am perfoming dml on view. IT wont allow me to perform DML on view which contain columns with expression. IS there any way to delete duplicates without using rowid?

View 36 Replies View Related

Multiple Table Query Returning Duplicates With Wrong Values

Oct 20, 2012

These are the tables I'm working with:

SQL> desc custinfo;
Name Null? Type
----------------------------------------- -------- ----------------------------
CUSTID VARCHAR2(4)
CUSTNAME VARCHAR2(18)
CUSTADR VARCHAR2(12)
CUSTCITY VARCHAR2(10)
CUSTSTATE CHAR(2)
CUSTZIP VARCHAR2(5)
CAPACITY NUMBER(3)
HOUSECODE VARCHAR2(2)
[code]...

I don't understand why the custid is the same for each customer, and why it's selecting every customer and not just those with more than 150 gallons ordered.

For this one use the oil tables that you set up and use a subquery. Select the minimum average fall use from the house table. Then show all customers whose number of gallons delivered times two is greater than the minimum.

View 4 Replies View Related

Forms :: Delete A Record By Writing Code In When_button_pressed Trigger

May 4, 2010

How can I delete a record by writing code in when_button_pressed trigger.

View 8 Replies View Related

SQL & PL/SQL :: Writing A Query To Multiply Columns

Nov 26, 2012

I am writing a query and I am trying to multiply some of the columns with *1.50 and 0.75.

The columns I am trying to multiply are coke_rebate.volumecsd and coke_rebate.volumencb. I am getting an error in oracle sql command from web "ORA-00937: not a single-group group function"

Here is the code I am writing:

SELECT CUSTOMERS.CUSTID,
CUSTOMERS.MEMBERID,
CUSTOMERS.BNAME,
COKE_REBATE.COKEID,
SUM(COKE_REBATE.VOLUMECSD*1.50) "TOTALCSD",
[code]........

View 7 Replies View Related

SQL & PL/SQL :: Delete Multiple Table Data By Single Query Without Any Condition?

May 10, 2012

can we delete multiples table through the single query?

suppose we have 2 table first one is emp and second is client

i want delete all data from emp and client through the single line query

View 1 Replies View Related

Query Return Results That Contain Duplicates - Only First Or Last Required

May 27, 2008

I have this query that returns results that contain duplicates(somewhat). I only want either the FIRST or LAST (either one is fine). Here is the query:

select unique PLLA.attribute4, PLA.item_description from po_lines_all PLA, po_line_locations_all PLLA
where PLLA.po_line_id = PLA.po_line_id
and PLLA.attribute4 is not null

So my output is something like this:

RCE12 This is an item for AUL1
RCE13 This is an item for PWEILL
RCE14 This is an item for AUL1

I just want either the RCE12 or RCE14 record and not both since they both have the same description.

View 2 Replies View Related

Forms :: Fields Not Writing To Database Table

Jul 27, 2010

I have an Oracle Form 6i. There are two blocks. One is a database block called CUSTOMER and the other is a non-database block called CONTROL.

In the PRE-INSERT trigger of the database block, values from the non-database table block are passed to the database table block. When I pass values I use the :BLOCK_NAME.field_name eg. :CUSTOMER.scale_code := :CONTROL.scale.

In this form the values passed to the database block from the non-database block in the PRE-INSERT trigger do not use the block name e.g. :-

:warehouse := :global.default_warehouse;
:capturer :=captured
:scale_code := scale;
:date_captured := sysdate;
insert into dd_audit(cus_id,cap_date) values(:CONTROL.cus_id,SYSDATE);

This application used to work fine for months, last week when writing the values in the PRE-INSERT trigger, just the warehouse field had a value. The remaining fields after the warehouse did not pass any values, although it was verified that values would have been present in the non-database block. The date_captured field should have at least had the system date. The last insert into dd_audit was successful.

I have done numerous tests on our test database and could not replicate the problem. Would passing the values from the non-database block to the database block without the :BLOCK_name preceding the field name cause this problem.

View 4 Replies View Related

SQL & PL/SQL :: Copy Into Same Table / Recursive Rename Of Duplicates

May 11, 2011

In MS Windows, if I copy a file and paste it into the same folder, I get a copy with the text 'Copy of' in front of the file name. If I paste it again, I get another copy with a different version number.

E.g.
sqlnet.log
Copy of sqlnet.log
Copy (1) of sqlnet.log
Copy (2) of sqlnet.log

I was wondering if I could copy existing rows into a table and do the same thing?

So, for example if I had this table:

create table tst_srch (srch_is varchar(100), user_name varchar(100), srch_name varchar(100));

insert into tst_srch values (1,'USER1','SRCHA');
insert into tst_srch values (2,'USER1','SRCHB');
insert into tst_srch values (3,'USER1','SRCHC');
insert into tst_srch values (4,'USER1','SRCHD');
insert into tst_srch values (5,'USER2','SRCHC');
insert into tst_srch values (6,'USER2','SRCHD');
insert into tst_srch values (7,'USER2','SRCHD_1');

Could I write a procedure like copy_searches('USER1','USER2') that would copy all USER1's searches to USER2 - including renaming any duplicates.

So it would create these new rows:

8,USER2,SRCHA
9,USER2,SRCHB
10,USER2,SRCHC_1
11,USER2,SRCHD_2

I've looked at various insert statements, merge and match statements and exception handling in procedures .

View 6 Replies View Related

SQL & PL/SQL :: Writing Procedure In User 2 Schema Accessing Table Product - Not Compiled?

Dec 17, 2010

I have got 2 users as user1 and user2.I have used the following statements from user 'user1':

create role GENEVAOBJECTS;
grant select, insert, update, delete on PRODUCT to GENEVAOBJECTS;
grant GENEVAOBJECTS to user2;

In the above statements, product is a table. Now, I could able to access this table from user 'user2'. But however if I write a procedure in user2 schema accessing the table product, then the procedure is not getting compiled.

create or replace procedure test_prc as
v_test number(9);
begin
select product_id into v_test
from PRODUCT where rownum=1;

[code]...

why I cannot access that table from procedure?

View 8 Replies View Related

Performance Tuning :: Remove Duplicates From Table Using Criteria Giving In Statement

Jun 3, 2011

I am running the following delete query and it has been running for over 2hrs:

delete from dw.ACCOUNT_FACT
where rowid in
(select rowid from DW.ACCOUNT_FACT
minus
select max(rowid) from DW.ACCOUNT_FACT

[Code]..

Here is the explan plain result:

explain plan for delete from dw.ACCOUNT_FACT
where rowid in
(select rowid from DW.ACCOUNT_FACT
minus
select max(rowid) from DW.ACCOUNT_FACT
group by CRTORD_FIPS_CD, LAST_PAYMENT_DT, ORDER_NUM,

[Code]....

PLAN_TABLE_OUTPUT

Plan hash value: 611392786

----------------------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)| Time |
----------------------------------------------------------------------------------------------------------------------
| 0 | DELETE STATEMENT | | 2604G| 260T| | 9018K (91)| 30:03:37 |
| 1 | DELETE | ACCOUNT_FACT | | | | | |
|* 2 | HASH JOIN | | 2604G| 260T| 369M|

[Code].....

Predicate Information (identified by operation id):
---------------------------------------------------

2 - access(ROWID="$kkqu_col_1")

I have all constraints disabled. How do I make this delete finish faster? We're trying to remove duplicates from this table using the criteria giving in the statement.

View 16 Replies View Related

SQL & PL/SQL :: How To Select And Delete At The Same Query

Jun 10, 2010

select SQL_CALC_FOUND_ROWS navl.xydata.Lat,
navl.xydata.Longi,
MIN(navl.xydata.GpsTime) as mn,
MAX(navl.xydata.GpsTime) as mx,
timediff(MAX(navl.xydata.GpsTime) ,MIN(navl.xydata.GpsTime) ) as idle,
[code]......

i want to delete WHERE mn = mx .

View 4 Replies View Related

Delete Query Causing Deadlock ORA-60

Nov 5, 2012

I am using oracle 10.2.0.3 and i am receiving very slow response time for the below query and sometimes resulting in a deadlock throwing ora-60 error.

DELETE FROM GBC_CORE.SPI_ELEMENT_ID TRGT WHERE (TRGT.URI) NOT IN (
SELECT DISTINCT FROMTOURI.URI FROM ( SELECT SERVICEACCESSNAME AS URI,
SUBSTR( SERVICEACCESSNAME,1,INSTR( SERVICEACCESSNAME ,'_')-1) AS
FROM_URI, SUBSTR( SERVICEACCESSNAME,INSTR( SERVICEACCESSNAME
,'_')+1,LENGTH(SERVICEACCESSNAME)) AS TO_URI FROM
TRPT.V_TRPT_SPI_VIEW@DBLNK_FCE_TRPT ) FROMTOURI,
[code]...

View 1 Replies View Related

SQL & PL/SQL :: Query To Delete Two Weeks Old Data?

Sep 12, 2013

I want to delete the records grater than two weeks old.From Saturday to Friday we are considering as Week.

P_ID CREATED_DT
105 28/AUG/2013
106 29/AUG/2013
107 30/AUG/2013
108 31/AUG/2013
109 01/SEP/2013
110 02/SEP/2013

[code]....

From 28/AUG/2013 to 30/AUG/2013 records has to be deleted becuase thease records are two weeks old.

From 31/AUG/2013 to 06/SEP/2013 records belongs to one week and from 07/SEP/2013 to 13/SEP/2013 belongs to another week.Today is 12/SEP/2013 so from 06/SEP/2013 to 12/SEP/2013 should be existed in the table.Once date changed to 13/SEP/2013 then from 31/AUG/2013 to 06/SEP/2013 records has to be deleted.

I am posting table and insert scripts.

CREATE TABLE process_data(p_id NUMBER,CREATED_DT DATE);
INSERT INTO process_data VALUES(TO_DATE('28/AUG/2013','DD/MON/YYYY');
INSERT INTO process_data VALUES(TO_DATE('29/AUG/2013','DD/MON/YYYY');
INSERT INTO process_data VALUES(TO_DATE('30/AUG/2013','DD/MON/YYYY');
INSERT INTO process_data VALUES(TO_DATE('31/AUG/2013','DD/MON/YYYY');
INSERT INTO process_data VALUES(TO_DATE('01/SEP/2013','DD/MON/YYYY');

[code]....

View 3 Replies View Related

SQL & PL/SQL :: Delete After Count Oldest Row Query?

Mar 22, 2011

I have one table that have many records. For the maintenance purpose I like to delete old record based on Customer No.-That is Mobile NO.If each Customer have more than 300 records, I like to delete by everyday batch process.can't figure out how to apply each Customer No.(Specific Column), I could sort (order by few column - SAVE_DT or SMS_ARV_CLC) how to write this kind of query? I try rownum but no more progress.

Here is my table
CREATE TABLE TM_060_SMS_TEST
(
SMS_SEQ VARCHAR2(18 BYTE),
SMS_RCV_CLC VARCHAR2(14 BYTE),
CUST_NUM VARCHAR2(12 BYTE),

[code]...

View 12 Replies View Related

SQL & PL/SQL :: Delete After Count Oldest Row Query BULK

Mar 24, 2011

I like to increase speed to delete our table. Is it possible to use BULK COLLECT or FORALL this query? This is not single delete or select, maybe I got the error? Is it possible to use BULK method to this query?

delete from
TM_060_SFS_TEST
WHERE
rowid in (
SELECT
[code]......

View 1 Replies View Related

SQL & PL/SQL :: Delete Rows Returned By Complex Join Query

Apr 5, 2013

How Can I delete the returned two rows?

1 select s.reg_no,s.course_code,
2 s.section src_sec,a.section a_sec,a.att_date,a.att_flag
3 from attendance a ,src s
4 where a.semester_code=1
5 and a.semester_year=2013
6 and s.semester_code=1
[code]....

View 6 Replies View Related

SQL & PL/SQL :: Write Query To Delete Similar Records In Particular Fields (columns) In Different Tables

Jul 17, 2012

write a query to delete similar records in particular fields(columns) in different tables.

View 2 Replies View Related

SQL & PL/SQL :: How To Delete Rows From Table

Oct 19, 2011

I am using the below proc to delete some records

1)select client_id,count(*) from TCLIENT_NOTIFICATION_PACK where client_id=1620560178 group by client_id order by 2 desc;

client_id count(*)
----------- ---------
16205601785128

2)select client_id, count(*) from TCLIENT_NOTIFICATION_PACK
where client_id=1620560178
group by client_id
having count(*) > 40
order by 2 desc
client_id count(*)
----------- ---------
16205601785128

3) select client_id,clnt_notification_pack_tid
-- bulk collect into v_client_id,v_notif_tid
from (select clnt_notification_pack_tid,
client_id,
clnt_notification_pack_typ_tid,
crte_dt,

[code]....

4) Iam using the below proc to delete the rows from table, except the 4 rows returned above

declare
v_clnt_notification_pack_tid TCLIENT_NOTIFICATION_PACK.CLNT_NOTIFICATION_PACK_TID%type;
tYPE t_client_id is table of TCLIENT_NOTIFICATION_PACK.client_id%type;
tYPE t_notif_tid is table of TCLIENT_NOTIFICATION_PACK.clnt_notification_pack_tid%type;
v_client_id t_client_id;
v_notif_tid t_notif_tid;

[code]....

5) After running this procedure, i shud see 5124 records, but i see zero records.

View 23 Replies View Related

SQL & PL/SQL :: Delete Duplication In A Table

Jul 7, 2011

I want to delete the duplicate rows in a table. there is no column which can be used to differentiate between the rows.

SELECT column_name1
FROM [table]
WHERE column_name2 = cond
GROUP BY column_name1
HAVING COUNT (column_name1) > 1

from the above query i can find the duplication in the table and can delete through it. But what i want one record of each duplication not to be deleted most probably the record added last to the table.

View 13 Replies View Related

SQL & PL/SQL :: Delete Table If Exist

Jan 18, 2013

delete table if exist

How do we write this code in oracle / sqlplus

View 4 Replies View Related

SQL & PL/SQL :: Delete Even Rows Of A Table

Oct 25, 2006

How to delete even rows of a table or rather alternate rows of a table.

View 31 Replies View Related

SQL & PL/SQL :: Getting Error While Using Delete In Table

Feb 19, 2012

Declare
Cursor Cur_Emp Is
Select Empno,Ename
From Emp;
Type Type_Emp Is Table Of Cur_Emp%Rowtype Index By Binary_Integer;
[code].......

View 4 Replies View Related

SQL & PL/SQL :: How To Delete 1% Of Rows From A Table

Jun 13, 2011

I have a table, in that i have "n" no of rows from that i want to delete 1% of rows from that table

View 26 Replies View Related

SQL & PL/SQL :: Delete Record From A Table

Oct 14, 2010

I have tried the following delete statement but it is taking long time,and it's not giving any result.

DELETE FROM hs_table WHERE sno=1234 and effdt='25-MAY-10';

The records in the table are 90000.And we are deleting only one report.

View 6 Replies View Related

SQL & PL/SQL :: Delete From A Table With Between Dates

Dec 7, 2011

I am trying to schedule a store procedure and wanted to remove some data from a table starting from a date and increase the delete by day until a specified date. I wrote the below function; but i can't get to work.

--Start
CREATE OR REPLACE FUNCTION remove_DateField return VARCHAR2 IS

i PLS_INTEGER;
startdate Date ;
endDate Date;
currentDate Date;
stopDate Date;
[code]....

View 8 Replies View Related

How To Delete Duplicate Entries In A Table

Sep 8, 2008

In oracle 9i ........How to delete duplicate entries in a table ?

if suppose in a table named office, one or more entry(row) is repeated more then twice or minimum twice.
I need a query to delete the multiple entries ....

Note:
--->No constraints applied on the table.
--->No Primary Key
--->You cannot create any object....that is no view or a duplicate table can be created

View 3 Replies View Related

Oracle 10g - Delete 1000 Table?

Dec 21, 2007

I have 1000+ tables in a DISCOVER tablespace in 10g.

I need to drop ALL tables in this area and leave the tblsp intact so that I can IMP a data update from 9i (prod) into 10g (test).

Is there an easy cmd to drop all the tbls, or am I missing someway to do this in DB Console for 10g.

View 3 Replies View Related

SQL & PL/SQL :: Delete Redundant Table In Oracle?

Apr 23, 2012

Is there a SQL query to find out the redundant or unused table in Oracle.

Some tables shows no dependencies to itself or other schemas,but has got valid data in it, deleting it will affect the functionality of the system.

View 3 Replies View Related

SQL & PL/SQL :: Parent And Child Table - Delete Row

May 18, 2010

I have a parent table and child table. I want a row to be deleted from the parent table which is referenced by a child row. Is there a way to achieve this. I dont have permission to re create the table or alter the table using delete cascade option. Is there a way to do it in sql.

SQL> create table t1(a number primary key, b number);
SQL> create table t2(c number, d number references t1(a));
SQL> insert into t1 values(1,2);
SQL> insert into t1 values(2,3);
SQL> insert into t1 values(3,4);
SQL> insert into t2 values(10,3);
SQL> insert into t2 values(20,2);
SQL> delete from t1 where a=2;
delete from t1 where a=2
*

ERROR at line 1:
ORA-02292: integrity constraint (CISBATCH.SYS_C00763501) violated - child
record found

View 11 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved