Oracle Toad 9.0- selection of rows based on timestamp

Hi,
I am using Oracle Toad 9.0 and am trying to pull records based on the timestamp they were modified.
To be more specific, i want to pull out the objects which were modified between 28th March 2011 and April 3rd 2011.
In my understanding it should return rows which were modified between 12 am 28th March till 11.59pm April 3rd,
Please let me know if this is correct..
If this is correct then i have a problem where the objects modified on April 3rd(12.00am to 11.59pm) are not being pulled.
Query used:
select * from tablename where cast(obj_mod_dt as date) between '28-Mar-2011' and '03-Apr-2011'
-- Results have objects modified from 28th March 12.00am to 02 Apr 11.59pm
Please let me know on why it behaves indifferently.

select * from tablename where cast(obj_mod_dt as date) between '28-Mar-2011' and '03-Apr-2011'Is obj_mod_dt not already a DATE datatype?
Why are you comparing a DATE to strings?
I think perhaps you are looking more for something like this:
select *
from tablename
where cast(obj_mod_dt as date) between to_date('28-Mar-2011','DD-Mon-YYYY') and to_date('04-Apr-2011','DD-Mon-YYYY')-(1/86400)or
select *
from tablename
where cast(obj_mod_dt as date) >= to_date('28-Mar-2011','DD-Mon-YYYY')
and cast(obj_mod_dt as date) < to_date('04-Apr-2011','DD-Mon-YYYY')Of course if obj_mod_dt is already a date column then there's no need to cast it.
If it's not a date column, then what is it? Is it varchar2? If so you should be explicit in the conversion to a DATE datatype e.g.
where to_date(obj_mod_dt,'DD-Mon-YYYY') ...and ensure you specify the correct date format for it.
Otherwise you are relying on implicit datatype conversions and it's likely that it'll break somewhere.

Similar Messages

  • Selecting duplicate rows based on a combination of columns as key

    Hi ,
    I have a table with 5 columns.
    Code ID S_DATE E_DATE Name
    1 23 01012001 null ABC
    1 09 01012001 null XYZ
    2 81 04022007 null TVU
    1 43 03092008 null XXX
    Now, I need write a select query to fetch the duplicate rows from the above table having the combination of (Code, S_DATE,E_DATE) as the key.
    So from the above example, I need to get Row1 and Row2 as output (but not Row3 as it has a different S_DATE)
    Thanks in advance for your suggestions.
    Thanks
    Edited by: thotaramesh on Mar 9, 2009 4:54 PM

    On XE;
    WITH sample_data AS (
       SELECT 1  code,23 ID, '01012001' s_date, null e_date, 'ABC' NAME FROM dual UNION ALL
       SELECT 1, 09, '01012001', null, 'XYZ' FROM dual UNION ALL
       SELECT 2, 81, '04022007', null, 'TVU' FROM dual UNION ALL
       SELECT 1, 43, '03092008', null, 'XXX' FROM dual)
    SELECT code, ID, s_date, e_date, NAME
    FROM (
       SELECT
          sample_data.*,
          COUNT(*) over (PARTITION BY code, s_date, e_date) dups
       FROM sample_data)
    WHERE dups > 1;
          CODE         ID S_DATE   E_DATE NAME
             1         23 01012001        ABC
             1          9 01012001        XYZ

  • Select distinct rows based on latest date

    Hi
    I need to produce data from two tables and return results where only data for the latest OriginationDate is returned  for each unique client. I have been trying all sorts of combinations but with no success. Any help would be appreciated
    e.g
    select
    c.client_no
    ,c.forename
    ,c.surname
    ,c.tel_no1
    ,c.tel_no2
    ,c.tel_no3
    ,o.ordernumber
    ,o.propertyidentifier
    ,o.contractorlongname
    ,o.OrderStatus
    ,o.CancelReasonDesc
    ,o.OriginationDate
    ,o.Completed
    ,DATEDIFF(d,o.OriginationDate,GETDATE())
    as Total
    FROM
    hgmclent AS c
    LEFT
    OUTER
    JOIN QLHPM_Order_Summary
    AS o
    ON
    c.client_no
    = o.ClientNumber
    WHERE
    o.Ordernumber
    IS
    NOT
    NULL
    GROUP
    BY c.client_no
    ,c.forename
    ,c.surname
    ,c.tel_no1
    ,c.tel_no2
    ,c.tel_no3
    ,o.ordernumber
    ,o.propertyidentifier
    ,o.contractorlongname
    ,o.OrderStatus
    ,o.CancelReasonDesc
    ,o.OriginationDate
    ,o.Completed
    Currently this produces the following data from which I have hidden sensitive information. What I need to show for client_no 1 is repair order 6353 which was reported on 2015-01-06 00:00:00.000 being the most recent of 12 orders for this client,
    Client No2 only has one order so this will be shown
    Client No3 should only show order number 6842 reported on 2015-01-19 00:00:00.000
    and so on.
    Can anyone help with this
    Thanks
    John

    I think he needs to return the data for the latest OriginationDate, so ORDER BY o.Completed DESC should be changed to
    ORDER BY o.OriginationDate DESC
    Row_number() Over(Partition
    by c.client_no Order
    by  o.OriginationDate
    DESC ) rn
    A Fan of SSIS, SSRS and SSAS

  • Deleting duplicate rows based on three columns in Oracle 8i

    Hi all,
    The database we use is Oracle 8i.
    The query below raises the too_many_rows exception when I launch an application. So I want to delete the duplicated rows :
    select polarisation_1, polarisation_2
    into v_pol1_tech, v_pol2_tech
    from v_cfh_lien_element
    where nom_lien = p_nom_lien
    AND num_canal_1 = p_num_canal_1
    AND freq_emise_1 = p_freq_emise_1;
    Notice that with many possible values of the parameters p_nom_lien, p_num_canal_1 and p_freq_emise_1 then the exception is raised.
    So how to delete generally the duplicated rows based on the three columns "nom_lien" , "num_canal_1" and "freq_emise_1" ?
    Thank you very much indeed.

    Check the other thread with same question deleting duplicate rows based on three columns in Oracle 8i

  • Select 10000 rows from Oracle in shortest way

    Looking for a good desicions for trasfering more than 10000 rows from
    oracle to mysql using only jdbc. Connect is mostly slow about 1 row in
    a second, rights on oracle are just for select, update, insert
    operations. I think if I can devide 10000 rows in 10 parts and transfer
    them in concurent threads and connections. Any suggestion can help me
    to solve this problem.

    See java.sql.Statement.setFetchSize(), e.g.I'm not sure that setFetchSize will have any impact on your performance. It is mostly a suggestion to the JDBC driver, and while in theory the suggestion may help, in practice I have not seen any signficant benefit when using Oracle.
    To test the speed of your fetch, try issuing your select, then loop through the resultset, getting all the columns, just don't do anything with them. You could try changing the fetchSize to see if it does have an impact in your specific architecture.
    Now that you know how fast you can 'get' all the rows, how much different is it then the 1 second per row that you are seeing when selecting and inserting (I'm assuming you haven't done this yet, sorry if you already have)?
    Assuming that you can select all rows in less then the 1 second per row in your original test; there are several things you can do to increase the speed of inserts. Try using a PreparedStatement if you are not already using one . Try using the .addBatch() and .executeBatch(). You can try changing the count of rows that are inserted on each executeBatch() command.
    If all your inserts are inserting into a single table, then I don't think multiple threads will help you, and may in fact hurt you because you could run into locking issues in the mySQL database. If you are inserting into multiple tables, then it is possible that multi-threading, done correctly, may provide some increase in overall speed.
    Oracle can be accessed with 3 different JDBC drivers. If you are using Oracle 8i or 9i, then try using the OCI8 driver instead of the thin driver. The OCI8 driver may provide some performance benefits when doing mass inserts in the older versions of Oracle. Do not use the JDBC-ODBC bridge as that will provide the worst performance.
    If I was going to move data between two different databases, and the vendor did not provide a utility to do that specifically then I would try and use the 1st db vendors unload utility to unload into a text file, and the 2nd db vendors load utility to load from that text file. These utilities have been optimized for speed far and above anything that will ever be available to you as a Java programmer using JDBC. That isn't always possible based on the architecture of your solution, but it is always preferrable.
    Best of luck to you.

  • How can I select and delete rows based on the value in one column?

    I searched through the discussion board, and found a thread on deleting blank rows, but not sure how to modify it to work with my issue.
    I have put together a rather complicated spreadsheet for designing control systems, it calculates parts needed based on check boxes selected in a second spreadsheet.
    Since not all systems require all parts there are many rows that have a 0 quantity value, I would like to select these rows and delete them once I have gone through the design phase (checking off required features on a separate sheet).
    I like the way the other thread I found will gather all the blank rows at the bottom without changing the order of the rows with data in them.
    I don't understand exactly how the formula in the other thread works well enough to modify it to look for a certain column.
    I hope I made myself clear enough here, to recap, I would like to sort the rows based on a zero value in one (quantity) column, move them (the zero quantity rows) to the bottom of the sheet, and then delete the rows with a zero quantity (I can delete them manually, but would like to automate the sorting part).
    Thanks for any help anyone can provide here.
    Danny

    I apologize but, as far as I know, Numbers wasn't designed by Ian Flemming.
    There is no "this column will be auto-destructing after two minutes"
    You will have to use your fingers to delete it.
    I wish to add a last comment :
    if your boss has the bad habit to look over your shoulder, it's time to find an other one.
    As I am really pig headed, it's what I did. I became my own boss so nobody looked over my shoulder.
    Yvan KOENIG (VALLAURIS, France) mercredi 13 juillet 2011 20:30:25
    iMac 21”5, i7, 2.8 GHz, 4 Gbytes, 1 Tbytes, mac OS X 10.6.8
    Please : Search for questions similar to your own before submitting them to the community
    To be the AW6 successor, iWork MUST integrate a TRUE DB, not a list organizer !

  • How to HIde rows based on User Selection

    I have a requirement where in I have to hide some rows based on Plant Name selected by USer at the time of opening the report.
    Here is the screen  shot:-
    Here I am seeing two Tag Types MACT and Average when User selects  Luling Plant. But When User selects some other Plant I don't want to see Tag Type 'MACT' in this table.
    We have a predefine filter for Plant.
    How can I achieve that. The data in White Rows is Average values.
    Please help.
    Regards

    Hi Shalini,
    Is user selecting Plant Name from the report prompt. If Yes, then try below-
    Create a variable-
    FilterSelect= If UserResponce("WritePromptTextHere") =" Luling Plant" and TagType inList ("MACT";"Average") Then 1 ElseIf  UserResponce("WritePromptTextHere") <>" Luling Plant" and TagType inList ("MACT";"Average") Then 3 Else 2
    Apply Filter on "FilterSelect" variable-
    FilterSelect=1 and 2
    ~Anuj

  • Selecting rows based on one column change

    Hi All -
    I need to select the rows from a table (this table has 4 columns and has a primary key and have many records for that primary key).
    I need to select all the rows for this primary key for which only one column (in this case "flag" column) has been changing from its past value.
    How can I do this?
    for example, table data is:
    ID, flag, Profile,date
    pk, Y, Profile4,01/10/10
    pk, N, Profile4, 01/08/10
    pk,N, Profile3, 01/07/10
    pk,Y, Profile3, 01/05/10
    pk,Y, Profile2, 01/03/10
    pk,N, Profile1, 01/02/10
    The output of the query I am looking for should return the following i.e. only retrieve rows whose previous flag value has been changed:
    ID, flag, Profile,date
    pk, Y, Profile4,01/10/10
    pk,N, Profile3, 01/07/10
    pk,Y, Profile2, 01/03/10
    pk,N, Profile1, 01/02/10
    Please share your expertise.
    Thanks,
    Seenu

    Hi, Seenu,
    Centinul wrote:
    It is always helpful to provide the following:
    1. Oracle version (SELECT * FROM V$VERSION)
    2. Sample data in the form of CREATE / INSERT statements.
    3. Expected output
    4. Explanation of expected output (A.K.A. "business logic")
    5. Use \ tags for #2 and #3. See FAQ (Link on top right side) for details.
    Seenu001 wrote:(1) Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bi
    PL/SQL Release 10.2.0.3.0 - Production
    CORE 10.2.0.3.0 Production
    TNS for Solaris: Version 10.2.0.3.0 - Production
    NLSRTL Version 10.2.0.3.0 - Production Good!
    (2) select 'pk' id,'Y' flag,'Profile4' profile,to_date('01/10/10','mm/dd/yy') dt from dual union all
    select 'pk','N','Profile4',to_date('01/08/10','mm/dd/yy') from dual union all
    select 'pk','N','Profile3',to_date('01/07/10','mm/dd/yy') from dual union all
    select 'pk','Y','Profile3',to_date('01/05/10','mm/dd/yy') from dual union all
    select 'pk','Y','Profile2',to_date('01/03/10','mm/dd/yy') from dual union all
    select 'pk','N','Profile1',to_date('01/02/10','mm/dd/yy') from dualNot bad. It can be made into a CREATE TABLE AS statement without a lot of work, but if you're not willing to do that little bit or work, why should anyone else?     
    (3) Expected output: I want all the rows from this table where the flags have been changed from its previous value.That's a vague description. Post the exat output, like Solomon did:
    ID F PROFILE  DT
    pk N Profile1 01/02/2010
    pk Y Profile2 01/03/2010
    pk N Profile3 01/07/2010
    pk Y Profile4 01/10/2010
    (4) I want all the rows from this table where the flags have been changed from its previous value.That's a repeat of the vague description. Explain how you get the crorrect results, with specific examples, like this:
    "The row dated January 2 should be included, because it is the oldest row in the table, regardless of what its flag is.
    The row dated January 3 should be included because ...
    The row dated January 5 should *not* be included, because ..."
    You don't have to explain every row, just every reason.
    Solomon - I tried your query but the prev_flag is not being populated, it shows null value '-'NULL is not the same as '-'. Did you issue a command like
    SET NULL "-"that would display a '-' instead of NULL?
    Solomon's query works fine for me, as it did for him. Post your code, even if you just copied it from this site. (There may have been an editing problem.)
    Frank - I tried your query, prev_flag is populated in this case but when I am using with the WITH clause, I am getting an error saying "unsupported column aliasing" , I guess WITH command doesnt allow use of column alias. The problem is that I forgot the keyword AS after the sub-query name.
    WITH     got_prev_flag     AS
         SELECT     id, flag, profile, dt     -- DATE is not a good column name
         ,     LAG (flag, 1, '??') OVER (ORDER BY dt)  AS prev_flag
         FROM     t
    --     WHERE     ...     -- any filtering goes here
    SELECT     id, flag, profile, dt
    FROM     got_prev_flag
    WHERE     flag     != prev_flag
    ;If you don't post data in an executable form, then people can't test their ideas. If people can't test their ideas, trivial mistakes like this are very likely.
    This flag column will have either
    Y or N columns. Could you tell me what is the use of "??" value.By default, LAG returns NULL for the first row. If you want to include the first row in the results, then "WHERE     flag     != prev_flag" won't work when prev_flag is NULL. We could explicitly check for "prev_flag IS NULL", but I find it cleared to override the default, and have LAG return '??' on the first row. I guessed that '??' would make the condition "WHERE     flag     != prev_flag" work, no matter what value flag had. There's nothing magical about '??'; you can use any string that will never actually match flag.

  • Insert new rows based on user selection on a table display on the screen

    Hi..
    In my requirement i need to display the line items of a PO# to the user on the screen for specific fields. Each row should also include an additonal checkbox when displayed for the user. When the user checks this check box or clicks on it a new row should be inserted below to that row with the existing data of that row being copied to newly inserted row and allowing the user to make any changes.
    The newly inserted row should also include a check box , so that when the user checks it again a new row should get inserted. Finally what ever data user enters on the screen, i should be able to update my internal table with those new values and records.
    Appreciate if anyone can guide me on how to proceed on this or any alternative approaches.
    Will reward helpful answers.
    Thanks.

    Hi ..
    Can you please be more detailed. First I need to know how to create the initial table display for the existing line items and then the techniques for inserting the new rows based on the check marks and finally add those news rows to my existing internal table..
    Appreciate ur help.
    Thanks.

  • Select rows based on condition of same row

    Hello,
    I have the following table structure and rows defind here
    http://sqlfiddle.com/#!4/3f474/3
    I would like to select rows if PRODUCT_NO is null then I need to select rows which are having IS_PAYABLE='Y'. If PRODUCT_NO is not null
    then IS_PAYABLE will be 'N' or IS_PAYABLE will be null.
    E.g.
    For PRODUCT_REG HPO_FABRIC, one PRODUCT_NO null so I need select that row only, not the other two rows.
    I can do
    select * from SUPPLIER_DETAILS where  IS_PAYABLE='Y', but what if there are many records with PRODUCT_NO having null or not null
    How can I do this using sql?

    This simple query!!!
    select *
      from supplier_details
    where (product_no is null
        and is_payable = 'Y')
       or (product_no is not null and is_payable is null);
    PRODUCT_REG                                                                                          PRODUCT_SUPPLIER_CODE PRODUCT_NO START_DATE                END_DATE                  IS_PAYABLE
    HPO_FABRIC                                                                                           JP_008                           01-AUG-01                 31-AUG-01                 Y         
    HPO_FABRIC                                                                                           JP_008                STGA-FABR1 16-AUG-01                 31-AUG-01                            --Edited:- Modified Query and Results for 2nd Requirement
    Edited by: Purvesh K on Sep 17, 2012 4:55 PM
    --Removed NVL
    Edited by: Purvesh K on Sep 17, 2012 5:04 PM

  • How to select rows based on values from other table?

    I need to select all rows from TABLE1 whose time column is NOT between fromTime and toTime from TABLE2.
    For example, those table contain following rows:
    TABLE1
    |id |time |...
    |1 | 10 |...
    |2 | 20 |...
    |... | ... |...
    TABLE2
    |fromTime|toTime|
    | 3 | 6 |
    | 10 | 16 |
    | 20 | 25 |
    So, in the case above the first and second rows shouldn't be returned by the query since 10<=10<=16 AND 20<=20<25.

    Try
    -- code #1
    SELECT id, time
    from TABLE1 as T1
    where not exists (SELECT * from TABLE2 as T2
    where T1.time between T2.fromTime and T2.toTime);
    José Diz     Belo Horizonte, MG - Brasil

  • How can I display "detailStamp" facet selectively for rows in a table ?

    Hi,
    My JDEV version is Studio Edition Version 11.1.1.5.0
    I am trying to display "detailStamp" facet selectively .
    If I read api in link below
    http://docs.oracle.com/cd/E26098_01/apirefs.1112/e17488/oracle/adf/view/rich/component/rich/data/RichTable.html
    Use the "detailStamp" facet on the Table to include a collapsable content area for each table row. Please note that the height of the open detail area will be a set height based on the height of the detailStamp component. Adding a component that changes in height (like showDetail or panelBox) will by default produce strange results when the detailStamp component's height changes.
    Detail Stamp can be selectively displayed for rows in the table by EL binding the "rendered" attribute of the "detailStamp" facet to "true" or "false". The EL binding can contain references to the table "var" attribute since during rendering it will be executed in the context of the row. Disclosure icon is displayed only for rows which have rendered="true".
    I can see that i can achieve it by setting rendered property for that facet. BUT this property is not available in Studio Edition Version 11.1.1.5.0

    Hi Frank.
    Thanks for your quick reply .
    But I am using Studio Edition Version 11.1.1.5.0 . In this version the property RENDERED of f:facet name="detailStamp" is NOT allowed.
    Edited by: user13764942 on Feb 7, 2013 5:48 AM
    Put in another way , I want to render the "detailStamp" facet selectively for rows , so for that I need the RENDERED property of "detailStamp" facet. This property is ONLY available in Jdev version 11.2 . I am using Jdev 11.1.1.5.0 so I need some alternative to RENDERED property as this property is NOT available in Jdev 11.1.1.5.0.
    Please suggest some way to achieve this behaviour of displaying "detailStamp" facet selectively ....
    Thanks!
    Edited by: Mangpal Singh on Feb 7, 2013 11:57 PM

  • How to query a row based on its rownum

    Dear all,
    what is the easiest way to query a row based on its rownum? Suppose I have the following query:
    select first_name from employees where rownum<5;
    FIRST_NAME
    Ellen
    Sundar
    Mozhe
    DavidSo Ellen has rownum 1, Sundar 2 and so on. How can I do it if I just want to query a row where Mozhe is the first_name, which is rownum 3?
    Best regards,
    Val

    JS1 wrote:
    Valerie Debonair wrote:
    I was thinking how oracle assign a rownum in a table is by how it populates the rows in the table.Hence a statement "based on its availability". Maybe my way of thinking it's not accurate?
    You are correct, your way of thinking is wholly innaccurate. Something that can easily be confirmed simply by reading the documentation:
    http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/pseudocolumns009.htm#i1006297
    okie doke... thanks for the correction

  • Combine rows based on column value

    I'm trying to combine rows based off of a common value.
    Table Data:
    Result A
    Player_ID   Player_Name  Team_Name  Points Sequence
    99999       John Smith    Bulls              50         1
    99999       John Smith    Pistons          14         2
    What i want in the output
    Result B
    Player_ID Player_Name Team_Name  Points
    99999     John Smith      Bulls           64 (50 for Bulls)Here's my main query...
    select player_id, player_name, team_name, points
    from
              SELECT player_id, player_name, team_name, sum(points) sum_points
              FROM stats_data
              WHERE season_id = 2008
              AND points > 0
              GROUP BY player_id, player_name, team_name
              ) t
    ORDER BY sum_points DESC, last_name;**The current query gives me the output from Result A
    1) Not entirely sure how to combine data based of player_id
    2) Once i figure out 1, im sure by adding the ('sum_points' for 'team_name') to the output can be done with a case statement, i think?

    Sorry about that Frank.
    Using: Oracle 10.2g
    i was incorrect about the output of the query
              SELECT player_id, sum(points) sum_points
              FROM stats_data
              WHERE season_id = 2008
              AND points > 0
              GROUP BY player_id
    )Output
    Player_ID      Sum_Points    
    99999              20        
    55455               6          
    66489               2  So the subquery is outputing the correct data
    The output of the original entire query(that you had posted) is:
    Player_ID    Player_Name   Team_Name    Points    
    99999        John Smith      Bulls               16 (8 for  Bulls)    
    55455        Bob Johnson    Rockets          6   (3 for Rockets)
    66489        Chris Terry       Kings              2   (1 Kings)Here's some more raw sample data from the table:
    Player_ID    Player_Name   Team_Name    Points     Sequence  Game_Type_ID Team_ID
    99999        John Smith      Bulls               12          1                       1                  5
    99999        John Smith      Bulls               0            1                      -1                  5
    99999        John Smith      Pistons            4           2                       1                 12
    99999        John Smith      Pistons            0           2                       -1                12
    55455        Bob Johnson    Rockets          4           1                        1                  3 
    55455        Bob Johnson    Rockets          0           1                       -1                  3 
    66489        Chris Terry       Kings              2           1                        1                  8
    66489        Chris Terry       Kings              0           1                       -1                  8So your code frank is very close, the issue is that:
    A) All players have a ('pt value' for 'team name') even if they played on the same team, which can prob. be solved with a case statement, which i tried to do in my last post.
    WITH       grouped_data     AS
              SELECT player_id, sum(points) sum_points
              FROM stats_data
              WHERE season_id = 2008
              AND points > 0
              GROUP BY player_id
    SELECT     g.player_id
    ,     s.player_name
    ,     s.team_name
    (case when sequence = 2 then g.sum_points  <==
         ||  '('
         ||  TO_CHAR (s.points)
         ||  ' for '
         ||  s.team_name
         || ')'
    else to_char (g.sum_points)
    END)     AS points
    FROM     grouped_data     g
    JOIN     stats_data     s     ON g.player_id     = s.player_id
    WHERE     s.sequence     in (1,2)     <==
    AND     s.season_id     = 2008
    AND     s.points     > 0;the output has two issues, for players who played on more than one team, like Josh Smith the output comes out as
    99999        John Smith      Pistons           20  (2 for Pistons)        
    99999        John Smith      Bulls               20While the players who played on one team came out correctly. So issue with my edit of your code is:
    A) josh smith is output 2, needs to be output once
    B)josh smith should say (Josh Smith Bulls 20 (4 for Pistons) not "99999 John Smith Pistons 20 (2 for Pistons)"
    c) Issues with "99999 John Smith Pistons 20 (2 for Pistons)" is that it listing the wrong team for him: should be Bulls and listing half of his total with the pistons in the prentices should be 4. --The reason that is because s.points needs to be summed as based off of the data there's two entries
    Hope this clears it up, thanks!
    Edited by: user652714 on Mar 11, 2009 9:28 AM

  • How not show duplicate rows based on one field

    Oracle Database 11g Enterprise Edition Release 11.2.0.3.0
    Hello
    I have a query that looks for certain scripts that did not run on a particular day compared to what ran the same day a week ago. We want to include the start_datetime and end_datetime but when I add it to the select statement it brings up all instances of the jobs that run multiple times during the day. Is there a way to exclude the extra rows based on the script_name field?
    SELECT instances.script_name,
                             instances.instance_name,
                             REGEXP_REPLACE(master.description,
                                            chr(49814),  -- em-dash
                                            '-') description
                                            --instances.start_datetime
                      FROM   xxcar.xxcar_abat_instances Instances,
                             xxcar.xxcar_abatch_master  Master
                      WHERE  1 = 1
                      AND    TRUNC(start_datetime) = TRUNC(TO_DATE(:p_StartDate, 'YYYY/MM/DD HH24:MI:SS')) - (:p_NumOfWeeks * 7)
                      AND    Instances.SCRIPT_NAME = Master.SCRIPT_NAME (+)
                      MINUS
                      SELECT script_name,
                             instance_name,
                             NULL
                             --NULL
                      FROM   xxcar.xxcar_abat_instances
                      WHERE  1 = 1
                      AND    TRUNC(start_datetime) = TRUNC(TO_DATE(:p_StartDate, 'YYYY/MM/DD HH24:MI:SS'))

    MINUS does a set operation - removing rows from the first set that exactly match the second set.
    When you add columns to the first set, you want a more restricted filtering - try a multi-column NOT IN:
    To remove multiple runs, group and get min/max
    SELECT instances.script_name,
                             instances.instance_name,
                             REGEXP_REPLACE(master.description,
                                            chr(49814),  -- em-dash
                                            '-') description,
                             min(instances.start_datetime) start_datetime,
                             min(instances.end_datetime) end_datetime
                      FROM   xxcar.xxcar_abat_instances Instances,
                             xxcar.xxcar_abatch_master  Master
                      WHERE  1 = 1
                      AND    TRUNC(start_datetime) = TRUNC(TO_DATE(:p_StartDate, 'YYYY/MM/DD HH24:MI:SS')) - (:p_NumOfWeeks * 7)
                      AND    Instances.SCRIPT_NAME = Master.SCRIPT_NAME (+)
                      AND (script_name, instance_name) NOT IN
                    ( SELECT script_name,
                             instance_name
                      FROM   xxcar.xxcar_abat_instances
                      WHERE  1 = 1
                      AND    TRUNC(start_datetime) = TRUNC(TO_DATE(:p_StartDate, 'YYYY/MM/DD HH24:MI:SS'))
    group by instances.script_name, instances.instance_name, master.descriptionYou didn't give table definitions, and the query has schemas in it, so I didn't test it.
    regards,
    David

Maybe you are looking for

  • The connection to the server has been lost

    The Connection to the server has been lost.There might have been a problem in connection to the network, or Playstation TM networkor the service provider might be temprarily busy.(CE-34861-2) 

  • Product Registration Pop

    I have a pop up reminder on the PC for the first time today to "register product and enjoy a host of benefits" - how can I get rid of it please - I've already registered and I thought it would be as simple as deleting the product registration link fr

  • Problem in connecting S-Video cable from T42 to my TV- Nothing showing in my TV

    Hi , I need your help in S-Video cable . When i am connecting my labtop ( T42 ) to my panosonic TV ,my TV doesn't show the anything from my primary screen ( labtop ) , I tried to do everything all drivers, adapters and window updates etc. But still c

  • XSLT Xpath question

    Hello all, I am kind of a newbie to the xpath sort of translation. I am curious on how to: Grab the last element with data from the input side of my xsl ? I appreciate any help on this. Jaden

  • *Automatically Delivery block on sales Order*

    Hi can you please tell me how to get delivery block automatically when creating  sales order? thanks L.C