Merge with where clause after matched and unmatched

Hai,
Can anybody give me one example of merge statement with
where clause after matched condition and after the unmatched condition.
MERGE INTO V1 VV1
USING (SELECT     A.CNO XXCNO, A.SUNITS XXSU, A.DDATE XXDD, XX.SUM_UNITS SUMMED
FROM V1 A,
(SELECT                
SUM(SUNITS) SUM_UNITS FROM V1 B                                   
GROUP BY CNO) c
WHERE
A.DDATE=0 AND A.SUNITS <>0 AND
A.ROWID=(SELECT MAX(ROWID) FROM V1 )) XX
ON (1=1)
WHEN MATCHED THEN UPDATE SET
VV1.SUNITS=XX.SUMMED
WHERE XX.XXDD=0
WHEN NOT MATCHED THEN INSERT
(VV1.CNO, VV1.SUNITS, VV1.SUNITS)
VALUES (XX.XXCNO, XX.XXSU, XX.XXDD)
WHERE XX.XXDD<>0
i am getting the error
WHERE XX.XXDD=0
ERROR at line 13:
ORA-00905: missing keyword
Thanks,
Pal

One of the example is there:
http://download-west.oracle.com/docs/cd/B14117_01/server.101/b10759/statements_9016.htm#sthref7014
What Oracle version do you use ?
Besides the condition (1=1) is non-deterministic,
I would expect there an exception like "unable to get a stable set of rows".
Rgds.

Similar Messages

  • Urgent: Performance problem with where clause using IN and an OR condition

    Select statement is:
    select fl.feed_line_id
    from ap_expense_feed_lines_all fl
    where ((:1 is not null and
    fl.feed_line_id in (select distinct r2.object_id
    from xxdl_pcard_wf_routing_lists r2,
         per_people_f hr2
    where upper(hr2.full_name) like upper(:1||'%')
              and hr2.person_id = r2.person_id
    and r2.fyi_list is null
              and r2.sequence_number <> 0))
    or
    (:1 is null))
    If I modify the statement to remove the "or (:1 is null))" part at the bottom of the where clause, it returns in .16 seconds. If I modify the statement to only contain the "(:1 is null))" part of the where clause, it returns in .02 seconds. With the whole statement above, it returns in 477 seconds. Anyone have any suggestions?
    Explain plan for the whole statement is:
    (1) SELECT STATEMENT CHOOSE
    Est. Rows: 10,960 Cost: 212
    FILTER
    (2) TABLE ACCESS FULL AP.AP_EXPENSE_FEED_LINES_ALL [Analyzed]
    (2) Blocks: 8,610 Est. Rows: 10,960 of 209,260 Cost: 212
    Tablespace: APD
    (6) TABLE ACCESS BY INDEX ROWID HR.PER_ALL_PEOPLE_F [Analyzed]
    (6) Blocks: 4,580 Est. Rows: 1 of 85,500 Cost: 2
    Tablespace: HRD
    (5) NESTED LOOPS
    Est. Rows: 1 Cost: 4
    (3) TABLE ACCESS FULL XXDL.XXDL_PCARD_WF_ROUTING_LISTS [Analyzed]
    (3) Blocks: 19 Est. Rows: 1 of 1,303 Cost: 2
    Tablespace: XXDLD
    (4) UNIQUE INDEX RANGE SCAN HR.PER_PEOPLE_F_PK [Analyzed]
    Est. Rows: 1 Cost: 1
    Thanks in advance,
    Peter

    Thanks for the reply, but I have already checked what you are suggesting and I am pretty sure those are not causing the problem. The hr2.full_name column has an upper index and the (4) line of the explain plan shows that index being used. In addition, that part of the query executes on its own quickly.
    Because the sql is not displayed in an indented format on this page it is a little hard to understand the structure so I am going to restate what is happening.
    My sql is:
    select a_column
    from a_table
    where ((:1 is not null) and a_column in (sub-select statement)
    or
    (:1 is null))
    The :1 bind variable is set to a varchar2 entered on the screen of an application.
    If I execute either part of the sql without the OR condition, performance is good.
    If the :1 bind variable is null with the whole sql statement (so all rows or a_table are returned), performance is still good.
    If the :1 bind variable is a not-null value with the whole sql statement, performance stinks.
    As an example:
    where (('wa' is not null) and a_column in (sub-select statement)) -- fast
    where (('wa' is null)) -- fast
    where (('' is not null) and a_column in (sub-select statement) -- fast
    or
    ('' is null))
    where (('wa' is not null) and a_column in (sub-select statement) -- slow
    or
    ('wa' is null))

  • Export (expdp) with where clause

    Hello Gurus,
    I am trying to export with where clause. I am getting below error.
    Here is my export command.
    expdp "'/ as sysdba'" tables = USER1.TABLE1 directory=DATA_PUMP dumpfile=TABLE1.dmp logfile=TABLE1.log query= “USER1.TABLE1:where auditdate>'01-JAN-10'” Here is error
    [keeth]DB1 /oracle/data_15/db1> DATA_PUMP dumpfile=TABLE1.dmp logfile=TABLE1.log query= USER1.TABLE1:where auditdate>'01-JAN-10'                    <
    Export: Release 11.2.0.3.0 - Production on Tue Mar 26 03:03:26 2013
    Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.
    Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
    With the Partitioning, OLAP, Data Mining and Real Application Testing options
    Starting "SYS"."SYS_EXPORT_TABLE_03":  "/******** AS SYSDBA" tables=USER1.TABLE1 directory=DATA_PUMP dumpfile=TABLE1.dmp logfile=TABLE1.log query= USER1.TABLE1:where auditdate
    Estimate in progress using BLOCKS method...
    Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
    Total estimation using BLOCKS method: 386 MB
    Processing object type TABLE_EXPORT/TABLE/TABLE
    Processing object type TABLE_EXPORT/TABLE/GRANT/OWNER_GRANT/OBJECT_GRANT
    Processing object type TABLE_EXPORT/TABLE/INDEX/INDEX
    Processing object type TABLE_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
    Processing object type TABLE_EXPORT/TABLE/TRIGGER
    Processing object type TABLE_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
    ORA-31693: Table data object "USER1"."TABLE1" failed to load/unload and is being skipped due to error:
    ORA-00933: SQL command not properly ended
    Master table "SYS"."SYS_EXPORT_TABLE_03" successfully loaded/unloaded
    Dump file set for SYS.SYS_EXPORT_TABLE_03 is:
      /oracle/data_15/db1/TABLE1.dmp
    Job "SYS"."SYS_EXPORT_TABLE_03" completed with 1 error(s) at 03:03:58Version
    SQL> select * from v$version;
    BANNER
    Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
    PL/SQL Release 11.2.0.3.0 - Production
    CORE    11.2.0.3.0      Production
    TNS for IBM/AIX RISC System/6000: Version 11.2.0.3.0 - Production
    NLSRTL Version 11.2.0.3.0 - Production

    Hello,
    You should use parameter file.Another question i can see you are using 11g.Why don't you use data pump?.
    Data Pump is faster and have more features and enhancement than regular imp and exp.
    You can do the following:
    sqlplus / as sysdba
    Create directory DPUMP_DIR3  for 'Type here your os path that you want to export to';then touch a file:
    touch par.txt
    In this file type the following the following :
    tables=schema.table_name
    dumpfile=yourdump.dmp
    DIRECTORY=DPUMP_DIR3
    logfile=Your_logfile.log
    QUERY =abs.texp:"where hiredate>'01-JAN-13' "then do the following
    expdp username/password parfile='par.txt'
    If you will import from Oracle 11g to version 10g then you have to addthe parameter "version=10" to the parameter file above
    BR
    Mohamed ELAzab
    http://mohamedelazab.blogspot.com/

  • Outer Join with Where Clause in LTS

    HI all,
    I have a requirement like this in ANSI SQL:
    select p1.product_id, p1.product_name, p2.product_group
    from product p1 left outer join product_group p2 on p1.product_id = p2.product_id
    and p2.product_group = 'NEW'
    In Regular SQL:
    select p1.product_id, p1.product_name, p2.product_group
    from product p1, product_group p2
    WHERE p1.product_id *= p2.product_id and p2.product_group = 'NEW'
    In OBIEE, I am using a left outer join between these two in Logical table Source, and also, Gave
    p2.product_group = 'NEW' in WHERE clause of LTS.
    This doesn't seem to solve purpose.
    Do you have any idea how to convert WHERE clause in physical query that OBIEE is generating to something like
    product p1 left outer join product_group p2 on p1.product_id = p2.product_id AND p2.product_group = 'NEW'
    I am using Version 10.1.3.4.1
    Creating an Opaque view would be my last option though.

    Hello
    I have read your post and the responses as well. and I understand that you have issues with the Outer Join with where Clause in LTS.
    Try this solution which worked for me (using your example ) -
    1. In the Physical Layer created a Complex join between PRODUCT and PRODUCT_GROUP tables and use this join relationship :
    PRODUCT.PROD_ID = PRODUCT_GROUP.PROD_ID  AND  PRODUCT_GROUP.GROUP_NAME = 'MECHANICAL' 
    2. In the General Tab of PRODUCT table LTS add PRODUCT_GROUP  table and select Join Type as Left Outer Join.
    3. Check Consistency and make sure there are no errors .
    when you run a request you should see the following query generated -
    select distinct T26908.PROD_ID as c1,
         T26908.PROD_NAME as c2,
         T26912.GROUP_NAME as c3
    from
         PRODUCT T26908 left outer join PRODUCT_GROUP T26912 On T26908.PROD_ID = T26912.PROD_ID and T26912.GROUP_NAME = 'MECHANICAL'
    order by c1, c2, c3
    Hope this works for you. If it does please mark this response as 'Correct' .
    Good Luck.

  • Insert with Where Clause

    Hi,
    Can we write Insert with 'Where' clause? I'm looking for something similar to the below one (which is giving me an error)
    insert into PS_AUDIT_OUT (AUDIT_ID, EMPLID, RECNAME, FIELDNAME, MATCHVAL, ERRORMSG)
    Values ('1','10000139','NAMES','FIRST_NAME',';','')
    Where AUDIT_ID IN
    (  select AUDIT_ID from PS_AUDIT_FLD where AUDIT_ID ='1' and RECNAME ='NAMES'
    AND FIELDNAME = 'FIRST_NAME' AND MATCHVAL = ';' );
    Thanks
    Durai

    It is not clear what are you trying to do, but it looks like:
    insert
      into PS_AUDIT_OUT(
                        AUDIT_ID,
                        EMPLID,
                        RECNAME,
                        FIELDNAME,
                        MATCHVAL,
                        ERRORMSG
    select  '1',
            '10000139',
            'NAMES',
            'FIRST_NAME',
      from  PS_AUDIT_FLD
      where AUDIT_ID = '1'
        and RECNAME ='NAMES'
        and FIELDNAME = 'FIRST_NAME'
        and MATCHVAL = ';'
    SY.

  • Hierarchical query with where clause

    Hi,
    How can I query hierarchically a query with WHERE clause? I have a table with three fields session_id,id and root_id.
    When I try with the following query,
    select id, level from relation
    where session_id = 79977
    connect by prior id = root_id start with id = 5042;
    It gets duplicate values.
    I want the query to show in the hierarchical manner with a filter condition using WHERE clause. Please help me how can I achieve this. If you know any link that describes more about this, please send it.
    Thanks in Advance.
    Regards,
    -Parmy

    Hi Sridhar Murthy an others,
    Thanks a lot for your/the answer. It's working for me. It saved a lot of other work around without the proper knowledge of hierarchical query. Please send me any link that describes these issues in detail and also I hope as I have mentioned in the other message, same cannot be achieved on views or ( on two different tables ???)
    Any way thanks for your reply,
    It's working for me.
    With happiness,
    -Parmy

  • Populate list by executing query with where clause

    Hi,
    I m populating my list from database table using following command.
    EntityManagerFactory emf = Persistence.createEntityManagerFactory("learning", new HashMap());
    EntityManager em = emf.createEntityManager();
    String query = "select d from Dept d";
    List list = em.createQuery(query).getResultList();
    My list is getting populated with all of rows in my database table(dept). The problem is, I cant use where clause in my query string.
    String query = "select d from Dept d where d.dept_name='ANYNAME'";
    Moreover I cant select even indivisual columns by using following line
    String query = "select d.dept_code,d.dept_name from Dept d";
    It looks like that my query is getting all rows from table as Object.
    What to do to
    1. put some where clause
    2. get some particular colums instead of all columns
    3. apply some table joins in query
    plz help.

    Hi Alex,
    I misunderstood your question. You had mentioned "My list is getting populated with all of rows in my database table(dept). The problem is, I cant use where clause in my query string. "
    I thought you might not have permissions to modify the code in the class, and that's why I suggested that you could write new classes.
    1) write new classes,? means if I need just two columns from a table >(instead of all columns), do I need to write new class with just two >columns (getters and setters)?You can write a SQL statement anyway you want , there are no restrictions in JDBC , so if you need just 2 columns you can write a custom query for that.
    "select column1 as a, column2 as be from table_name where column3 = xyz" etc.
    2) Is not anyway to write SQL statement like
    select dept_code,dept_name from dept where dept_name='anything'The above SQL is correct, it should work.
    3) Stored procedures? can I get some example(code) to get an idea >how to implement complex queries with where clause and joinings >using stored procedures?Stored procedures are specific to the database you are using, Oracle has a particular syntax for store procdures.
    You can call stored procedures from JDBC also, search on Google for
    "Calling stored procedures from JDBC"
    4) I m using hibernate. can I get any example of using hibernate own >query?Tutorial on Hibernate Query Language:
    http://www.hibernate.org/hib_docs/v3/reference/en/html/queryhql.html

  • Have to papulate table with matched and unmatched data

    Hi all
    I have to populate tables suppose T1 and T2 on the basis of a SELECT satement with various WHERE clause.
    now the problem is i have to Put the matched data in T1 and the remaing unmatched data in T2.
    Please reply
    thanks

    well i dont think this will work in my case.
    Let me tell you exact scene
    Table T has columns which contains records.
    Now i have to Build a procedure the logic of proc should be
    When that proc run the good records should goes to Table T1 and the bad records to T2.
    and bad records are determind with where cluase like e.g
    "where col1 not like 'rec2.1' " and many other clauses.
    so here an eg
    Table T
    col1 col2 col3
    rec1.1 rec1.2 rec1.3
    Now when proc run I have to sort the records on condition Where so n so
    And required out put should be
    Table T1
    Col1 col2 col3
    rec1.1 rec1.2 rec1.3 -----good record
    Table T2
    col1 col2 col3
    rec2.1 rec2.2 rec3.3 ----- bad record
    I guess this will help to understand prob.

  • Problem with date fields in where clause after changing driver

    Hi,
    We have changed the oracle driver we use to version 10
    and now we have some trouble with date-fields.
    When we run this SQL query from our Java program:
    select *
    from LA_TRANS
    where LA_TRANS.FROM_DATE>='20040101' AND LA_TRANS.FROM_DATE<='20041231'
    We get this error code:
    ORA-01861: literal does not match format string
    The query worked fine whit the previous driver.
    Is there some way I can run a SQL query with date fields
    as strings in the where clause?
    Thanks!

    Keeping the argument of standard SQL or not aside, comparing DATE columns to a constant string (which looks like a date in one of the thousands of the formats available, but not in others) is NOT one of the best programming practices and leads to heartburn and runtime errors (as you have seen yourself).
    I would rather compare a DATE to a DATE.
    Also, constants like that would be another issue to fix in your code:
    http://asktom.oracle.com/pls/ask/f?p=4950:8:6899751034602146050::NO::F4950_P8_DISPLAYID,F4950_P8_CRITERIA:528893984337,

  • Select sdo_nn with where-clause on large table

    Hi spatial-experts,
    I've following problem. I use a table with more than 2.500.000 dataset. Every dataset represents one point (SDO_GEOMETRY, SDO_POINT_TYPE) and have further (text) information. (PI (point of interest) table from TeleAtlas mn_pi)
    Following Select works fine:
    SELECT /*+ ORDERED NO_INDEX(pi IX_PI_FEATTYP) */
    sdo_nn_distance(1) distance,
    id, feattyp, arnamelc, name, stname, stnamelc, hsnum, postcode
    FROM multinet.mn_pi pi
    WHERE
    pi.feattyp IN ( 9373,9374)
    AND
    SDO_NN(
    pi.geom,
    SDO_GEOMETRY( 2001, 8307, SDO_POINT_TYPE(613.86865234375/60, 3002.94677734375/60, NULL), NULL, NULL),
    'sdo_batch_size=0', 1) = 'TRUE'
    AND rownum = 1
    ORDER BY distance
    (P.S. IX_PI_FEATTYP is an index on column feattyp, here not used. When I'm using it the select do not work (it last very long...))
    When I now modify the where clause to an pi which feat type that does not exists (no entry in table) the select lasts very long (I canceled the select after 5 minutes).
    for example: pi.feattyp = 9756
    Otherwise I add a further where clause like
    AND arnamelc = 'ITA'
    the select also works very long. The point are now in italy. refrence point is in germany and is more than 500km away.
    Are there some solutions to solve this problems
    (should I use for every feat type a own table)?
    Why is the select so slow?
    Thanks for all helpfully answers,
    Matthias

    Hi Matthias,
    When you use nearest neighbor, Oracle will use the spatial index to find the nearest neighbor that meets the query criteria. It probes into the index, calculates distances, and returns data in distance order.
    Using SDO_BATCH_SIZE, it keeps going back to the database, returning more and more records in distance order until the other predicates are satisfied (in your case, pi.feattyp IN ( 9373,9374).
    When you specified pi.feattyp = 9756 (which doesn't exist), you told Oracle to keep going and calculating distances for each of the more than 2.500.000 records in the the data set (you killed it after 5 minutes).
    I don't know why adding: AND arnamelc = 'ITA' caused Oracle to take extra time. Sometimes I will do a: set autotrace trace exp
    then compare plans for something that runs quickly vs. something that runs slowly. If you want to post the plans for the fast and slow versions it might be interesting to look at.
    My guess is you may want to look at a solution that incorporates various possibilities. For instance, if there are only a few of some feattyp values, you may want to select those using the non-spatial index then use sdo_geom.sdo_distance to find the closest point rather than risk having to look through a few million values for a match.
    I'm sure other people have thoughts as well...
    Kind regards,
    Dan

  • DB Adapter wizard – WHERE clause on parent and child tables not working.

    I have two tables, SECURITY and SECURITY_POSITIONS, where SECURITY has a 1:M relationship with SECURITY_POSITIONS. I used the DB-adapter wizard to create the relationship and the following WHERE clause expression which is looking at both the parent and the child tables;
    The expression builder looks like this:
    AND
    |--- 1. partitionKey EQUAL p_SearchKey
    |--- 2. securityType EQUAL “DBT”
    |--- 3. securityPositionsCollection.dealReference EQUAL “NA”
    The primary key on SECURITY = PARTITION_KEY and SECURITY_REFERENCE
    The foreign key from SECURITY_POSITIONS to SECURITY = PARTITION_KEY and SECURITY_REFERENCE
    securityType is on SECURITY table (master)
    securityPositionsCollection.dealReference is on SECURITY_POSITIONS table (child)
    The invoke on the database adapter is selecting a row in securityPositionsCollection for each child row, rather than just those with dealReference = “NA”!
    I turned on DEBUG logging in the BPEL console and I can see that there are 2 SELECT queries run (guess this is how Toplink does it!), where the 1st query appears to select the parent rows and the 2nd query selects the child rows.
    However the 2nd query is not working because it is failing to select only those child rows where dealReference = “NA”. Also, don’t know why the 2nd SELECT query needs to specify the child SECURITY_POSITIONS table twice in the FROM clause, because that seems to be causing the problem.
    1st query executed is as follows;
    SELECT DISTINCT t0.PARTITION_KEY, t0.SECURITY_REFERENCE, t0.SECURITY_TYPE
    FROM CENTRAL.SECURITY t0, CENTRAL.SECURITY_POSITIONS t1
    WHERE ((((t0.PARTITION_KEY = ?) AND (t0.SECURITY_TYPE = ?)) AND (t1.DEAL_REFERENCE = ?)) AND ((t1.SECURITY_REFERENCE = t0.SECURITY_REFERENCE) AND (t1.PARTIT
    ION_KEY = t0.PARTITION_KEY)))
    bind => [200706200000, DBT, NA]
    2nd query executed is as follows, where child table appears twice! ;
    SELECT DISTINCT t0.DEAL_REFERENCE, t0.PARTITION_KEY, t0.SECURITY_REFERENCE
    FROM CENTRAL.SECURITY_POSITIONS t0,
    CENTRAL.SECURITY_POSITIONS t2,
    CENTRAL.SECURITY t1
    WHERE ((((t0.SECURITY_REFERENCE = t1.SECURITY_REFERENCE) AND (t0.PARTITION_KEY = t1.PARTITION_KEY)) AND
    (((t1.PARTITION_KEY = ?) AND (t1.SECURITY_TYPE = ?)) AND
    (t2.DEAL_REFERENCE = ?))) AND
    ((t2.SECURITY_REFERENCE = t1.SECURITY_REFERENCE) AND
    (t2.PARTITION_KEY = t1.PARTITION_KEY)))
    bind => [200706200000, DBT, NA]
    Anyone experienced the same problem e.g. why is toplink making the query more complicated that it needs to be, because the query only needs to reference the SECURITY_POSITIONS table once, as follows;
    SELECT DISTINCT t0.DEAL_REFERENCE, t0.PARTITION_KEY, t0.SECURITY_REFERENCE
    FROM CENTRAL.SECURITY_POSITIONS t0,
    CENTRAL.SECURITY t1
    WHERE ((((t0.SECURITY_REFERENCE = t1.SECURITY_REFERENCE) AND (t0.PARTITION_KEY = t1.PARTITION_KEY)) AND
    (((t1.PARTITION_KEY = '200706200000') AND (t1.SECURITY_TYPE = 'DBT')) AND
    (t0.DEAL_REFERENCE = 'NA'))) AND
    ((t0.SECURITY_REFERENCE = t1.SECURITY_REFERENCE) AND
    (t0.PARTITION_KEY = t1.PARTITION_KEY)))

    Hello,
    It looks like you have configured your 1:M relationship to use batch reading. This causes the query to bring in the Security_Position table's objects to use the same selection criteria as was used on the initial query, with a join statement. This is more efficient in most cases as it ensures only the Security_positions needed for the Security objects to be fully built are read, in a single query.
    The selection criteria added is only used to filter out the Security objects. All referenced Security_Positions must be read in for the returned Security objects so that the data matches what is in the database. If you do not want the Security_Positions, you might try using indirection on the mapping which will delay the second query until you need the Security_Positions. Or, if you want only the Security_Positions with dealReference EQUAL “NA", you could do a query specifically to filter on them.
    Best Regards,
    Chris

  • No tree displayed with WHERE clause (data issue?)

    I tried this on the apex.oracle.com workspace after it didnt run in our setup, and I ran into the same issue.
    I cant get the tree to display when I add a WHERE clause to the query.
    I know this isnt a problem with the WHERE clause, and has something to do with the data.
    If I just delete the data I dont want from the table (data_type <> 'S'), it WORKS, even with the WHERE clause.
    I have checked running the SQL, and the root element is returned.
    When I look at the HTML source of the page, I can see the js object created, though it seems to be constructed incorrectly.
    select case when connect_by_isleaf = 1 then 0
    when level = 1 then 1
    else -1
    end as status,
    level,
    "DATA_TEXT" as title,
    null as icon,
    "ID" as value,
    null as tooltip,
    null as link
    from "#OWNER#"."T_ROOT_CAUSE_TEMPLATE"
    where (data_type='S' or id=346)
    start with id=346
    connect by prior "ID" = "PARENT"
    order siblings by "DATA_SEQUENCE"

    Just in case if you didn't know it, you can use WITH factoring clause when creating a tree. It makes it possible to create as many "tables" as you need, while the final hierarchical query (that is responsible for the way the tree looks like) is a simple one. This (+WITH+) approach is convenient as you can avoid repeating inline views and/or subqueries.
    For example, your query might have looked like this:
    with s_type as
      (select * from t_template
       where data_type = 'S'
          or id = 346
    select
      case when connect_by_isleaf = 1 then 0
           when level = 1 then 1
           else -1
      end as status,
      level,
      data_text as title,
      null as icon,
      id as value,
      null as tooltip,
      null as link
    from
      s_type
    start with id=346
    connect by prior id = parent
    order siblings by data_sequence

  • Function in where clause is executed and returns null instead a valid value

    Hi all
    i have a strange problem.
    There is a access-application where i have a pass-through-sql.
    This sql is fetching a foreign exchange rate from a history table which holds this rates for every day and i'm going to fetch the rate for the last day of the last month.
    Example of the fraction which does not work and which i executed directly on the DB, Oracle 11.2.0.3.0:
    select val
    ,last_day(add_months((trunc(sysdate)+3),-1)) tag
    from k.obj_ts_hist th
    where obj_id = 2660
    and eff_date = last_day(add_months((trunc(sysdate)+3),-1))
    --and      eff_date = '01-mar-2013'
    eff_date on table k.obj_ts_hist is defined as date.
    The function last_day in the where clause leads to null for both values in the select (val and tag).
    If i use eff_date = '01-mar-2013' it's all ok, i get the rigth values.
    I tested some combinations of the clause, e.g.
    eff_date = to_date(to_char(last_day(add_months((trunc(sysdate)+3),-1)),'YYYYMMDD'),'YYYYMMDD')
    or
    to_char(eff_date,'YYYYMMDD') = to_char(last_day(add_months((trunc(sysdate)+3),-1)),'YYYYMMDD') , etc., but all of them do not work.
    Also i tested the clause with select ... from dual, e.g.
    select eff_date from
    select last_day(add_months((trunc(sysdate)+3),-1)) eff_date from dual
    where eff_date = last_day(add_months((trunc(sysdate)+3),-1))
    This work's !
    A cross check on Oracle 9.2.0.8.0: it works as expected !
    Thanks in advance for your effort.
    Regards, Konrad

    a little simulation of your formula
    select the_date,last_day(add_months((trunc(the_date) + 3),-1)) eff_date
      from (select to_date('20130224','yyyymmdd') + level - 1 the_date
              from dual
            connect by level <= 7
           )reveals you might have been querrying future rates
    THE_DATE   EFF_DATE 
    24.02.2013 31.01.2013
    25.02.2013 31.01.2013
    26.02.2013 28.02.2013  /* future date */
    27.02.2013 28.02.2013  /* future date */
    28.02.2013 28.02.2013  /* current date */
    01.03.2013 28.02.2013
    02.03.2013 28.02.2013Regards
    Etbin

  • Issue in select query with where clause

    Hi guys,
    I'm facing an issue while using select query with the where clause. When I'm selecting all the data from the table it returns the correct result. But when I'm using the where clause to get the specific rows from the table it returns no rows. But the data I'm trying to fetch using the where condition exists in the table.
    Here is my query which causing the issue,
    select * from mytable where myfield = 'myvalue'
    But if I use the following query it returns the result correctly.
    select * from mytable
    Also the myfield value 'myvalue' exists in the table.
    I have tried by running this query in both SQL Developer and SQL Plus. I have tried this query in mssql as well. It works perfectly and returns correct result sets for both the queries I have mentioned above. I'm unable to predict the issue as I'm new to ORACLE. Please help.
    Thanks,
    Ram.

    Hi Ram,
    I experienced an issue similar to this with a varchar2 field. Some of our records had a hidden newline character at the end of them, which was making queries like the one below fail:
    select * from employees
    where email = '[email protected]'The best way I found to detect this was to use
    select 'XX'||email||'XX' from employeesTo make sure that there were no newlines. But that is just a guess. If you could provide some example table data and the outputs of your selects, it would be helpful.
    Jeff

  • Summary column with where clause

    Hi all,
    I'm using Oracle Report Builder 10GR2. I have the following issue: In one of the query i have the following result :
    Suppliers     0
    Suppliers     1408
    Total in  BGN     1408
    Customers      6024
    Customers      11779.32
    Customers      
    Total in  BGN     11779.32
    Taxes      0
    Taxes      0
    Total in  BGN     0
    Cash      1363.85
    Cash      691
    Cash      991.23
    Cash      688
    Total in  BGN     2355.08I want to make a sum for these columns where corresponds to description " Total in BGN" . Maybe it is a simple task... Do i have a chance to select from a query in a Report Builder?
    If yes, pls specify? Or maybe there is a chance to add a where clause for summary column. But keep in mind that this is one of the queries in the report builder and i have to add summary with this conditions. I cannot change the existing query but probably add a new one.
    Any ideas?
    DB Version: 11g
    Thanks in advance,
    Bahchevanov.
    Edited by: bahchevanov on Sep 29, 2012 2:21 AM

    Hello,
    You should use parameter file.Another question i can see you are using 11g.Why don't you use data pump?.
    Data Pump is faster and have more features and enhancement than regular imp and exp.
    You can do the following:
    sqlplus / as sysdba
    Create directory DPUMP_DIR3  for 'Type here your os path that you want to export to';then touch a file:
    touch par.txt
    In this file type the following the following :
    tables=schema.table_name
    dumpfile=yourdump.dmp
    DIRECTORY=DPUMP_DIR3
    logfile=Your_logfile.log
    QUERY =abs.texp:"where hiredate>'01-JAN-13' "then do the following
    expdp username/password parfile='par.txt'
    If you will import from Oracle 11g to version 10g then you have to addthe parameter "version=10" to the parameter file above
    BR
    Mohamed ELAzab
    http://mohamedelazab.blogspot.com/

Maybe you are looking for

  • New iPad won't save genius playlists to iCloud (iTunes Match)

    Hi, Just received the new iPad.  One feature I was excited for in iOS 5.1 was the ability make and save genius mixes to iTunes Match so that I would have the mixes across iTunes, my iPhone, and my iPad.  However, when I make a genius mix on the new i

  • CS Review in InDesign CS 5 causing Blue Screen

    Everytime I try to run the CS Review extension in InDesign CS 5, it causes my computer to blue screen. I'm on Windows 7 Professional, 64bit system. Intel Core 2 Duo CPU T8300 @ 2.40GHz. 8 GB of Ram. Is this happening to anyone else? I've made sure al

  • MacBook Pro is getting very slow after ~1h of using. It's not even getting hot!

    MacBook Pro 15' early 2011 OS X 10.9 (13A603) Maverics 2 GHz Intel Core i7 8 GB 1600 MHz DDR3 Intel HD Graphics 3000 512  MB +my battery is dead and Im using cable all the time When I turn ON my Macbook everything is OK, but after ~1h of doing whatev

  • Oracle 9 ,10 client errors.

    In toad there is such an error: Cannot load OCI DLL: C:\Users\Admin\Desktop\instantclient_10_2\oci.dll in client 10 there is such error: ORA-12154: TNS:could not resolve the connect identifier specified There is such an error I can't seem to get work

  • Runtime Error message prior to crash in Premiere Pro CS4

    I'm having issues with Adobe Premiere CS4 crashing regularly and the same error message always pops up. Runtime Error! R6025 -pure virtual function call What do I need to do to make this stop happening.  It doesn't seem to be a result of a particular