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),
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]......
I have written the following PL/SQL procedure to delete the records and count the number of records has been deleted.
CREATE OR REPLACE PROCEDURE Del_emp IS del_records NUMBER:=0; BEGIN DELETE FROM candidate c WHERE empid in (select c.empid from employee e, candidate c where e.empid = c.empid and e.emp_stat = 'TERMINATED' ); [code]....
I want to fetch oldest record in database table based on llast updated date ; I tried following queries..it gave me different results
SELECT EVENT_ID, RETENTION_TS FROM ( SELECT EVENT_ID, RETENTION_TS, RANK() OVER (ORDER BY RETENTION_TS) RETENTION_TS_RANK FROM EVENT ) WHERE RETENTION_TS_RANK <= 1;
select * from EVENT where rowid=(select min(rowid) from EVENT);
SELECT * FROM (select * from EVENT ORDER BY RETENTION_TS) EVENT2 WHERE rownum <= 1 ORDER BY rownum DESC;
Above query takes like 10 to 20 mins to return me the record.
I' m doing a query on multiple tables willing to get only top scorers from a certain round. Here's the relevant part of relation:
SOCCER_TEAM(TEAMID, NAME, CITY) PLAYER (PLAYERID, NAME_SURNAME, DOB, TEAMID) GAME_STATS(ROUNDID, GAMEID, TIME, PLAYERID, STATTYPE)
TIME is No between 1-90 representing the minute of the game STATTYPE is IN('GOAL', 'OWN GOAL', 'RED', 'YELLOW')
Here's my sql code for the query:
SELECT ROUNDID, NAME_SURNAME, NAME, COUNT(STATTYPE) FROM GAME_STATS, PLAYER, SOCCER_TEAM WHERE PLAYER.PLAYERID IN (SELECT GAME_STATS.PLAYERID FROM GAME_STATS WHERE STATTYPE='GOAL' AND PLAYER.TEAMID = SOCCER_TEAM.TEAMID) AND STATTYPE='GOAL' AND GAME_STATS.PLAYERID = PLAYER.PLAYERID GROUP BY ROUNDID, NAME_SURNAME, NAME ORDER BY ROUNDID, COUNT(STATTYPE) DESC
This results in correctly displaying all scorers from all the rounds, yet I haven't been able to construct the HAVING clause to display ONLY the top scorers from each round (there can be multiple of them scoring equal top amount of goals and I need to show them all)
p.s. I have underlined primary keys, while foreign keys are in cursive, if it is of any relevance
I need to modify my query so that it can give me a total(duration) and total(stlmntcharge) per day in april 2013 starting from the 1st till the 30th. At the moment my query looks like below:
SELECT sum(duration),sum(stlmntcharge) FROM voipcdr WHERE (calldate >= TO_DATE('20130401','YYYYMMDD') AND calldate <= TO_DATE('20130430','YYMMDD')) AND (remtrunkid IN (SELECT UNIQUE trunkid FROM trunks WHERE description LIKE '%Telkom%' AND gw_range_id = '61' AND trunkid like '9%'))
or remip in(SELECT UNIQUE startip FROM gateways WHERE rangename LIKE 'vo-za%' OR rangename LIKE 'PC-IS-VOIS%')
But I cannot get the count I have to do a separate Query to get the count here it is How can I put the two together to get my count information and Report information together in one Report???
Select Count(pm.description), mv.R1_State FROM windsoradm.member_mv mv
How to count siblings in a hierarchical query? I'm trying to get a listing of employees
SELECT LEVEL, last_name||', '||first_name AS Manager, count(employee_id) FROM employees START WITH manager_id IS NULL CONNECT BY PRIOR employee_id = manager_id GROUP BY level
This returns 4 levels. I'm wanting to add up the number of siblings under the level 2 instead of listing them all.
I have a table which contains two columns containing the range of some products. These range are alphanumeric and i want to calculate the count of this range by a query. .
test case: CREATE TABLE MARRIAGE_FILE_NAME ( START_SERIAL_NO VARCHAR2(10 BYTE) NOT NULL, END_SERIAL_NO VARCHAR2(10 BYTE) NOT NULL, CATCODE VARCHAR2(10 BYTE) NOT NULL,
I am Having below query which is having total 664 records and for WHERE Clause (accountno ='13987135') it is having 3 records but when i am taking count it is returning 3 at first time and again returning 4 every time from then onwords.
Need a query to find the count of presence of delimiter "," in column VAL for below mentioned table.
Table:
CREATE TABLE N_B_S_1 ( NUM NUMBER, VAL VARCHAR2(20) )
Data:
INSERT INTO N_B_S_1 VALUES(1,'A,B,C'); INSERT INTO N_B_S_1 VALUES(2,'D'); INSERT INTO N_B_S_1 VALUES(3,'ER,NF,G,H,XK'); INSERT INTO N_B_S_1 VALUES(4,'LQW,MBV'); INSERT INTO N_B_S_1 VALUES(5,'KS,YJ,WE,RQ,PM'); COMMIT;
I want to count the batch records using BATCH_ID with CASE statement ,for that i am using below query but its not working ,
SELECT COUNT(*) FROM <TABLENAME> WHERE VNBATCH_ID=CASE WHEN #SDC <10 AND #PERIOD >=10 THEN 0||#SDC||#PERIOD||#BATCH_ID WHEN #SDC <10 AND #PERIOD <10 THEN 0||#SDC||0||#PERIOD||#BATCH_ID WHEN #SDC >=10 AND #PERIOD <10 THEN #SDC||0||#PERIOD||#BATCH_ID ELSE #SDC||#PERIOD||#BATCH_ID END
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]...
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');
I am using an query to fetch the data from oracle DB and fill dataset using oledb dataadapter in ASP.net.When i run the same query in PL/SQL i am getting 14952 records,but when i am filling it to dataset i am getting only 13700 records.