Deleting records based on date with timestamp

Hi there,
In continuation from my earlier Query. Multiple reccord have inadvertantly been inserted in the LOAN_TXN table. I want to delete all the records, except one, based on date with timestamp.
CREATE TABLE LOAN_TXN
TXN_DATE                     DATE,
BALANCE          NUMBER(10,2),
CODE          VARCHAR2(1),
INSERT INTO LOAN_TXN ( TXN_DATE, BALANCE, CODE) VALUES (TO_Date( '02/15/2010 11:00:00 AM', 'MM/DD/YYYY HH:MI:SS AM'), 250000, 'D');
INSERT INTO LOAN_TXN ( TXN_DATE, BALANCE, CODE) VALUES (TO_Date( '03/31/2010 11:59:59 AM', 'MM/DD/YYYY HH:MI:SS AM'), 250000, 'B');
INSERT INTO LOAN_TXN ( TXN_DATE, BALANCE, CODE) VALUES (TO_Date( '05/14/2010 11:25:00 AM', 'MM/DD/YYYY HH:MI:SS AM'), 500000, 'D');
INSERT INTO LOAN_TXN ( TXN_DATE, BALANCE, CODE) VALUES (TO_Date( '06/30/2010 12:15:00 PM', 'MM/DD/YYYY HH:MI:SS AM'), 4000, 'R');
INSERT INTO LOAN_TXN ( TXN_DATE, BALANCE, CODE) VALUES (TO_Date( '08/02/2010 10:45:26 AM', 'MM/DD/YYYY HH:MI:SS AM'), 4000, 'R');
INSERT INTO LOAN_TXN ( TXN_DATE, BALANCE, CODE) VALUES (TO_Date( '09/08/2010 02:10:17 PM', 'MM/DD/YYYY HH:MI:SS AM'), 4000, 'R');
INSERT INTO LOAN_TXN ( TXN_DATE, BALANCE, CODE) VALUES (TO_Date( '10/27/2010 04:25:20 PM', 'MM/DD/YYYY HH:MI:SS AM'), 4000, 'R');
INSERT INTO LOAN_TXN ( TXN_DATE, BALANCE, CODE) VALUES (TO_Date( '11/09/2010 10:15:55 AM', 'MM/DD/YYYY HH:MI:SS AM'), 4000, 'R');
INSERT INTO LOAN_TXN ( TXN_DATE, BALANCE, CODE) VALUES (TO_Date( '12/29/2010 03:10:20 PM', 'MM/DD/YYYY HH:MI:SS AM'), 4000, 'R');
INSERT INTO LOAN_TXN ( TXN_DATE, BALANCE, CODE) VALUES (TO_Date( '01/12/2011 01:11:15 PM', 'MM/DD/YYYY HH:MI:SS AM'), 4000, 'R');
INSERT INTO LOAN_TXN ( TXN_DATE, BALANCE, CODE) VALUES (TO_Date( '02/11/2011 12:11:48 PM', 'MM/DD/YYYY HH:MI:SS AM'), 4000, 'R');
INSERT INTO LOAN_TXN ( TXN_DATE, BALANCE, CODE) VALUES (TO_Date( '03/31/2011 11:59:59 PM', 'MM/DD/YYYY HH:MI:SS AM'), 4000, 'R');
INSERT INTO LOAN_TXN ( TXN_DATE, BALANCE, CODE) VALUES (TO_Date( '03/31/2011 11:59:59 PM', 'MM/DD/YYYY HH:MI:SS AM'), 4000, 'R');
INSERT INTO LOAN_TXN ( TXN_DATE, BALANCE, CODE) VALUES (TO_Date( '03/31/2011 11:59:59 PM', 'MM/DD/YYYY HH:MI:SS AM'), 4000, 'R');
INSERT INTO LOAN_TXN ( TXN_DATE, BALANCE, CODE) VALUES (TO_Date( '03/31/2011 11:00:00 AM', 'MM/DD/YYYY HH:MI:SS AM'), 4000, 'R');
INSERT INTO LOAN_TXN ( TXN_DATE, BALANCE, CODE) VALUES (TO_Date( '03/31/2011 11:59:59 AM', 'MM/DD/YYYY HH:MI:SS AM'), 460000, 'B');I want to delete mutiple records, except one, with code 'R' and TXN_DATE = '03/31/2011 11:59:59 PM' How do I do that ?

user3308033 wrote:
I think your query would delete all the duplicate records. Keeping one, I just want to delete mutiple records with timestamp : 11:59:59.
DELETE FROM loan_txn
WHERE rowid != (
                 SELECT  MIN(rowid)
                   FROM  loan_txn
                   WHERE txn_date = TO_DATE('03/31/2011 11:59:59 PM','MM/DD/YYYY HH:MI:SS AM')
                     AND code = 'R'
    AND txn_date = TO_DATE('03/31/2011 11:59:59 PM','MM/DD/YYYY HH:MI:SS AM')
    AND code = 'R'
/SY.

Similar Messages

  • Is it possible to get the updated table records based on date & time.

    Is it possible to get the updated table records based on date & time in oracle.
    Thanks in advance.

    no, actually i am asking update records using 'UPDATE
    or DELETE' statement, but not insert statement.
    Is it possible?
    I think we can do using trigger on table, but problem
    is if i am having 20 tables means i have to write 20
    trigger. i don't want like this.Of course it's still possible, typically you'll find applications with a column LAST_UPDATE, probably a LAST_UPDATED_BY and so on column. You don't say what your business need is, if you just want a one of query of updates to particular records and have a recent version of Oracle, then flashback query may well help, if you want to record update timestamps you either have to modify the table, or write some code to store your updates in an audit table somewhere.
    Niall Litchfield
    http://www.orawin.info/

  • Returning records based on the max timestamp

    I am writing a query to return records for each dat with max timestamp. so the query must return 1 record for each day with the latest timestamp. I am doing a partition over the timestamp column and wondering which analytic func gives the fastest result. This is in a data warehouse environment where there may be millions of recs.
    thanks

    My sample table has 3 columns - deptno, deptdesc, and eff_ts. There may be multiple rows for each day but I want to pick only the first (or last) record for each day.
    This is one query I am thinking about using analytic functions.
    SELECT deptno, deptdesc, eff_ts from test_dates where eff_ts in (
    select FIRST_VALUE(eff_ts)
    OVER (PARTITION BY trunc(eff_ts) ORDER BY eff_ts) eff_ts FROM test_dates)
    I can also use max (or min) timestamp and do a group by.
    SELECT deptno, deptdesc, eff_ts from test_dates where eff_ts in (
    select min(eff_ts) FROM test_dates group by trunc(eff_ts))
    Which is better (or is there any other better way) to use in a data warehousing env?

  • Deleting records from a table with 12 million records

    We need to delete some records on this table.
    SQL> desc CDR_CLMS_ADMN.MDL_CLM_PMT_ENT_bak;
    Name Null? Type
    CLM_PMT_CHCK_NUM NOT NULL NUMBER(9)
    CLM_PMT_CHCK_ACCT NOT NULL VARCHAR2(5)
    CLM_PMT_PAYEE_POSTAL_EXT_CD VARCHAR2(4)
    CLM_PMT_CHCK_AMT NUMBER(9,2)
    CLM_PMT_CHCK_DT DATE
    CLM_PMT_PAYEE_NAME VARCHAR2(30)
    CLM_PMT_PAYEE_ADDR_LINE_1 VARCHAR2(30)
    CLM_PMT_PAYEE_ADDR_LINE_2 VARCHAR2(30)
    CLM_PMT_PAYEE_CITY VARCHAR2(19)
    CLM_PMT_PAYEE_STATE_CD CHAR(2)
    CLM_PMT_PAYEE_POSTAL_CD VARCHAR2(5)
    CLM_PMT_SUM_CHCK_IND CHAR(1)
    CLM_PMT_PAYEE_TYPE_CD CHAR(1)
    CLM_PMT_CHCK_STTS_CD CHAR(2)
    SYSTEM_INSERT_DT DATE
    SYSTEM_UPDATE_DT
    I only need to delete the records based on this condition
    select * from CDR_CLMS_ADMN.MDL_CLM_PMT_ENT_bak
    where CLM_PMT_CHCK_ACCT='00107' AND CLM_PMT_CHCK_NUM>=002196611 AND CLM_PMT_CHCK_NUM<=002197018;
    Thsi table has 12 million records.
    Please advise
    Regards,
    Narayan

    user7202581 wrote:
    We need to delete some records on this table.
    SQL> desc CDR_CLMS_ADMN.MDL_CLM_PMT_ENT_bak;
    Name Null? Type
    CLM_PMT_CHCK_NUM NOT NULL NUMBER(9)
    CLM_PMT_CHCK_ACCT NOT NULL VARCHAR2(5)
    CLM_PMT_PAYEE_POSTAL_EXT_CD VARCHAR2(4)
    CLM_PMT_CHCK_AMT NUMBER(9,2)
    CLM_PMT_CHCK_DT DATE
    CLM_PMT_PAYEE_NAME VARCHAR2(30)
    CLM_PMT_PAYEE_ADDR_LINE_1 VARCHAR2(30)
    CLM_PMT_PAYEE_ADDR_LINE_2 VARCHAR2(30)
    CLM_PMT_PAYEE_CITY VARCHAR2(19)
    CLM_PMT_PAYEE_STATE_CD CHAR(2)
    CLM_PMT_PAYEE_POSTAL_CD VARCHAR2(5)
    CLM_PMT_SUM_CHCK_IND CHAR(1)
    CLM_PMT_PAYEE_TYPE_CD CHAR(1)
    CLM_PMT_CHCK_STTS_CD CHAR(2)
    SYSTEM_INSERT_DT DATE
    SYSTEM_UPDATE_DT
    I only need to delete the records based on this condition
    select * from CDR_CLMS_ADMN.MDL_CLM_PMT_ENT_bak
    where CLM_PMT_CHCK_ACCT='00107' AND CLM_PMT_CHCK_NUM>=002196611 AND CLM_PMT_CHCK_NUM<=002197018;
    Thsi table has 12 million records.
    Please advise
    Regards,
    NarayanDELETE from CDR_CLMS_ADMN.MDL_CLM_PMT_ENT_bak
    where CLM_PMT_CHCK_ACCT='00107' AND CLM_PMT_CHCK_NUM>=002196611 AND CLM_PMT_CHCK_NUM<=002197018;

  • Deleting Records based on status in another table

    Dear All,
    I am using oracle 11gR1 on Linux.
    We have two tables one holding year starting and closing dates with year status as open/closed for multiple years and multiple entities. Any year may be open for an entity.
    Relevant columns/Pk
    PK: entity_id, fin_year_id
    Cols: year_st_dt, year_end_dt, year_status
    We have another table where monthly summarized information is stored via scheduled procedure. Currently the procedure deletes all records and inserts new records.
    Relevant columns/Pk
    Cols: entity_id, year_month
    What we want is that the procedure should not delete records that related to financial years that are closed.
    How would I write a delete statement to do that?
    Regards, Imran

    Hi,
    957 posts, but still while posting a question, you have not
    1) Posted the table structure of all the tables involved. (create statement)
    2) Posted the sample input (insert statement)
    3) Posted the sample output.
    4) More importantanly posted on the correct forum.
    Regards
    Anurag Tibrewal.

  • Best way to create detail records based on data in the master record..

    Hi,
    I am using 11gr1p1 and ADF stack.
    I have a master detail relation between 2 records. I have EO and entity associations. I want to create a number detail records based on the data on the master record.
    For example
    I have a Stay Record which has begin and end date I need to create the DailyStay Record for each day for the range of begin and end date of StayRecord.
    Where should I do this? In EO implementation or in VO implementation.?
    Thanks

    Where should I do this? In EO implementation or in VO implementation.?If your child record should in no case be created without those default values, then EO.
    Otherwise, to increase reusability of your EO, then in the VO over the view link (i.e. other VO's would still be able to use your EO without having the child VO created with these defaults).
    This way your ViewObjects can also be used in a context where you don't want to copy from the masterFrank, If there's another UI flow that is so drastically different that it does not want things defaulted, then it probably needs a different VO altogether (on the same underlying EO though)

  • SQL Developer 3.2 - Exporting data with TIMESTAMP datatype

    Hi,
    We have users that are attempting to export data with the Timestamp format to Excel (xls format) using SQL Developer 3.2.  When attempting to sort the Timestamp in either asc or desc order, Excel is having issues sorting correctly.  I suggested that the user just do all the sorting within their SQL Developer session but they require the ability to slice and dice in Excel.
    This is definitely not an issue with Excel as the users have previously exported Timestamp data from Toad and been able to sort without issue.  Any thoughts as to what might resolve this issue? 
    Thanks.

    We're not formatting timestamps in Oracle as numbers/dates in Excel. They'll need to properly format the Excel column/cells to get it to sort the way they want vs being treated as simple strings.

  • Compare date with timestamp

    I have data in timestamp format like 10/06/2009 11:59:01 PM EDT. I need to compare it with sysdate after removing the PM EDT etc.
    I tried to_date, trunc etc... nothing worked. Is there a way to remove that PM EDT and compare with sysdate.

    Hi,
    What problem you face when you directly compare timestamp column with sysdate?
    select cast (systimestamp as timestamp with local time zone) -sysdate from dual;
    CAST(SYSTIMESTAMPASTIMESTAMPWITHLOCALTIMEZONE)-SYSDATE
    +000000000 00:00:00.481609Regards
    Anurag Tibrewal.

  • How to insert date with timestamp into table values

    hi,
    I have a table
    create table abc1(dob date);
    insert into abc1 values (to_date(sysdate,'RRRR/MM/DD HH24:MI:SS'))
    but when i see in data base it shows as normal date without time stamp.
    Is it possible to insert into back end with timestamp.
    Thanks..

    First, SYSDATE is a DATE already, no need to convert it to a DATE using the TO_DATE() function.
    The date ALWAYS has a time component, whether or not it is displayed is up to your NLS settings. for example:
    SQL> CREATE TABLE ABC1(DOB DATE);
    Table created.
    SQL> ALTER SESSION SET NLS_DATE_FORMAT='MM/DD/YYYY';
    Session altered.
    SQL> INSERT INTO ABC1 VALUES(SYSDATE);
    1 row created.
    SQL> SELECT * FROM ABC1;
    DOB
    02/04/2010
    SQL> ALTER SESSION SET NLS_DATE_FORMAT='MM/DD/YYYY HH24:MI:SS';
    Session altered.
    SQL> SELECT * FROM ABC1;
    DOB
    02/04/2010 12:54:57
    SQL> DROP TABLE ABC1;
    Table dropped.

  • Selecting single record from multiple record based on date

    Hi experts,
    I have a table which contains the multiple records for single ID No. Now i have to select single record which contains the latest date.
    here is the structure
    Name   Null Type        
    ID_P        NUMBER      
    NAME_P      VARCHAR2(12)
    DATE_P      TIMESTAMP(6)
    Records
    1 loosi     22-AUG-13 01.27.48.000000000 PM
    1 nammi  26-AUG-13 01.28.10.000000000 PM
    2 kk        22-AUG-13 01.28.26.000000000 PM
    2 thej      26-AUG-13 01.28.42.000000000 PM
    now i have to select below 2 rows how can write select qurie for this?
    1 loosi     26-AUG-13 01.27.48.000000000 PM
    2 thej      26-AUG-13 01.28.42.000000000 PM

    Hi,
    You can use the analytic ROW_NUMBER function.
    I don't have a copy of your table, so I'll use scott.emp to illustrate.  In scott.emp, there may be multiple rows for a single job.  To display just 1 row per job, the row with the most recent hiredate:
    WITH got_r_num AS
         SELECT  empno, job, deptno, hiredate -- Or whatever columns you want
         ,       ROW_NUMBER () OVER ( PARTITION BY  job
                                      ORDER BY      hiredate DESC
                                    )  AS r_num
        FROM    scott.emp
    --  WHERE ...   -- If you need any filtering put it here
    SELECT   *      -- Or list all columns except r_num
    FROM     got_r_num
    WHERE    r_num   = 1
    What results do you want in case of ties?  Depending on your requirements, you may want to add tie-breaking expressions to the analytic ORDER BY clause, and/or use RANK instead of ROW_NUMBER.
    I hope this answers your question.
    If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all the tables involved, and the results you want from that data.
    Point out where the query above is producing the wrong results, and explain, using specific examples, how you get the right results from the given data in those places.
    If you modify the query at all, post your modified version.
    Always say what version of Oracle you're using (e.g. 11.2.0.2.0).
    See the forum FAQ: https://forums.oracle.com/message/9362002

  • Delete records in a report with a popup

    Hi.
    In my report, the first column contains edit buttons for each record. Now, the second column should provide a delete button for each record. Is it possible to create a popup window that comes up if the user presses the button and ask to submit and to cancel? And after a submit, the record is deleted from the database and the page refreshed? How do I create this popup and the process?
    Thanks in Advance for your help.
    Stephan

    Hi Denes.
    Yes. Your example makes exactly that what I'm going to try. I had a closer look at the settings of your page and tried to transfer it to my problem.
    Unfortunately, it don't work and I don't know why.
    the URL with the javascript popup is:
    javascript:confirmDelete(htmldb_delete_message,'f?p=&APP_ID.:3010:&SESSION.:DELETE:&DEBUG.::P3010_DELETE_ID:#ACT_ID#');
    The debug modues displays the following messages:
    A C C E P T: Request="f?p=100:3010:4471084058876053:DELETE:YES::P3010_DELETE_ID:22"
    S H O W: application="100" page="3010" workspace="" request="" session="4471084058876053"
    ...Session State: Save "P3010_DELETE_ID" - saving same value: ""
    If I use the page as target of the button with the request value and the setting of delete_id it works but without a popup confirmation dialog.
    I have nearly done it like in your example. What could be the problem?
    Thanks for help
    Stephan

  • Get the todays record based on date filed

    DB Version:10g
    OS:windows 7
    Hi Guys good afternoon.
    The scenario is that i want to get the records of the employees who were hired today between 2pm to 10pm
    lets say based on hire-date field which is a date field of emp table.This is just an example.This is not the real table.
    Can anyone help me out please.
    Iam not posting the data as emp table is general table.
    Edited by: user123 on Jul 18, 2011 2:22 PM

    user123 wrote:
    Riaz Thank for the query but can you explain me what does 14/24 and 22/24 means?????In Oracle, unit of date airthmetics is day.
    Since 1 day = 24 hours, in order to add one hour to a given date, I'll need to add
    date + (1/24)In your case, since the hour portion has to be betweem 2 PM (i.e. 14 in 24 Hour format) and 10 PM (i.e. 22 in 24 Hour format), date has to incremeted by that many hours.
    So
    trunc(sysdate) +(14/24)is equal to SYSDATE 02:00:00 PM. Similarly
    trunc(sysdate) +(22/24)is SYSDATE 10:00:00 PM

  • Producing report sections based on data with previous sections

    I'm designing a event tracking report where you provide the event number to the report through a parameter, which then gets the corresponding event data.
    This then has to use the previous event number that was retrieved by said event number to get the next lot of event data and so on until it reaches a event that has a previous event number of 'NA' meaning no more events.
    So my question is how can i achieve this within crystal reports?
    I was using a parameter that could hold the multiple event numbers that resulted from a tracking search with in visual basic, and that worked fine, but i now realize that with another report that i have to produce with multiple starting events that all have to be tracked in the one report.
    For this i was just going to use a sub report within the details section but because i don't know how many sub reports would have to be produced i can't allow for enough parameters to pass the list of events in the way i was previously doing it, thus i have to let the report do the tracking for me.
    Google hasn't returned anything that would provide a solution to this problem, so any help would be gladly recieved

    I have decided to use a dataset for this where i populate it with all the events with all their traces and give each set of traced events a number, then in crystal load this dataset and group by the trace number and sort my the event number to get them in order.
    This should give me the required output, but I'm having trouble implementing the dataset with crystal reports, i have maked a strongly typed dataset and populated it with columns, then get all the data for the traces and add that to a dataset using the strongly typed dataset as a template.
    Then create the report as an object and assign the report source as the dataset and pass it to the crystal report viewer
    Unfortunately this does not have any resulting data produced on the crystal report
      Dim objRpt = New Trace_Report
            objRpt.SetDataSource(Plant_Report_Data)
            With Trace_Report__Form
                .CrystalReportViewer1.ParameterFieldInfo = paramFields
                .CrystalReportViewer1.ReportSource = objRpt
                .WindowState = FormWindowState.Maximized
                .ShowDialog()
            End With
    Any ideas?

  • Retrieve the records based on date where date is not stored

    Hi,
    I have one table in Oracle.
    I want to retrieve the records which are added or modified after a particular date & time.(but the table does not contain any column for date & time )
    For example: Product table(pid number,pname varchar2)
    i am entering 10 records on date 21/07/2005
    i am entering 20 records on date 22/07/2005
    i am entering 15 records on date 23/07/2005
    i am entering 30 records on date 24/07/2005
    If i want to retrieve the records added after 22/7/2005
    (ie.) last 45 records
    But the table does not contain any date field.
    How will you know date & time of each record updated in the table.
    If any one knows, help me.
    bye.

    for 9iR2: check out online document of Oracle9i Application Developer's Guide - Fundamentals and search flash back query
    http://download-west.oracle.com/docs/cd/B10501_01/appdev.920/a96590/adg08sql.htm#10851
    for 10G, flash back feature is enhenced to whole database level, you can still use flash back query though.

  • Getting records based on date entered by the user

    Gurus,
    I have a valid to and valid from dates in ODS. The user is allowed to enter a date on the selection screen. If the user entered date lies in between Valid from and Valid to dates only these records need to be displayed in the report.
    E.g.
    ODS:
    Valid From                   Valid to                       Functional Area
    01/01/2009                  01/01/2099                             X
    01/01/2010                  01/01/2011                             Y
    01/01/2011                  01/01/2012                             Z
    User Entered Date: 01/02/2010
    Report Output:
    X
    Y
    How do i do this? Appreciate your immedite assistance.
    Thanks,
    Ravi Ananthuni

    Hi Ravi,
    You can do this by using cust exit, but that would affect the query performance adversely.
    I would suggest that you use condition in your report.
    Include Valid to and valid from dates in your report layout. Make 2 replacement path type formula variables on these 2 dates.
    And also the date you are entering in selection option, make it a formula variable ready for input.
    Now make a CKF. In the calculation write:  (user date > valid from)AND(user date <valid to)*1.
    And apply a condition to show only those rows where this CKF is 1.
    The replacement path variables will work only when you have those 2 dates in the report layout. If you don't wanna do that , you can make 2 date type KFs and use them directly in calculation.
    I hope this helps.
    Best Wishes,
    Mayank

Maybe you are looking for

  • Quality issues from iPhoto import to iMovie!

    Can anyone explain why after you import photos (using a Canon 5.0 mp S2 digital) the clarity and resolution seems to go from clear to very fuzzy when you place the photos in the work space in iMovie! Joe McGarry

  • Question regarding Update from an ODS

    Hi Experts, I have an issue of data mismatch between oa ODS 0FIGL_O02 and the InfocubeSFIGL_C02. the infocube is getting updated through the ODS(By means of generated Datasource). I have some Question: 1) If i delete the data selectively from Infocub

  • Df error for lofs file system in local zone.

    I 've a zone which is running oracle db instance. We have exported the SAN file system from the global zone as following fs: dir: /oradb special: /oradb raw not specified type: lofs options: [] from global zone #df -h | grep oradb /dev/dsk/emcpower17

  • I don't have the new Firefox button

    I've upgraded our XP pc to Firefox & I don't have the new Firefox button - I've still got the old File - Edit etc menu at the top. The Tabs etc have all changed - it's just the button that hasn't appeared. My husband has a different XP user on the sa

  • Getting http printing to windows printer server to work! - IPP over HTTP

    Im trying to get our macs to print to our windows print server using web printing (http). The server is setup to accept anonymous as well as domain user print requests. when i add the printer using advanced setup > ipp over http and enter our printer