Subquery within MERGE?

Hello,
I'm having a bit of difficulty getting a MERGE command to work with a subquery as part of the imported data. Thoughts?
-- Clean up from prior run, if there was one
DROP TABLE PARENT CASCADE CONSTRAINTS;
DROP TABLE CHILD CASCADE CONSTRAINTS;
DROP TABLE INPUT CASCADE CONSTRAINTS;
DROP SEQUENCE ENTERPRISE_SEQ;
--create objects for test
CREATE TABLE PARENT(
PARENT_ENTERPRISE_ID NUMBER(4, 0) NOT NULL,
PARENT_SOURCE_NAME VARCHAR2(20) NOT NULL,
PARENT_SOURCE_ID VARCHAR2(20) NOT NULL,
PARENT_COMMENT VARCHAR2(25) NOT NULL,
CONSTRAINT PARENT_PK PRIMARY KEY (PARENT_ENTERPRISE_ID),
CONSTRAINT PARENT_AK UNIQUE (PARENT_SOURCE_NAME, PARENT_SOURCE_ID)
CREATE SEQUENCE ENTERPRISE_SEQ;
CREATE TABLE CHILD(
PARENT_ENTERPRISE_ID NUMBER(4, 0) NOT NULL,
CHILD_ENTERPRISE_ID NUMBER(4, 0) NOT NULL,
CHILD_SOURCE_NAME VARCHAR2(20) NOT NULL,
CHILD_SOURCE_ID VARCHAR2(20) NOT NULL,
CHILD_COMMENT VARCHAR2(25) NOT NULL,
CONSTRAINT CHILD_PK PRIMARY KEY (CHILD_ENTERPRISE_ID),
CONSTRAINT CHILD_AK UNIQUE (CHILD_SOURCE_NAME, CHILD_SOURCE_ID)
ALTER TABLE CHILD
ADD CONSTRAINT CHILD_FK_PARENT
FOREIGN KEY (PARENT_ENTERPRISE_ID)
REFERENCES PARENT(PARENT_ENTERPRISE_ID)
CREATE TABLE INPUT(
INPUT_SOURCE_NAME VARCHAR2(10) NOT NULL,
INPUT_SOURCE_ID VARCHAR2(20) NOT NULL,
INPUT_RECORD_LEVEL VARCHAR2(10) NOT NULL,
INPUT_COMMENT VARCHAR2(25) NOT NULL,
INPUT_PARENT_RECORD_ID VARCHAR2(20) NULL,
CONSTRAINT INPUT_PK PRIMARY KEY (INPUT_SOURCE_NAME, INPUT_SOURCE_ID)
-- insert records into the table simulating external input
-- note that the input table has two levels of records: Parent and Child
insert into INPUT values ('Source A', '123', 'Parent', 'Input rec 1', null);
insert into INPUT values ('Source A', '234', 'Parent', 'Input rec 2', null);
insert into INPUT values ('Source A', '345', 'Child', 'Input rec 3', '123');
insert into INPUT values ('Source A', '456', 'Child', 'Input rec 4', '123');
-- Merge into Parent table
-- This works just fine
merge into PARENT P
using (select INPUT_SOURCE_NAME,
INPUT_SOURCE_ID,
INPUT_COMMENT
from INPUT
where INPUT_RECORD_LEVEL = 'Parent'
) I
on (I.INPUT_SOURCE_NAME = PARENT_SOURCE_NAME and
I.INPUT_SOURCE_ID = PARENT_SOURCE_ID
when matched then
update set P.PARENT_COMMENT = I.INPUT_COMMENT
when not matched then
insert (P.PARENT_ENTERPRISE_ID,
P.PARENT_SOURCE_NAME,
P.PARENT_SOURCE_ID,
P.PARENT_COMMENT
values
(ENTERPRISE_SEQ.NEXTVAL,
I.INPUT_SOURCE_NAME,
I.INPUT_SOURCE_ID,
I.INPUT_COMMENT
-- Merge into Child table
-- This fails
merge into CHILD C
using (select INPUT_SOURCE_NAME,
INPUT_SOURCE_ID,
INPUT_COMMENT
from INPUT
where INPUT_RECORD_LEVEL = 'Child'
) I
on (I.INPUT_SOURCE_NAME = C.CHILD_SOURCE_NAME
and
I.INPUT_SOURCE_ID = C.CHILD_SOURCE_ID
when matched then
update set C.CHILD_COMMENT = I.INPUT_COMMENT
when not matched then
insert (C.PARENT_ENTERPRISE_ID,
C.CHILD_ENTERPRISE_ID,
C.CHILD_SOURCE_NAME,
C.CHILD_SOURCE_ID,
C.CHILD_COMMENT
values
((select PARENT_ENTERPRISE_ID
from PARENT
where PARENT_SOURCE_NAME = I.INPUT_SOURCE_NAME
and PARENT_SOURCE_ID = I.INPUT_SOURCE_ID
ENTERPRISE_SEQ.NEXTVAL,
I.INPUT_SOURCE_NAME,
I.INPUT_SOURCE_ID,
I.INPUT_COMMENT
select * from PARENT;
select * from CHILD;

ME_XE?merge into child c
  2  using
  3  (
  4     select
  5             i.input_source_name,
  6             i.input_source_id,
  7             i.input_comment,
  8             p.parent_enterprise_id
  9     from
10             input   i,
11             parent  p
12     where i.input_record_level              = 'Child'
13     and   i.input_source_name               = p.parent_source_name
14     and   i.input_parent_record_id          = p.parent_source_id
15  ) i
16  on
17  (
18             i.input_source_name = c.child_source_name
19     and     i.input_source_id   = c.child_source_id
20  )
21  when matched then
22     update set c.child_comment = i.input_comment
23  when not matched then
24  insert
25  (
26     c.parent_enterprise_id,
27     c.child_enterprise_id,
28     c.child_source_name,
29     c.child_source_id,
30     c.child_comment
31  )
32  values
33  (
34     i.parent_enterprise_id,
35     enterprise_seq.nextval,
36     i.input_source_name,
37     i.input_source_id,
38     i.input_comment
39  );
2 rows merged.
Elapsed: 00:00:00.01
ME_XE?
ME_XE?
ME_XE?select * from parent;
PARENT_ENTERPRISE_ID PARENT_SOURCE_NAME                                           PARENT_SOURCE_ID                                             PARENT_COMMENT
                   1 Source A                                                     123                                                          Input rec 1
                   2 Source A                                                     234                                                          Input rec 2
2 rows selected.
Elapsed: 00:00:00.00
ME_XE?select * from child;
PARENT_ENTERPRISE_ID CHILD_ENTERPRISE_ID CHILD_SOURCE_NAME                                            CHILD_SOURCE_ID                                              CHILD_COMMENT
                   1                   3 Source A                                                     345                                                          Input rec 3
                   1                   4 Source A                                                     456                                                          Input rec 4
2 rows selected.
Elapsed: 00:00:00.01
ME_XE?

Similar Messages

  • Subquery inside Merge Into under 11g

    create or replace
    PROCEDURE SP_IN_CURRENCY
    IS
    CURSOR csr IS SELECT currency_code FROM in_currency ORDER BY currency_code;
    v_hkd_rate NUMBER(15,9);
    BEGIN
    SELECT spot_rate INTO v_hkd_rate FROM in_currency WHERE in_currency.currency_code = 'HKD';
    MERGE INTO currency USING
    (SELECT currency_code, spot_rate FROM in_currency WHERE in_currency.currency_code = 'HKD') rec_in_currency
    ON (currency.currency_code = rec_in_currency.currency_code)
    WHEN MATCHED THEN
    UPDATE
    SET currency.CURRENCY_NAME = NVL(
    (SELECT value
    FROM tb_resources
    WHERE PACKAGE = 'currency'
    AND locale = 'en_US'
    AND KEY = rec_in_currency.currency_code
    ), currency.CURRENCY_NAME),
    currency.spot_rate = (v_hkd_rate/rec_in_currency.spot_rate),
    currency.SPOT_RATE_IN_USD = rec_in_currency.spot_rate
    WHEN NOT MATCHED THEN
    INSERT
    currency_code,
    CURRENCY_NAME,
    spot_rate,
    SPOT_RATE_IN_USD
    VALUES
    rec_in_currency.currency_code,
    (SELECT value FROM tb_resources WHERE PACKAGE = 'currency' AND locale = 'en_US' AND KEY = rec_in_currency.currency_code),
    (v_hkd_rate/rec_in_currency.spot_rate),
    rec_in_currency.spot_rate
    COMMIT;
    END SP_IN_CURRENCY;
    The above stored procedure created successfully in 9i but retrun the following error when create on 11g. Anyone has idea? is it the limitation of 11g? The problem was caused by this subquery:
    (SELECT value FROM tb_resources WHERE PACKAGE = 'currency' AND locale = 'en_US' AND KEY = rec_in_currency.currency_code),
    Error(38,99): PL/SQL: ORA-00904: "REC_IN_CURRENCY"."CURRENCY_CODE": invalid identifier

        value assign in variable equals value return by subquery in USING clause
        so   (V_HKD_RATE / REC_IN_CURRENCY.SPOT_RATE) = 1
        and  CURRENCY_CODE = 'HKD'
        key = rec_in_currency.currency_code is always 'HKD'
        let's say
        SPOT_RATE  = 999
        v_hkd_rate = 999
    -- BEFORE:
    select  spot_rate
    into    v_hkd_rate
    from    in_currency
    where   in_currency.currency_code = 'HKD';
    merge into currency using
        select  currency_code, spot_rate
        from    in_currency
        where   in_currency.currency_code = 'HKD'
    ) rec_in_currency
    on
        currency.currency_code = rec_in_currency.currency_code
    when matched then update set
        currency.currency_name = nvl
                                        select  value
                                        from    tb_resources
                                        where   package = 'currency'
                                        and     locale = 'en_US'
                                        and     key = rec_in_currency.currency_code
                                ,   currency.currency_name
    ,currency.spot_rate           = (v_hkd_rate / rec_in_currency.spot_rate)
    ,currency.spot_rate_in_usd    = rec_in_currency.spot_rate
    when not matched then insert
        currency_code
    ,   currency_name
    ,   spot_rate
    ,   spot_rate_in_usd
    values
        rec_in_currency.currency_code
            select  value
            from    tb_resources
            where   package = 'currency'
            and     locale  = 'en_US'
            and     key     = rec_in_currency.currency_code
    ,    (v_hkd_rate/rec_in_currency.spot_rate)
    ,    rec_in_currency.spot_rate
    -- AFTER:
    merge into currency using
        select  currency_code, spot_rate
         -- 'HKD', 999
        from    in_currency
        where   in_currency.currency_code = 'HKD'
    ) rec_in_currency
    on
        currency.currency_code = 'HKD'
    when matched then update set
        /* If value IS NULL update with current value? I think you should change it... */
        currency.currency_name = nvl
                                        select  value
                                        from    tb_resources
                                        where   package = 'currency'
                                        and     locale  = 'en_US'
                                        and     key     ='HKD'
                                ,   currency.currency_name
    ,    currency.spot_rate        = 999/999
    ,    currency.spot_rate_in_usd = 999
    when not matched then insert
        currency_code
    ,   currency_name
    ,   spot_rate
    ,   spot_rate_in_usd
    values
        'HKD'
            select  value
            from    tb_resources
            where   package = 'currency'
            and     locale  = 'en_US'
            and     key     = 'HKD'
    ,   999/999
    ,   999
    Can anybody check it?
    */

  • Rename audio clips within merged clips

    Hi there,
    In premiere CS5.5, is it possible to rename the audio clips that are within a merged clips ?
    I mean, with each video, I have several audio tracks from ambient and 2 booms.
    In order not to mess up with those when editing sound in ProTools later, I need to know which one is which.
    Thanks.

    If you only want the sound clip for a set period of time, drag it on top of one of the video clips near the beginning that will prevent the audio from becoming a 'background music clip'. Grab the title bar of that clip in the Project window and drag it until the whole background area changes from purple/green to the normal dark grey color of the Project window. Same would apply to your voice clips as well, just drag those sound clips right on the very middle of the thumbnail image of the video clip, and then slide it around to where it needs to be by dragging it to the left or right.

  • Conditional Insert within Merge???

    can we use conditional insert within the merge statement????
    thanks a lot..
    nantha

    NanthaKumarAR wrote:
    is there is any possible way to do so????
    thanks a alot ....
    nanthaHmmm let's look at the conversation so far...
    You: "is this possible?????"
    Me: "No."
    You: "is there is any possible way to do so????"
    I'm now wondering which part of "No" you failed to understand.
    You cannot perform multiple/conditional inserts within a MERGE statement. The purpose of a MERGE statement is to take data and MERGE it into a single table.
    The only messy way I can think of would be to merge into an intermediate table with triggers on it, that takes the merged data and splits it out into the seperate tables. Messy and not likely the best solution to the initial problem, which would probably be better solved by avoiding the use of MERGE in the first place (though we don't know what problem you are actually trying to solve).

  • Merged WebHelp within Merged WebHelp

    RH9 | WebHelp
    Has anyone encountered problems with more than one level of merged WebHelp? It seems to work okay, other than including an extra Home link in the breadcrumbs, but I just wondered if this was not recommended.
    Generated folder
    mergedProjects
    Project1
    Project2
    mergedProjects
    Project3
    Project4
    Project5
    Project6
    Thanks
    Jonathan

    How to do it with a redirect is covered at http://www.grainge.org/pages/authoring/merging_webhelp/merging_toclinks.htm but I am not sure that will still work because of browser changes.
    If it does not, see Step 5 at http://www.grainge.org/pages/authoring/merging_webhelp/merging_method_rh9.htm
    that sets out a different type of redirect. Maybe you can cobble something out of that. I am not able to check right now.
    See www.grainge.org for RoboHelp and Authoring tips
    @petergrainge

  • Subquery inside CASE statement

    I am trying to use a subquery within a Case statement with a 'where' condition that binds to the parent query. Like this:
    Select T.idperson , CASE WHEN  T.type = 'C' THEN (SELECT name from Customers where C.idcustomer = T.idperson)
    ELSE
    (SELECT name from Providers where idprovider = T.idperson)
    END Name
    from myTable T This works for me in SQL Server but in ORACLE the subquery does not return any rows, i guess its the binding to parent query part. Any thoughts of another way I could get the result I want?
    Thanks,
    JuanDiego

    Hi, Juandiego,
    If it's not returning any rows, then you must not have any rows in the table.
    If you have any rows in the table, you will either get
    (a) an error, or
    (b) some rows (even if the columns are NULL).
    There is another way to get the results you want.
    I probably wouldn't use scalar sub-queries. I would outer-join all the tables, like this:
    Select  T.idperson
    ,       CASE
                WHEN  T.type = 'C'
                THEN  c.name
                ELSE  p.name
            END  AS Name
    from             myTable   t
    LEFT OUTER JOIN  Customers c  ON c.idcustomer = T.idperson
    LEFT OUTER JOIN  Providers p  ON p.idprovider = T.idperson
    ;

  • Finder and Windows Explorer Functionality to be 'Merged'

    Right, before I start what I expect will be an epic battle, this is not what I intend this thread to entail...
    I have recently moved from being a purely windows user (Software Developer), to using OS X as well. My girlfriends study dictated that I recommended her buying a Mac. Consequently, her inexperience dictated that I should learn OS X in order to be her technical support. Everything until earlier this week was great, but I'm still a lover of the OS.
    The aforementioned 'until earlier this week' has caused one major usability gripe with which I have now read up on exstensively; the way that finder handles copying folders.
    Now to a certain extent I see why it was slightly naieve of me to think that copying a folder should ONLY replace the files within and not the whole folder, but thats because I have grown up basically Windows only.
    So I copied the folder structure (containing organised subfolders) of ALL of my girlfriends university work to date across to the Mac and misinterpreted what the copy would do, it turns out that this replaces the whole folder, and does not move the original folder to trash.
    AND NOW TO THE POINT OF THIS THREAD...
    As I began, I do not intend this thread to be a Windows vs Mac rantfest. I would merely like to rally up who can see the benefits of merging the way that OS X replaces the whole folder with the Windows options to only replace files within (merge).
    This would then allow the possibility of easily copying folders with nested sub-folders (a la windows), but also allow the original method of replacing the destined folder (keeping with the mac tradition).
    I don't want to go down the route of 'but every other OS merges folders' because this isn't every other OS, its OS X, and it seems that everything else that they have done, they've done well!
    If the proposed could be implemented, not only would it allow more options for existing Mac users, but also allow a smoother crossover for users from other OS's
    Perhaps something like below could work.
    'The folder <folder name> already exists, do you wish to replace this folder, or merge its contents with the current folder?'
    || Replace || || Merge || || Cancel ||
    As I am no expert of usability, the wording above should probably be changed.
    Given enough interest (and perhaps a little understanding from long term mac users ;o) ) I wish to inform Apple of this thread so we will all get the best of both worlds (and I won't have a nagging girlfriend with much lost work).
    I look forward to your interest/comments (but please keep it nice).
    Robsta
    Message was edited by: Robsta83

    A slightly different angle of approach here can be viewed by how I think Superduper operates. Superduper has a really smart update function in its cloning. It will when updating the clone look for files on a bit by bit basis and see if there are changes to any specific file. If it sees changes, it will ensure that the files that are changed on the original get updated on the clone. It will ensure the files that are deleted on the original get deleted on the clone, and it will ensure that the files that are added on the original get added to the clone when the update is performed.
    Now here in is the problem. Some users actually want OLDER versions to be preserved on their backup but not the original when they copy to the archived backup. We've seen here people are complaining that their archived backup is not preserved by Time Machine:
    http://discussions.apple.com/thread.jspa?messageID=6107525#6107525
    So the problem we are faced with here, is there are different needs for different people when copying files. While some are happy just to maintain a current copy of their files, others wish to manage archives when copying files. So a merge function would have to include the caveat of what does not get preserved when the merge happens. In the face of trying to be simple, you can't be all things for all people. As a freelance technician not working for Apple, I can just say, it probably is best for the user to see how an effort has been made to simplify the process, and work around it if necessary to achieve your needs.
    I've used Windows 2000 and XP Pro and know it asks me whether or not to replace each file that is identical each time I copy from one folder to another when the names are the same. This is a laborious process, saying OK, cancel, ok, cancel if it is done indefinitely. I can see the dialog box asking:
    "Do you want to replace all older files, some older files, with newer files of the same name, or do you want to replace newer files with some older files of the same name?"
    A new computer user would go "Huh???"
    Merge is nice for those of us who can keep track of it in real life.
    For the rest of us who are organizationally challenged, or time challenged, we just want it done right the first time. Unfortunately neither Apple, nor the computer can read everyone's mind.
    I agree a merge function would be nice, but I think it would overly complicate matters.

  • Oracle error from to_date in WHERE clause but not in SELECT clause

    If I issue a query like:
    select * from view_1
    where to_date(col1, 'mm/dd/yyyy') > sysdate
    I get an ora-01858 error.
    If I issue a query like
    select to_date(col1, 'mm/dd/yyyy') from view_1
    I don't get any error.
    I've verified the data both visually and using several recommended methods( checking with translate or regular expression), but I can't seem to find any problems with the data.
    Any suggestions for what I should try next?
    cheers,
    dz

    Hi user552575,
    Very strangeNothing mystical, especially if you say that VStudyPatientData is some view. You didn't post its underlying query so one can only guess about what is going on with your queries.
    This is my hypothetical scenario and my guess of what might happen. Consider:
    SQL> create table TStudyPatientData
      2    (SomeKey,
      3     StudyDatasetItemId,
      4     StudyPatientDataValue) as
      5   select rownum,
      6          4232,
      7          '01/12/2008'
      8     from dual
      9  connect by level <= 3;
    Table created.
    SQL> -- Now, let's insert row with incorrect date
    SQL> insert into TStudyPatientData values (4, 4232, 'AA/12/2008');
    1 row created.Here is what we have in TStudyPatientData:
    SQL> select * from TStudyPatientData;
       SOMEKEY STUDYDATASETITEMID STUDYPATIE
             1               4232 01/12/2008
             2               4232 01/12/2008
             3               4232 01/12/2008
             4               4232 AA/12/2008Now, let's create one extra "lookup" table and our hypothetical view:
    SQL> create table SomeTable (x, y) as
      2  select 4232, 4 from dual;
    Table created.
    SQL> create or replace view VStudyPatientData as
      2  select a.*
      3    from TStudyPatientData a
      4   where a.SomeKey <
      5         (select b.y
      6            from SomeTable b
      7           where b.x = a.StudyDatasetItemId);
    View created.It's clear that our simple view will return three rows (row with SomeKey = 4 won't be returned):
    SQL> select * from VStudyPatientData;
       SOMEKEY STUDYDATASETITEMID STUDYPATIE
             1               4232 01/12/2008
             2               4232 01/12/2008
             3               4232 01/12/2008Now, let's see what happens about your queries. This one will succeed:
    SQL> select to_date(StudyPatientDataValue, 'MM/DD/YYYY')
      2    from VStudyPatientData
      3   where StudyDatasetItemId = 4232
      4     and StudyPatientDataValue is not null;
    TO_DATE(S
    12-JAN-08
    12-JAN-08
    12-JAN-08But this one fails, just as in your case:
    SQL> select *
      2    from VStudyPatientData
      3   where StudyDatasetItemId = 4232
      4     and StudyPatientDataValue is not null
      5     and to_date(StudyPatientDatavalue, 'MM/DD/YYYY') > sysdate;
    ERROR:
    ORA-01858: a non-numeric character was found where a numeric was expected
    no rows selectedSo how did this happen? Once we have query execution plans, the answer is obvious. Let's start with "good" query:
    SQL> explain plan for
      2  select to_date(StudyPatientDataValue, 'MM/DD/YYYY')
      3    from VStudyPatientData
      4   where StudyDatasetItemId = 4232
      5     and StudyPatientDataValue is not null;
    Explained.
    SQL> @utlxpls
    PLAN_TABLE_OUTPUT
    | Id  | Operation            |  Name              | Rows  | Bytes | Cost  |
    |   0 | SELECT STATEMENT     |                    |       |       |       |
    |*  1 |  FILTER              |                    |       |       |       |
    |*  2 |   TABLE ACCESS FULL  | TSTUDYPATIENTDATA  |       |       |       |
    |*  3 |   TABLE ACCESS FULL  | SOMETABLE          |       |       |       |
    Predicate Information (identified by operation id):
       1 - filter("SYS_ALIAS_1"."SOMEKEY"< (SELECT "B"."Y" FROM "SOMETABLE"
                  "B" WHERE "B"."X"=:B1))
       2 - filter("SYS_ALIAS_1"."STUDYPATIENTDATAVALUE" IS NOT NULL AND
                  "SYS_ALIAS_1"."STUDYDATASETITEMID"=4232)
       3 - filter("B"."X"=:B1)
    Note: rule based optimization
    20 rows selected.Take a close look at FILTER operation (with Id = 1). It filters out rows which do not satisfy subquery within a view (where a.SomeKey < (select ... )). Thus, row with incorrect date (AA/12/2008) is simply filtered out.
    But what happens with "bad" query? Let's see:
    SQL> explain plan for
      2  select *
      3    from VStudyPatientData
      4   where StudyDatasetItemId = 4232
      5     and StudyPatientDataValue is not null
      6     and to_date(StudyPatientDatavalue, 'MM/DD/YYYY') > sysdate;
    Explained.
    SQL> @utlxpls
    PLAN_TABLE_OUTPUT
    | Id  | Operation            |  Name              | Rows  | Bytes | Cost  |
    |   0 | SELECT STATEMENT     |                    |       |       |       |
    |*  1 |  FILTER              |                    |       |       |       |
    |*  2 |   TABLE ACCESS FULL  | TSTUDYPATIENTDATA  |       |       |       |
    |*  3 |   TABLE ACCESS FULL  | SOMETABLE          |       |       |       |
    Predicate Information (identified by operation id):
       1 - filter("SYS_ALIAS_1"."SOMEKEY"< (SELECT "B"."Y" FROM "SOMETABLE"
                  "B" WHERE "B"."X"=:B1))
       2 - filter(TO_DATE("SYS_ALIAS_1"."STUDYPATIENTDATAVALUE",'MM/DD/YYYY')>S
    YSDATE@! AND "SYS_ALIAS_1"."STUDYPATIENTDATAVALUE" IS NOT NULL AND
                  "SYS_ALIAS_1"."STUDYDATASETITEMID"=4232)
       3 - filter("B"."X"=:B1)
    Note: rule based optimization
    21 rows selected.Please notice the second step of the plan (with Id = 2) and the corresponding filtering predicates (especially the one I've marked bold). As we can see, TO_DATE(...) > SYSDATE predicate is evaluated at very first stage, before subquery filtering is done.
    In general, Oracle tries to evaluate single-table predicates first, before evaluating joins and subqueries. In our case, this means that Oracle tries to apply TO_DATE(...) to every row in TStudyPatientData, and it throws exception as soon as it reaches 'AA/12/2008' value.
    Of course, this is hypothetical scenario - I haven't seen your view text so the best I can do is guess.
    However, as you can see, everything is possible with views and, without seeing query plans, it can be hard to understand what is going on.
    Regards.

  • Why do I get the symbol data link in the query_name of the data model

    If I use an inline subquery within the SELECT of a data model query, the symbol data link appears in the query_name of the data model.
    This causes the data link between two queries not to be used even if there is an existing link between the two. The trace file doesn't
    have that join condition and so the child query in which the inline subquery was added fetches many redundant data.
    Any idea what that symbol represents and how to get rid of it. It also appears during other times, not only when we use inline subquery
    within a SELECT. Not sure if it can cause any harm to the report.
    The problem is seen in Report Builder 6.0.8.19.0. Not sure if the problem is with other releases also.
    Any suggestions are welcome.

    I am living with the symbol in the query box as well, because my report only has a single query. My query also has several inline subqueries. I had never seen this before last week, spent a day re-reading the manuals and couldn't figure it out.
    My post is not a solution, but a "me too" echo that could use an answer.
    Troy Tremble
    If I use an inline subquery within the SELECT of a data model query, the symbol data link appears in the query_name of the data model.
    This causes the data link between two queries not to be used even if there is an existing link between the two. The trace file doesn't
    have that join condition and so the child query in which the inline subquery was added fetches many redundant data.
    Any idea what that symbol represents and how to get rid of it. It also appears during other times, not only when we use inline subquery
    within a SELECT. Not sure if it can cause any harm to the report.
    The problem is seen in Report Builder 6.0.8.19.0. Not sure if the problem is with other releases also.
    Any suggestions are welcome.

  • Need information about Garnishments  and  USA Tax     (Very Urgent)

    Hi SAP Experts,
    Please send me some configuration flow (one by one steps) about Garnishments and USA Tax . Please let me know where exacttly i need to configure. Please send me one by one steps.
    Thanks & Regards,
    GKReddy.K

    You might look towards forming a query that accurately restricts the identifying information
    for rows you want to display in your view, and using that as a subquery within the view definition.
    This can be described generally as:
    CREATE OR REPLACE VIEW yourViewHere AS
    SELECT
    usefulData
    FROM
    listOfTables
    WHERE
    properlyJoined
    AND someKeyColumn(s) IN (
    SELECT someKeyColumn(s)
    FROM listOfTables
    WHERE properlyJoined
    AND yourSpecialBusinessCondition(s)
    Note that SELECT UNIQUE/DISTINCT is not needed for
    the SELECT in the subquery ... the IN operator will
    do well enough without the extra work performed by UNIQUE.
    Usually good to look at the query plan used for each part of the query.
    HTH
    Bob Grove

  • Urgent pls...sql query

    Hi
    I have a sample table of empno,sal and hiredate. I have 2 duplicate rows for example
    empno sal Hiredate
    7900 1000 1-mar-03
    7900 2000 2-mar-03
    I want to eliminate the duplicate row. My query should be like this ...
    Select empno,sal,min(hiredate) .... and not any other type. Also I should not use subquery or correlated subquery within this query. It should be a single query only. In real I am using many tables. I found the duplicate rows in one table as I mentioned above for example. Thats why my query should start with those columns and it must be a single query. Can any one help me out to solve this. Please reply as early as possible. I am in most urgent.
    thanks in advance.

    Hi Andrew!
    Thanks for ur response. Eliminate in the sense, just to omit the uplicate rows while displaying and not to delete. I didnt mean to delete, I meant for display. Just to query omiting the duplicate rows. If I use sub query its getting hanged as there r 5 tables and each got more than 50,000 records in live. So I want it to be in a single query using group functions and joins and not sub query or multiple query or correlated sub query.
    The problem is if we didn't select sal column then this will work ...
    select empno,min(hiredate) from emp group by empno.
    But I must use sal column also to display, thats the problem!

  • Converting SQL to PS Query

    I have this piece of code in an Oracle SQL and I want to convert to PS Query.  Not sure how to do this.  Any help would be greatly appreciated.
    from ps_audit_ax_names a
    left join
        (select b.emplid, b.effdt, b.name from ps_names b
            where b.effdt = (select max(aa1.effdt)
                from ps_names aa1
                where aa1.emplid = b.emplid
            and name_type = 'PRI' 
            and aa1.effdt < (select max(aa2.effdt)
                from ps_names aa2
                where aa2.emplid = b.emplid
            and name_type = 'PRI'  ))
            and b.name_type = 'PRI')  BB
          on bb.emplid = a.emplid,

    As far as I know, there's no way to left join to a subquery within PS/Query.
    There are a couple of approaches that I would try:
    1) you could create a view that contains the sql for your subquery.  After adding the view to the appropriate Query Tree(s), you could left outer join it in PS/Query.
    2) You could do this as a union; one part of the union would have "exists" criteria (or just do a straight join) for the PS_Names subquery; the second part of the union would have a "not exists" criteria for the Names subquery.  That would be a bit trickier but could approximate what you're trying to achieve.

  • Oracle Lite, optimizer?

    Hi all!
    I'm in Oracle lite 10.3...what type of optimizer use Olite?
    I've some mysterious results in a select, only i change the order in the where conditions and the results are distincts...

    Hey Anastasia,
    Do you mean for the client or for MGP? I am assuming you want to unnest the subquery within the COMPOSE phase. Correct?
    Here is the only reference to unnesting on the client in the documentation:
    Example 5
    In this example, the "ordered" hint selects the EMP table as the outermost table in the join ordering. The optimizer still attempts to pick the best possible indexes to use for execution. All other optimizations, such as view replacement and subquery unnesting are still attempted.
    Select //ordered// Eno, Ename, Loc from Emp, Dept
    where Dept.DeptNo = Emp.DeptNo and Emp.Sal > 50000;
    But if this is your MGP that you are inquiring about, just alter the publication select statement with:
    SELECT /*+ UNNEST */ * FROM SOMESCHEMA.SOMETABLE WHERE BLAH, BLAH, BLAH

  • Why update with subqueries does not have cost and cardinality?

    There is update.
    update test t1 set dummy = (select dummy from test2 t2 where t1.id = t2.id);Both tables which have actual statistics. Each has 1000 rows. And column ID have values from 1 to 1000 in each table.
    This is explain plan
    | Id  | Operation          | Name  | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | UPDATE STATEMENT   |       |  1000 | 13000 |   426   (9)| 00:00:01 |
    |   1 |  UPDATE            | TEST  |       |       |            |          |
    |   2 |   TABLE ACCESS FULL| TEST  |  1000 | 13000 |   426   (9)| 00:00:01 |
    |*  3 |   TABLE ACCESS FULL| TEST2 |     1 |    13 |   426   (9)| 00:00:01 |
    Predicate Information (identified by operation id):
       3 - filter("T2"."ID"=:B1)We can see here, that Oracle consider subquery within update as once-executed subquery.
    This is runtime plan
    | Id  | Operation          | Name  | Starts | E-Rows | A-Rows |
    |   1 |  UPDATE            | TEST  |      1 |        |      0 |
    |   2 |   TABLE ACCESS FULL| TEST  |      1 |   1000 |   1000 |
    |*  3 |   TABLE ACCESS FULL| TEST2 |   1000 |      1 |   1000 |
    Predicate Information (identified by operation id):
       3 - filter("T2"."ID"=:B1)Why first plan does not have cost in step 1?
    Does Oracle always not understand that update with subqueries will performed as NL or filter? In other words that step 3 will executed many times.
    Or it is my bug (or what?)?

    793769 wrote:
    Does Oracle always not understand that update with subqueries will performed as NL or filter? In other words that step 3 will executed many times.
    Or it is my bug (or what?)?It's not possible to say whether this is a bug or a deliberate choice.
    Because of "subquery caching" (see http://jonathanlewis.wordpress.com/2006/11/06/filter-subqueries/ ) the optimizer cannot predict how often the subquery will have to run. So possibly it shows nothing rather than showing the best or worst cases or a pure guess.
    Regards
    Jonathan Lewis

  • Problem with selecting remote tables.

    Hi, im having problems with one select...
    Running select, in which i select tables from remote DB, takes not more then 2 seconds, retrieving few rows.
    1) When i try to "create table as" using that select it takes about 1 minute to run.
    2) Trying "merge into" my table using that select takes more that 5 minutes, ... replacing the select within merge by newly created temporary table (point 1) works fine - takes few seconds to run.
    So why simple select takes few seconds, creation of table using that select takes one minute and merge using that select takes 5minutes to run ?
    Thanks for any ideas
    Plan hash value: 1936184599
    | Id  | Operation                             | Name                        | Rows  | Bytes | Cost (%CPU)| Time     | Pstart| Pstop | Inst   |IN-OUT|
    |   0 | MERGE STATEMENT                       |                             |     1 |   642 |    84  (12)| 00:00:02 |       |       |        |      |
    |   1 |  MERGE                                | NP_HT_REC        |       |       |            |          |       |       |        |      |
    |   2 |   VIEW                                |                             |       |       |            |          |       |       |        |      |
    |   3 |    NESTED LOOPS OUTER                 |                             |     1 |  8637 |    84  (12)| 00:00:02 |       |       |        |      |
    |*  4 |     HASH JOIN                         |                             |     1 |  8244 |    81  (13)| 00:00:01 |       |       |        |      |
    |*  5 |      HASH JOIN                        |                             |     1 |  4220 |    60  (10)| 00:00:01 |       |       |        |      |
    |*  6 |       HASH JOIN                       |                             |     1 |  4182 |    56   (9)| 00:00:01 |       |       |        |      |
    |   7 |        NESTED LOOPS                   |                             |     1 |  4134 |    41  (10)| 00:00:01 |       |       |        |      |
    |*  8 |         HASH JOIN                     |                             |     1 |  4109 |    40  (10)| 00:00:01 |       |       |        |      |
    |   9 |          REMOTE                       | HT_REC              |     2 |   170 |    11   (0)| 00:00:01 |       |       |   NP | R->S |
    |  10 |          VIEW                         | VW_SQ_3                     |   806 |  3167K|    29  (14)| 00:00:01 |       |       |        |      |
    |  11 |           SORT GROUP BY               |                             |   806 | 96720 |    29  (14)| 00:00:01 |       |       |        |      |
    |  12 |            MERGE JOIN                 |                             |   806 | 96720 |    28  (11)| 00:00:01 |       |       |        |      |
    |  13 |             SORT JOIN                 |                             |     2 |   170 |    12   (9)| 00:00:01 |       |       |        |      |
    |  14 |              REMOTE                   | HT_REC              |     2 |   170 |    11   (0)| 00:00:01 |       |       |   NP | R->S |
    |* 15 |             SORT JOIN                 |                             |  7100 |   242K|    16  (13)| 00:00:01 |       |       |        |      |
    |  16 |              REMOTE                   | T_UR_BUS               |  7100 |   242K|    14   (0)| 00:00:01 |       |       |   NP | R->S |
    |  17 |         REMOTE                        | T_UR                      |     1 |    25 |     1   (0)| 00:00:01 |       |       |   NP | R->S |
    |  18 |        REMOTE                         | T_UR_BUS               |  7100 |   332K|    14   (0)| 00:00:01 |       |       |   NP | R->S |
    |  19 |       REMOTE                          | HT_BUS                 |     3 |   114 |     3   (0)| 00:00:01 |       |       |   NP | R->S |
    |  20 |      VIEW                             | VW_SQ_4                     |     2 |  8048 |    21  (20)| 00:00:01 |       |       |        |      |
    |  21 |       REMOTE                          |                             |       |       |            |          |       |       |   NP | R->S |
    |  22 |     PARTITION RANGE ITERATOR          |                             |     2 |   786 |     3   (0)| 00:00:01 |   KEY |   KEY |        |      |
    |  23 |      TABLE ACCESS BY LOCAL INDEX ROWID| NP_HT_REC        |     2 |   786 |     3   (0)| 00:00:01 |   KEY |   KEY |        |      |
    |* 24 |       INDEX RANGE SCAN                | NP_HT_REC_IDX_UK |     2 |       |     1   (0)| 00:00:01 |   KEY |   KEY |        |      |
    Predicate Information (identified by operation id):
       4 - access("HB"."CHANGE_DATE"="VW_COL_1" AND "TUB"."BUNDLE_ID"="BUNDLE_ID")
           filter("ROWID"=ROWID)
       5 - access("TUB"."BUNDLE_ID"="HB"."BUNDLE_ID")
           filter("TUB"."DATE_CHANGE">="HB"."CHANGE_DATE")
       6 - access("HR"."USER_ID"="TUB"."USER_ID" AND "TUB"."DATE_CHANGE"="VW_COL_1")
           filter("HR"."CHANGE_DATE">="TUB"."DATE_CHANGE")
       8 - access("HR"."USER_ID"="USER_ID")
           filter("ROWID"=ROWID)
      15 - access(INTERNAL_FUNCTION("HR"."CHANGE_DATE")>=INTERNAL_FUNCTION("TUB"."DATE_CHANGE"))
           filter(INTERNAL_FUNCTION("HR"."CHANGE_DATE")>=INTERNAL_FUNCTION("TUB"."DATE_CHANGE"))
      24 - access("RES"."CHANGE_ID"(+)=TO_NUMBER(TO_CHAR("HR"."CHANGE_ID")) AND "RES"."REC_ID"(+)=TO_NUMBER(TO_CHAR("HR"."REC_ID")) AND
                  "RES"."SCHEDULE_ID"(+)=TO_NUMBER(TO_CHAR("HR"."SCHEDULE_ID")) AND "RES"."USER_ID"(+)=TO_NUMBER(TO_CHAR("HR"."USER_ID")) AND
                  "RES"."CHANGE_DATE"(+)=TO_DATE(INTERNAL_FUNCTION("HR"."CHANGE_DATE"),'dd.mm.yyyy hh24:mi:ss'))

    Have tried hint /*+NO_QUERY_TRANSFORMATION*/ and it is working fine now = 2seconds for merge :) Have no idea why is that, but it works
    thanks
    d.

Maybe you are looking for

  • Nokia Lumia 920 email : how to do search on all em...

    Hello all,  This is  a feature i miss from my previous iphone 4.  I have multiple email accounts linked together (hotmail, 2 google accounts) on my lumia 920 email client app. I have set all email accounts to sync emails from past one month. However

  • Auto clearing of bank clearin account during FEBA

    Hi, I am having a problem on how i can automate in the config the bank clearing GL account when the debit and credit is match by amount.. Anybody know the answer.. please help.. Thanks Coco

  • Office Mac 2011 - Tasks / Flagged messages Errors

    Using the latest version of Outlook 2011 on OSX Mavericks 10.9.2 linked to a Exchange Server. On my iPad and iPhone using the TaskTask App all my Tasks and Flagged items display correctly as they are using OWA. In Outlook 2011 there are flagged messa

  • Lenovo g550 bios enable hardware virtualization

    I have Lenovo g550 machine with following configurations. CPU - T6500 Intel Core 2 Duo Please let me know this machine does support for the hardware virtualizion, since i couldnt find it in BIOS. Regards, Nandika

  • Finder window is not proportioned correctly

    We just updated to Adobe Acrobat DC and it looks like the Finder window is not proportioned correctly.   There is the large grey space that cannot be reduced. If the window is scaled down then you lose the files on the top while the gray space remain