[SQL] Where the problem of the clause with subqueries

Hello

I am writing a query for an apex application where I have a field (P47_UNNR) for filtering. In my where clause I try to do this:

... AND IN qo.pk_id
CASE
WHEN: P47_UNNR IS NULL
THEN
(SELECT pk_id FROM quote_orders)
ON THE OTHER
(SELECT QOR. FK_QUOTE_ORDER_ID
OF QUOTE_ORDER_RIDS QOR
JOIN THE
RID RID
WE RID. PK_ID = QOR. FK_RID_ID
WHERE RID.NAME LIKE: P47_UNNR)
END
...


But it gives an error "ORA-01427: einreihig subquery returns more than one line.

I tried several ways to work around this problem, but don't seem to be able to do. Does anyone have a suggestion on how to fix this?

Try something like...

AND qo.pk_id IN
(SELECT pk_id FROM quote_orders WHERE :47_UNNR IS NULL
 UNION ALL
 SELECT QOR.FK_QUOTE_ORDER_ID
 FROM   QUOTE_ORDER_RIDS QOR
        JOIN RIDS RID ON RID.PK_ID = QOR.FK_RID_ID
 WHERE RID.NAME LIKE :P47_UNNR
)

Tags: Database

Similar Questions

  • How to create the file on a location where the user with rights?

    Hello
    I have a requirement in my application a lot of program thatcreating a report to a file and it is written in a user's location. Now he specified directly as (c:\ or d:\...).

    The problem is that the user does not have right to access that directory. What I suggest, or I want to create is special reports on a location where the user with rights.

    Essentially in Windows system % UserProfile % having right to do anyting. Assume that the operating system that is installed in C: the % UserProfile % c:\documents and Settings\nom_utilisateur or D: then D:\Document and user Settings\nom.

    How do I get this help please me.

    Good help will be appreciated.

    Iqbal

    Hello
    The best practice would be to create the file in My Documents for the user currently logged in windows.

    Unfortunately, you did not mention your version of forms. In an older version like 6.x it is function in the library of d2kwutil called Read_Registry in the win_api_environment section, and in the more recent versions the same availble function in the library webutil to client_ name.

    So, you can read the registry database for the current logged in user using the function mentioned above of the location next to the register.
    My Computer\HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell folders

    There is an entry named personal. Read the path of this entry when running while generating / record file to the customer's location and save the file in this path.

    -Clément

  • Problem with the case where the clause

    Hello

    I want to use cases in which clause. I wrote a very simple query to test how it works. However, I always got an error message. Here's what I did.

    Select eid, firstname, lastname from employee where eid = 1 works fine

    Select eid, name, name of the employee

    where

    cases where 1 = 1 then eid = 1

    When 1! = 1 then eid = 2

    end

    I ORA-00905: lack of keyword.

    Did I miss something?

    Thank you

    Jennifer

    Hi, Jennifer.

    Why do you want to use BOX in a WHERE clause?  The wonderful thing about the CASE is that it allows you to do IF-THEN-ELSE logic.  In a SELECT clause, or an ORDER BY clause, this is really useful, but the WHERE clause already allows you to use the IF-THEN-ELSE logic.

    However, if you use the BOX in a WHERE clause, it is as it does nowhere else.  Always BARGAIN instead of a single expression in a SQL data types.  All the clauses THEN (and ELSE, if there is one) must return a single expression, such as the NUMBER.  (There is no BOOLEAN data type in SQL).  So, you can use a CASE statement like this:

    ...

    CASES WHERE

    WHEN 1 = 1 THEN 1

    WHEN 1! = 1 THEN 2

    END = eid

    Here, the CASE expression takes the place of a NUMBER.

    However, if I was not sure if 1 = 1 or not, I would write the condition in this way, without a CASE expression:

    WHERE (1 = 1 AND eid = 1)

    OR (1! = 1 AND eid = 2).

  • A clumsy behavior of the place where the clause on joins

    I have a problem to join tables querying. If i:

    (1) join two tables
    (2) then filter a few lines with 'where '.
    (3) then filter the result with another 'where '.

    It seems oracle swaps two filtering. It seems wrong for two 'where' clauses cannot be expected.

    How to reproduce:
    create table table_a(
      n_a Number);
      
    create table table_b(
      n_b Number);
      
    insert into table_a (n_a) values(1);
    insert into table_a (n_a) values(2);
    insert into table_b (n_b) values(1);
    commit;
    
    create or replace function func(p_n in Number)
      return Number
    as begin
      if p_n = 1 then
        raise_application_error(-20100, 'Redwood City, we have a problem');
      end if;
      
      return p_n;
    end;
    /
    The fact that the following query works:
    select *
      from table_a
      left join table_b
        on table_a.n_a = table_b.n_b
     where n_b is null;
    and it didn't 'has value 1 ='. But
    with t as (
      select *
        from table_a
        left join table_b
          on table_a.n_a = table_b.n_b
       where n_b is null)
    select * from t
     where func(n_a) = 2
    fails, although "func" throws the exception only on the value "1", which I assume to be absent in 't', I have filtered it earlier. The question is exposed both in oracle 10 and 11.

    Is this a bug or expected behaviour? In any case, how could avoid dealing with 'where' oracle as commutative?

    UPD
    Even easier way to reproduce without a user-defined function:
    with t as (
      select *
        from table_a
        left join table_b
          on table_a.n_a = table_b.n_b
       where n_b is null)
    select * from t
     where 1/(n_a-1) = 2
    It will trigger the divide by zero exception.

    Published by: 922141 on 24.09.2012 06:17

    Published by: 922141 on 24.09.2012 06:25

    Hello

    The optimizer may choose to evaluate the conditions in an order; He can choose to evaluate the conditions of the main query WHERE clause before it evaluates the conditions in the WHERE clause of the query-sub.
    You can force it to evaluate the subquery all first by adding ROWNUM to its result set:

    with t as (
      select table_a.*, table_b.*, ROWNUM AS r_num     -- *****  CHANGED  *****
        from table_a
        left join table_b
          on table_a.n_a = table_b.n_b
       where n_b is null)
    select * from t
     where func(n_a) = 2
    ;
    
  • Source of SQL in the Page with variables

    Hello

    I need to set up a source of the page with the conditions in which the declaration.
    For example Select * from mytable where myField = myVar1.
    The where statement must be used, if a text box: myBox contains a specific value.
    The content of myVar1 should vary also in regard to the value in: myBox.
    How can I do this?
    Thanks in advance for you help.

    Edited by: kps204020 the 05.10.2012 16:09

    Select * from mytable where (myField =: P1_PAGE_ITEM or nvl(:P1_PAGE_ITEM,-1) =-1)

    Assumming myField is a numeric field, and P1_PAGE_ITEM is your myVal1 and is assumed to be a number. I must use you bind variables for security reasons.

  • Problem with dynamic setting where the clause OFA

    Hi all

    I have a view object with the following query:

    SELECT rownum LINENUM,

    B.line_id LINE_ID,

    B.INVENTORY_ITEM_ID INVITMID,

    B.QUANTITY_DELIVERED PICKQTY

    MTL_TXN_REQUEST_HEADERS a,.

    MTL_TXN_REQUEST_LINES B

    WHERE A.HEADER_ID = B.HEADER_ID

    AND A.MOVE_ORDER_TYPE = 2

    AND "on" =: 1

    AND B.TO_SUBINVENTORY_CODE = NVL(:4,B.TO_SUBINVENTORY_CODE)

    AND A.request_number = NVL(:5,A.REQUEST_NUMBER)

    UNION ALL

    SELECT rownum LINENUM,

    a.wip_entity_id LINE_ID,

    a.INVENTORY_ITEM_ID INVITMID,

    a.QUANTITY_ISSUED PICKQTY

    WIP_REQUIREMENT_OPERATIONS has

    eam_work_orders_v b

    WHERE a.wip_entity_id = b.wip_entity_id

    AND "on" =: 2

    AND a.ATTRIBUTE2 = NVL(:4,a.ATTRIBUTE2)

    and b.wip_entity_name = NVL(:6,b.wip_entity_name)

    I need to dynamically pass a condition to my where clause that I can manage it by setting two binding settings in the query of vo and can pass it on but the problem is the connection variable contains a string like 1311,13112,14445 that I need to spend for a domain like B.line_id in the first query and b.wip_entity_id in the second query , so when I'm passing the string as a value it works fine, but it gives for value separetd by comma prob.

    so I tried passing dynamic where clause, but there is every time that the execution of the first clause only how can I dynamically pass both queries.

    vo.setWhereClause ("LINE_ID in" + wherclause);

    Please help me

    Thnaks

    Deb

    Hello

    Actually I'm passing the parameter to the basic page popup, so in page popup page and the base, I was using the VO even to run then, probably due to that he was running again for all data, so for the basic page I created a new VO and tried to pass the parameter like when clause for questioning now it runs very well Thank you for all your help

  • Select the query with the level line list where the clause

    Hi all

    I am creating a tabular presentation based on a SQL query that has a list of selection based on a query with a where clause clause that refers to a column in the original SQL query.

    The situation is, I have a table that stores the client_id, source_id, and build_id, lets call it client_source. I have a second table, build_source, containing source_id and build_id, one to many relations between the two (1 source_id could have build_id 1-7).

    Using a tabular presentation, I want to select the correspondent build_id to use in client_source, but the selection list should contain only the build_id for this particular source_id of lines.

    Here is an example of the SQL source of tabular presentation;

    Select
    s.ROWID,
    s.CLIENT_ID,
    s.SOURCE_ID,
    APEX_ITEM. SELECT_LIST_FROM_QUERY (1, s.BUILD_ID,)
    "Select display b.build_id, b.build_id return.
    b build_source where b.source_id = s.SOURCE_ID ') lst
    of s client_source

    what I want to achieve, it's as source_id "BOLD" match fields. When the query is built this way, I get an error of "invalid identifier" Oracle on s.SOURCE_ID during execution.

    Is there some special tags to be used to refer to the external column? I must be missing something because this looks like a pretty mundane problem.

    I am running on 4.1.0.00.32, on an Oracle 10 g release 10.2.0.4.0 Server Express request.


    I look forward to useful responses!


    See you soon,.
    Jason

    Published by: 1005131 on May 9, 2013 19:02

    Your selection by query list receives a static SQL. That SQL can't "see" the value of your s.source_id.
    But it would work like this:
    where b.source_id = ' | s.SOURCE_ID)

    You would be the value for the SQL concatenation. It is not ideal, but it will work.

    Jorge

  • "Invalid column" on the place where several clauses with subqueries and cfqueryparam

    I see a behavior in the cfquery coldfusion I would like to find an exmplanation for.  I have a query that performs a subquery in the select part and if I have several where lines, I get a message 'invalid column name' to find out where my second article, but only when I'm with cfqueryparam

    For example, on what follows, I get "invalid column name «position_id»»

    SELECT department_staff_tbl.*,
    (SELECT max (bookmark_id)
    OF bookmarked_items_tbl
    WHERE item_id = department_staff_tbl.staff_id

    ) AS bookmark_id
    OF department_staff_tbl
    WHERE department_id = < cfqueryparam value = "" #arguments.deptid # "cfsqltype ="cf_sql_integer">"
    AND position_id = < cfqueryparam value = "" #arguments.posid # "cfsqltype ="cf_sql_integer">"
    AND staff_id = < cfqueryparam value = "" #arguments.staffid # "cfsqltype ="cf_sql_integer">"

    If I change the order of my where clause staff_id is first, and then he said "department_id" is an invalid column.

    If I don't have a where clause, it works.  (i.e. WHERE position_id = < cfqueryparam value = "" #arguments.posid # "cfsqltype =" cf_sql_integer">).

    If I remove the where clause of my subquery (WHERE item_id = department_staff_tbl.staff_id) it works.

    This also works if I remove the cfqueryparam where my article so that my query looks like this:

    SELECT department_staff_tbl.*,
    (SELECT max (bookmark_id)
    OF bookmarked_items_tbl
    WHERE item_id = department_staff_tbl.staff_id

    ) AS bookmark_id
    OF department_staff_tbl
    WHERE department_id = #arguments.deptid #.
    AND position_id = #arguments.posid #.
    AND staff_id = #arguments.staffid #.

    Any thoughts?

    A more conventional way to enter your data is without the subquery.  Something like that

    Select fields, the bookmarkid max (bookmark_id)

    from bookmarked_items__tbl join department_staff_tbl on staff_id = bookmark_id

    When etc.

    Some field group

  • Using arrary associative as parameter and passing then to the place where the clause of the select statement

    Hello

    I have this scenario where I have to pass multiple values to a parameter of a procedure of monkey and then collect in another variable (the lines can be multiple).

    The parameter must be used in the where clause of the statement select here I create a sample table for the problem.

    Create table test_tab (number of trans_id, cmts varchar2 (50));

    insert into test_tab values (568890112115, ' wnlb-CMTS-11-04' ");

    insert into test_tab values (568890112115, ' wnlb-CMTS-11-04' ");

    insert into test_tab values (568890112115, ' wnlb-CMTS-11-01' ");

    insert into test_tab values (568890112115, ' wnlb-CMTS-11-01' ");

    insert into test_tab values (568890112115, ' wnlb-CMTS-11-01' ");

    insert into test_tab values (568890112115, ' wnlb-CMTS-12-02' ");

    insert into test_tab values (568890112115, ' wnlb-CMTS-12-02' ");

    This is so all cmts have same trans_id but different name

    This query gives the result as -

    Select the cmts, count (1)

    of test_tab

    where cmts ("wnlb-cmts-11-04','wnlb-cmts-11-01", "wnlb-CMTS-11-02'")

    and trans_id = 568890112115

    Cmts group;

    COUNTY OF CMTS

    WNLB-CMTS-11-04 2

    3 WNLB-CMTS-11-01

    Now, I want to use this query in a PLSQL block like where I can spend the CMTS collection and trans_id as a scalar variable and once again an OUTPUT parameter that holds the result of the query.

    I use OUT parameter because it will be called to the JAVA program.

    Here, I write a PACKAGE for it but it gives me compilation error!

    create or replace package CMTS_SUCCESS_FAILED_API

    is

    type t_item_name is table of index varchar2 (50) by pls_integer;

    TYPE t_cmts_count () IS RENDERING

    CMTS VARCHAR2 (30),

    number of NUMBER

    );

    type t_reseg_dtl is table of index t_cmts_count by pls_integer;

    procedure CMTS_SUCCESS_FAILED_RESEG_ORDR (p_item_name t_item_name, p_trans_id in numbers, p_reseg_dtl to t_reseg_dtl);

    end CMTS_SUCCESS_FAILED_API;

    /

    Now that I have created a different PACKAGE BODY, but none don't work!

    1.

    create or replace package CMTS_SUCCESS_FAILED_API

    is

    type t_item_name is table of index varchar2 (50) by pls_integer;

    TYPE t_cmts_count () IS RENDERING

    CMTS VARCHAR2 (30),

    number of NUMBER

    );

    type t_reseg_dtl is table of index t_cmts_count by pls_integer;

    procedure CMTS_SUCCESS_FAILED_RESEG_ORDR (p_item_name t_item_name, p_trans_id in numbers, p_reseg_dtl to t_reseg_dtl);

    end;

    /

    create or replace package CMTS_SUCCESS_FAILED_API body

    is

    procedure CMTS_SUCCESS_FAILED_RESEG_ORDR (p_item_name t_item_name, p_trans_id in numbers, p_reseg_dtl to t_reseg_dtl)

    is

    Start

    I'm in p_item_name.first... p_item_name. Last

    loop

    Select the cmts, count (1)

    bulk collect into p_reseg_dtl (i)

    of test_tab

    where cmts = p_item_name (i)

    and trans_id = p_trans_id

    Cmts group;

    end loop;

    for r in p_reseg_dtl.first... p_reseg_dtl. Last

    loop

    dbms_output.put_line (p_reseg_dtl (r). TRANSACTION_ID | » '|| p_reseg_dtl (r). JOB_STATUS | » '|| p_reseg_dtl (r). CMTS);

    end loop;

    end CMTS_SUCCESS_FAILED_RESEG_ORDR;

    end CMTS_SUCCESS_FAILED_API;

    While I run this procedure it is said TOO_MANY LINES.

    2.

    create or replace package CMTS_SUCCESS_FAILED_API body

    is

    procedure CMTS_SUCCESS_FAILED_RESEG_ORDR (p_item_name t_item_name, p_trans_id in numbers, p_reseg_dtl to t_reseg_dtl)

    is

    cursor c_dtl is

    Select the cmts, count (1)

    of test_tab

    where cmts = p_item_name < < error

    and trans_id = p_trans_id

    Cmts group;

    Start

    Open c_dtl;

    collect the fetch c_dtl in bulk in p_reseg_dtl;

    close c_dtl;

    -for i in p_item_name.first... p_item_name. Last

    -loop

    -end loop;

    end;

    end;

    THIS error GIVES BODY as EXPRESSION IS OF TYPE INCORRECT for where clause where I mark it as "BOLD".

    I think Miss me a small detail to add here, but I can't do even now it seems for me that I'm working on it since the morning and SQL are a little complex in real time who also write.


    I use-

    Oracle Database 11 g Enterprise Edition Release 11.2.0.1.0 - 64 bit Production

    Please suggest me!

    Until then I'm also working on this issue hope will find a solution.

    In the database (we show it with a standalone function, you should put it in a package):

    create or replace function CMTS_SUCCESS_FAILED_RESEG_ORDR (
      p_item_name IN SYS.DBMS_DEBUG_VC2COLL,
      p_trans_id IN number
    )
    return sys_refcursor is
      l_refcur sys_refcursor;
    begin
      open l_refcur for
        SELECT cmts , COUNT(*)
          FROM test_tab
        WHERE cmts member of p_item_name
           AND trans_id = p_trans_id
        GROUP BY cmts;
      return l_refcur;
    end CMTS_SUCCESS_FAILED_RESEG_ORDR;
    /
    

    In Java:

    import java.math.BigDecimal;
    import java.sql.CallableStatement;
    import java.sql.Connection;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    
    import oracle.jdbc.OracleCallableStatement;
    import oracle.jdbc.OracleTypes;
    import oracle.jdbc.pool.OracleDataSource;
    import oracle.sql.ARRAY;
    import oracle.sql.ArrayDescriptor;
    
    public class SQLCollection {
    
        public static void main(String[] args) throws SQLException {
    
            System.out.println("Class SQLCollection started.");
    
            OracleDataSource ods = null;
            Connection conn = null;
            CallableStatement cs = null;
            ResultSet rset = null;
    
            try {
                ods = new OracleDataSource();
                String url = "jdbc:oracle:thin:@//127.0.0.1:1522/orcl.localdomain";
                ods.setURL(url);
                ods.setUser("stew");
                ods.setPassword("stew");
                conn = ods.getConnection();
                conn.setAutoCommit(false);
    
                ArrayDescriptor oracleVarchar2Collection =
                    ArrayDescriptor.createDescriptor("SYS.DBMS_DEBUG_VC2COLL", conn);
                String[] inset = new String[2];
                inset[0] = "wnlb-cmts-11-04";
                inset[1] = "wnlb-cmts-11-01";
                ARRAY ora_inset = new ARRAY(oracleVarchar2Collection, conn, inset);
    
                cs = conn.prepareCall("begin ? := CMTS_SUCCESS_FAILED_RESEG_ORDR(?, ?); end;");
                cs.registerOutParameter(1, OracleTypes.CURSOR);
                cs.setArray(2, ora_inset);
                cs.setBigDecimal(3, new BigDecimal("568890112115"));
                cs.execute();
    
                // Dump the cursor
                rset = ((OracleCallableStatement)cs).getCursor(1);
                while (rset.next())
                    System.out.println(rset.getString(1) + ": " + rset.getInt(2));
    
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                if (rset != null) {
                    rset.close();
                }
                if (cs != null) {
                    cs.close();
                }
                if (conn != null) {
                    conn.close();
                }
                System.out.println("Class SQLCollection ended.");
            }
        }
    }
    
  • in the clause with subquery in oracle

    Hi friends,

    I have two tables say table1 and table2 with details below

    create table test1 (identification number, name varchar2 (20));
    Insert into test1 values(11,'micro');
    Insert into test1 values(22,'soft');


    create table test2 (identification number, name varchar2 (20));
    Insert into test2 values(77,'micro,soft');

    (1) if I use under request I do not receive either delivering lines
    Select * from t1 test1 where t1.name in (select "': replace (t2.name, ','" ', "') |") ' from test2;

    (2) if I had the fire out one subquery I get is: "micro", "smooth".
    Select "' | Replace (t2.name, ',' "'," ') | " ' from test2;

    But if I fire the query (1) I need the result
    name identity
    ------------
    11 microphone
    22 soft

    can someone please help me to get the same result with a query (1).

    Few things

    1. your table TEST2 is not in first normal form (1NF). It's ugly!

    2. IN paragraph does not evaluate a single variable or a column with values defined as several values, they are just single value.

    FAQ a few details, read Re: 7. the list of values in an IN clause?

    And this is how its done (one-way)

    SQL > select id, name
    test1 2
    3 where name in)
    4 Select regexp_substr (name, "[^,] +', 1, level")
    5 of test2
    6 where id = 77
    7. plug
    8 per level<= length(name)-length(replace(name,="">
    9                 );

    ID NAME
    ---------- --------------------
    11 microphone
    22 soft

  • SQL in the command with the parameter

    Hello

    When I tried to run this query, it returns the empty data set.did I missed something or is - it is not allowed to use?

    SQL:

    String sql ="select * from customer where customerId in (?) » ;
    objConnection = super.getConnection ();

    = objConnection.prepareStatement (sql) stmt1;
    stmt1. SetString (1, id); Here id format will be ('100', '102'...)

    resultSet = stmt1.executeQuery ();

    Thanks in advance.

    You mean something like...

    SQL> ed
    Wrote file afiedt.buf
    
      1  select *
      2  from emp
      3  where ename in (
      4    with t as (select '&input_string' as txt from dual)
      5    select REGEXP_SUBSTR (txt, '[^,]+', 1, level)
      6    from t
      7    connect by level <= length(regexp_replace(txt,'[^,]*'))+1
      8*   )
    SQL> /
    Enter value for input_string: SCOTT,JAMES
    old   4:   with t as (select '&input_string' as txt from dual)
    new   4:   with t as (select 'SCOTT,JAMES' as txt from dual)
    
         EMPNO ENAME      JOB              MGR HIREDATE                   SAL       COMM     DEPTNO
    ---------- ---------- --------- ---------- ------------------- ---------- ---------- ----------
          7788 SCOTT      ANALYST         7566 19-04-1987 00:00:00       3000                    20
          7900 JAMES      CLERK           7698 03-12-1981 00:00:00        950                    30
    
    SQL>
    
  • When the clause with conditions

    Hi all

    I have a report that must be filtered according to user input in a field of text and drop-down list.
    The goal is to let the user enter either an exact value (based on the AutoComplete feature) or use the wildcard character %

    It is where comes the menu drop down. If they choose value1, AutoComplete, the exact value is used and the where clause would look like something below,
    select col1, col2, col3
    from table
    where :P1_FILTER in (select distinct col2 from another_table)
    If they choose value2, then where should deal with using the same function and % s. something like:
    select col1, col2, col3
    from table
    where :P1_FILTER like (select distinct col2 from another_table)
    How can I take care of this in 1 where clause? I'm kind of stuck trying to figure out.
    Thanks for any help.

    -Chris

    Try this:

    select col1, col2, col3
    from table
    where
    (
    :P1_FILTER in (select distinct col2 from another_table)
    AND
    :P1_LOV =1
    )
    OR
    (
     :P1_FILTER like (select distinct col2 from another_table)
    AND
    :P1_LOV =2
    )
    

    I hope this helps!
    Sam

  • SQL - select the data with the nearest past date

    Hello
    I have a requirement to retrieve data based on a closer effective_date in the past.
    Here are examples of data

    Data in the table

    DESCRIPTION OF ARTICLE EFFECTIVE_DATE
    ---------------------------------------------------------------------------
    018885237 24 OCTOBER 09 DVD + R 47 10 PK
    DISC OF DVD + R 10 018885237 16 APRIL 10

    040706113 FLASH PLAYER 24 OCTOBER 09
    040706113 4 March 10 Micro USB 4 GB
    040706113 13 January 10 Flash drive 4 GB

    032140640 26 FEBRUARY 10 8 GB USB
    032140640 24 OCTOBER 09 8 GB FLASH

    The power required

    DESCRIPTION OF ARTICLE EFFECTIVE_DATE
    ---------------------------------------------------------------------------
    DISC OF DVD + R 10 018885237 16 APRIL 10
    040706113 4 March 10 Micro USB 4 GB
    032140640 26 FEBRUARY 10 8 GB USB

    Can someone help me with the SQL please?

    Concerning
    Harsha
    SQL> --- generating sample  data:
    SQL> with t as (
      2  select 018885237 item, to_date('24-OCT-09', 'dd-mon-yy') effective_date, 'DVD+R 47 10 PK' description from dual unio
      3  select 018885237, to_date('16-APR-10', 'dd-mon-yy'), 'DVD+R 10 DISC' from dual union
      4  select 040706113, to_date('24-OCT-09', 'dd-mon-yy'), 'FLASH DRIVE' from dual union
      5  select 040706113, to_date('04-MAR-10', 'dd-mon-yy'), '4GB USB Micro' from dual union
      6  select 040706113, to_date('13-JAN-10', 'dd-mon-yy'), 'Flash Driv 4GB' from dual union
      7  select 032140640, to_date('26-FEB-10', 'dd-mon-yy'), '8GB USB' from dual union
      8  select 032140640, to_date('24-OCT-09', 'dd-mon-yy'), '8GB FLASH' from dual
      9  )
     10  --
     11  -- actual query
     12  --
     13  select  item
     14  ,      effective_date
     15  ,      description
     16  from ( select item
     17         ,      effective_date
     18         ,      description
     19         ,      row_number() over (partition by item order by effective_date desc)  rn
     20         from   t
     21       )
     22  where rn=1;
    
          ITEM EFFECTIVE DESCRIPTION
    ---------- --------- --------------
      18885237 16-APR-10 DVD+R 10 DISC
      32140640 26-FEB-10 8GB USB
      40706113 04-MAR-10 4GB USB Micro
    
  • Placing values retuened to a cursor at the place where the clause of a query SELECT

    Hello
    I'm trying to accomplish a task of writing a SELECT statement where I have to query the table based on the values returned by a cursor.
    For example:
    SELECT a.operator_name, a.country_name, a.state_name FROM Table_A a WHERE a.country_id IN (values returned by cursor for country ID) AND the a.operator_name in (values returned by cursor for Operator_Id) AND a.state_id in (values returned by cursor State_ID for).

    Is it possible to make this request, my task is to write it in a stored procedure so that I can return a cursor reference with values as described above.
    Please let me know how to go about this request.

    PS: Cursors are used because it is a Wild-Card search for values where several records can be returned.

    Thanks in advance.

    Kind regards
    Priya

    Because your

    SELECT a.operator_name, a.country_name, a.state_name
      FROM Table_A a
     WHERE a.country_id IN (Values returned from cursor for Country ID's)
       AND a.operator_name IN (Values returned from Cursor for Operator_Id's)
       AND a.state_id IN (Values returned from Cursor for State_ID's)
    

    say something like (sliders deliberately avoided (see Tom Kyte mantra - http://asktom.oracle.com/pls/apex/f?p=100:11:0:::P11_QUESTION_ID:73891904732164))

    SELECT operator_name,country_name,state_name
      FROM Table_A
     WHERE country_id IN (select country_id
                            from countries
                           where upper(country_name) like 'U%?
                         )
       AND operator_name IN (select operator_id
                               from operators
                              where operator_name like 'A%'
                            )
       AND state_id IN (select state_id
                          from states
                         where state_name like 'C%'
                       )
    

    Concerning

    Etbin

  • the clause WITH XMLNAMESPACES xmltable: do you go on the internet for xsd?

    Hello

    I have a request of xmltable passing an xmltype variable.

    Something like this:
    select id, name, data
    From XMLTable(XMLNamespaces ('https://www3.somesite.es/bla/bla/bla/thexsd.xsd' as "n1" , 
                                        'https://www3.somesite.es/bla/bla/bla/otherxsd.xsd' as "co") , 
                         '/n1:some/tag' passing l_my_xmltype_var 
    COLUMNS id        NUMBER(20)      PATH '//n1:id' ,
                                 name        VARCHAR2(9)     PATH '//n1:name' ,
                                 data     VARCHAR2(125)   PATH '//co:datatxt') X
    This query is executed in a loop, and we try to improve its performance.
    S/n told me that whenever the query is run, we need to get the two xsd via internet.

    1. is this true?
    2. If it is... Can I keep the local XSD or even inside the database? (I heard something on the registration of the scheme)

    Thank you

    Julius says:
    The actual query has more than 75 columns. Its consumption is spent on java, so I have to assume that this is because of the money the xmltable process analysis.

    You OR do something (horribly) wrong OR should move to a longer version of database great or equal to 10.2.0.3.x

    PLEASE post your version of the database (all figures!)

    Do you mean that, even working with a local xmltable passing a variable xmltype (not a structured xml real chart), save the scheme will do good performance?

    Yep, for example by avoiding calls JAVA... through the registered XML schema validation is optimized if not only because of its kernel code, it's C - code

    I guess I have to:
    1 save the xsd
    2 reference him when I create the xmltype variable (by adding the second parameter to the function of xmltype).

    Fix.

    Then, during the treatment of xmltable, the engine will be smart enough to use the xsd saved info to improve the query performance? Okay, I'm a little skeptical, but will give it a try.

    I will also try to facilitate the processing by specifying the path of the full tree instead of using "/ / tag.

    It will make a difference (providing you're at least on 10.2.0.3.x regarding the use of XMLTABLE, the XQuery engine...)

    As a curiosity, all this quest for optimization of query came when - after a change - the performance of the query went from 5 seconds to 90 seconds. Things went south when I added a * in select it the list instead of referring columns with their names. So it doesn't seem a good idea to use * with a high column number xmltable

    Perhaps, but cannot say. These questions depend on many parameters and environment settings. It could be a connection problem or... or...

    It's one of the reasons why we need the version of database for you give a better answer...

    Published by: Marco Gralike June 8, 2011 11:17

Maybe you are looking for