Cursor with where X In ( :Parameter) clause

Hello,
I'm having a problem with this type of cursors:
declare
cursor c_cursor is
select * from emp
where id IN ( :PARAMETER.P_ID );
begin
end;
When :PARAMETER.P_ID is a list of numbers separeted by comma, like this one : 1,2,3 , the cursor doesn't work ( does not bring relevant data or any data ). In Reports we used to make it work with lexical parameters. How about in Forms? Is there anything I can do to make it work?
Note: I really need a cursor, NOT a sql string to put it in EXECUTE_IMEDIATE statement

Create a function returning a collection, and select from that:
Re: Passing Parameters to reports - Help needed

Similar Messages

  • Passing where cluase as parameter for cursor

    I want to pass where clause of cursor as parameter.... how can I do that?
    say I want cursor as,
    cursor c1 is select fname, mname from person where :param;
    where :param is a value I want to pass in declare section

    I want to pass where clause of cursor as parameter.... how can I do that?Yes.
    cursor c1 is select fname, mname from person where :param;
    where :param is a value I want to pass in declare sectionYou can also shoot yourself in the foot using a 357 Magnum.
    Neither is recommended - unless you are a professional idiot. Which I doubt as these are typically your Darwin Award Winners.
    Why is it bad to to have "+WHERE :param+"?
    Bind variables. If the WHERE clause is passed as a dynamic string. this will usually be implemented in the following fashion:
    SQL> create or replace procedure smellyFoo( filterClause varchar2, refCur in out sys_refcursor ) is
      2  begin
      3          open refCur for
      4          'select owner, object_id, object_name from all_objects where owner != ''SYS'' and '||filterClause||' order by 1,2';
      5  end;
      6  /
    Procedure created.
    SQL>
    SQL> var c refcursor
    SQL> exec smellyFoo( 'object_type=''TABLE'' and rownum <11', :c );
    PL/SQL procedure successfully completed.
    SQL>
    SQL> print c
    OWNER       OBJECT_ID OBJECT_NAME
    OUTLN             452 OL$
    OUTLN             453 OL$HINTS
    OUTLN             456 OL$NODES
    SYSTEM           3621 MVIEW$_ADV_WORKLOAD
    SYSTEM           3624 MVIEW$_ADV_BASETABLE
    SYSTEM           3626 MVIEW$_ADV_SQLDEPEND
    SYSTEM           3628 MVIEW$_ADV_PRETTY
    SYSTEM           3630 MVIEW$_ADV_TEMP
    SYSTEM           3632 MVIEW$_ADV_FILTER
    SYSTEM           3634 MVIEW$_ADV_LOG
    10 rows selected.
    SQL>What's wrong with this? The filter clause contains literals. Not bind variables. Which means that non-sharable SQL will be created. This means more cursors (for same SQLs with different literal values) in the shared pool. Different sizes SQLs that leads to fragmentation of the shared pool memory. More hard parsing. Bigger delay in parsing as there are more cursors to scan in the shared pool (useless exercise) as there are no existing cursors that are sharable and can be re-used.
    So what would the correct way be? The client passing a filter clause as a proper bind variable string, and also passing (separately) the values for those bind variables. But this is not easy to code, especially when dealing with filter clauses that may contain no bind variables. or a 100 bind variables.
    Also, the call interface the client needs to use will become a lot more complex as the client now not only needs to build a proper string containing bind variables, it also need to make sure it pass the values for those variables in the correct order.
    So why? Why do any of this? What is the requirement that lead you to this "solution" where the client can dynamically decide on what the filter criteria is?
    Surely, there must be a reason to this madness of the client wanting to throw any filter clause at a SQL cursor... and surely, that is what needs to be identified and analysed and resolved - instead of wanting to create hacks like the above. Causing performance issues. Not to mention opening a security hole that is ideal for SQL injection.

  • 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/

  • Cursor with for update clause problem

    Hi all,
    We are having this problem with Oracle 8.1.7 where in we have a cursor with for update clause. The PL/SQL script used to work fine with Oracle 8.0.5 but is causing problems with Oracle 8.1.7. What the script is ending up doing in 8.1.7 is that it updates only one record instead of updating close to 60000 which it used to do in Oracle 8.0.5
    The script just hangs after updating one record. We have replicated the same problem.
    Has anyone seen this error before and attained resolution?
    Thanks

    Hello ,
    I have found the same / very close to the same problem. I tried the code below in Oracle 10.2.0.1 and got the following error after the first loop.
    ORA-01002: fetch out of sequence
    ORA-06512: at "DEMO_TEST_RESEARCH_PKG", line 18
    ORA-06512: at line 7
    After trying to debug it , i thought i would try it in Oracle 9.0.2.0.7.0 , and to my suprise it worked fine.
    Am i missing something ? Thanks in advance , ...
    I have included the code i was running ...
    PROCEDURE WhereCurrentOf(Param1 IN NUMBER) IS
    v_title_eng ISSUES.TITLE_ENG%TYPE;
    v_issue_id ISSUES.ISSUE_ID%TYPE;
    CURSOR issues_cur
    IS
    SELECT issue_id,title_eng
    FROM issues
    WHERE title_eng IS NULL
    FOR UPDATE OF title_eng;
    BEGIN
    FOR i IN issues_cur
    LOOP
    FETCH issues_cur INTO v_issue_id,v_title_eng;
    EXIT WHEN issues_cur%NOTFOUND;
    DBMS_OUTPUT.PUT_LINE(v_issue_id||' This was the english title before : '||v_title_eng);
    v_title_eng := 'This is my title';
    UPDATE issues
    SET title_eng = v_title_eng
    WHERE CURRENT OF issues_cur;
    DBMS_OUTPUT.PUT_LINE(v_issue_id||' This is the english title after : '||v_title_eng);
    END LOOP;
    END WhereCurrentOf;

  • Huge query  with  parameter for to use Dynamic Cursor with Parameters

    Hi
    Is possible put the query below like dynmic cursor passing Parameters ?
    How can I do it ?
        OPEN P_CURSOR FOR
        WITH NOTIFICACAO AS(
          SELECT 
           t1.cd_consultora,
           t1.dc_nome_consultora,
           t2.nm_notificacao_cn,
           t2.dt_notificacao_cn dt_notificacao,
           t2.dt_atendimento_notificado,
           t1.cd_tipo_estrutura_comercial,
           t1.cd_estrutura_comercial
            FROM t_consultora t1, nc.t_nc_notificacao_cn t2
           WHERE t2.dt_notificacao_cn BETWEEN w_DTA_INI AND w_DTA_FIM
             AND t2.cd_consultora = t1.cd_consultora
             AND t1.cd_setor = w_cd_setor
             AND t1.cd_tipo_estrutura_comercial = p_tp_estrutura_comercial
             AND t1.cd_estrutura_comercial = p_cd_estrutura_comercial),
        T_NOTIFICADA AS ( select Count(t1.nm_notificacao_cn) over (partition by  t1.cd_consultora,t1.nm_notificacao_cn ) QTD_NOTAS,
                                 Count(t2.nm_item_notificacao_cn) over (partition by  t1.cd_consultora,t1.nm_notificacao_cn ) QTD_ITENS,
                                 T3.*
                                  from nc.t_nc_notificacao_cn t1,
                                       nc.t_nc_item_notificacao_cn  T2,
                                       NOTIFICACAO                  T3 
                                   where       t1.dt_notificacao_cn >= to_date('01/09/2006','dd/mm/yyyy')
                                    and   t3.nm_notificacao_cn = t1.nm_notificacao_cn
                                   and    t1.nm_notificacao_cn = t2.nm_notificacao_cn
                                   and    ((t2.cd_tipo_item_nc = 4 and t2.cd_subtipo_item_nc = 6)
                                           or t2.cd_tipo_item_nc = 2 or t2.cd_tipo_item_nc = 3)
                                           and t3.cd_consultora = t1.cd_consultora (+)  )  ,
        T_BLOQUEADA AS ( SELECT T4.* FROM
                     (SELECT  T3.*,
                            CASE WHEN T3.BLOQUEADA = -1 THEN  'Bloqueada'
                                 WHEN  T3.BLOQUEADA = 0 THEN
                              (CASE WHEN T3.QTD_NOTAS > 2 THEN
                                 CASE WHEN T3.QTD_ITENS > 8 THEN 'Atencao / Analise'
                                 ELSE
                                    'Normal'
                                 END
                               ELSE
                                 'Atencao / Analise'   
                              END)
                             END OBSERVACAO
                      FROM  (SELECT CASE WHEN NVL(T2.ID_CN_BLOQUEADA,1) = 1 then -1
                                   WHEN NVL(T2.ID_CN_BLOQUEADA,1) = 0  THEN 0
                                   END BLOQUEADA, T1.*
                        FROM   T_NOTIFICADA T1,
                               T_PS_CONSULTORA T2 
                               WHERE T1.CD_CONSULTORA = T2.CD_PESSOA)T3) T4 )
            select *
              from (SELECT t1.*, ROWNUM r_linha
               FROM (SELECT  cd_consultora,
                       dc_nome_consultora,
                       fnc_busca_telefone(CD_CONSULTORA, 1) TELEFONE1,
                       fnc_busca_telefone(CD_CONSULTORA, 2) TELEFONE2,
                        EMAIL,
                        observacao,
                       nm_notificacao_cn,
                       nvl(vl_total_final,0) vl_total_final,                  
                       dt_notificacao,
                       qt_produto_item_nc,
                      sg_notificacao,
                      ID_SITUACAO,
                       qtd_registros
                    FROM (SELECT /*+ INDEX(W5 I0_NC_TIPO_ITEM_NC) */
                       W1.cd_consultora,
                       W1.dc_nome_consultora,
                       fnc_busca_telefone(w1.CD_CONSULTORA, 1) TELEFONE1,
                       fnc_busca_telefone(w1.CD_CONSULTORA, 2) TELEFONE2,
                       fnc_busca_email(w1.CD_CONSULTORA) EMAIL,
                       W1.OBSERVACAO observacao,
                       W1.nm_notificacao_cn,
                       sum(W4.qt_produto_nf *
                           W4.vl_unitario_final_produto_nf) OVER(PARTITION BY W1.cd_consultora, W1.nm_notificacao_cn) vl_total_final,
                       W1.dt_notificacao,
                       sum(W4.qt_produto_nf) OVER(PARTITION BY W1.cd_consultora, W1.nm_notificacao_cn) qt_produto_item_nc,
                       'PENDENTE' sg_notificacao,
                       W5.dc_tipo_item_nc ID_SITUACAO,
                       W_qtd_registros qtd_registros
                        FROM T_BLOQUEADA               W1,
                             nc.t_nc_item_notificacao_cn W2,
                             nc.t_nc_produto_item_nc     W3,
                             nc.t_nc_produto_item_nf     W4,
                             nc.t_nc_tipo_item_nc        W5
                       WHERE W1.dt_atendimento_notificado is null
                         and W1.nm_notificacao_cn =
                             W2.nm_notificacao_cn
                         and W2.cd_tipo_item_nc = W5.cd_tipo_item_nc
                         and W2.nm_notificacao_cn =
                             W3.nm_notificacao_cn(+)
                         and W2.nm_item_notificacao_cn =
                             W3.nm_item_notificacao_cn(+)
                         and W3.nm_notificacao_cn =
                             W4.nm_notificacao_cn(+)
                         and W3.nm_item_notificacao_cn =
                             W4.nm_item_notificacao_cn(+)
                         and W3.nm_sequencia_produto_item_nc =
                             W4.nm_sequencia_produto_item_nc(+)
                         and W2.cd_tipo_item_nc not in (6, 7)
                         and ((W2.id_situacao_item_nc = 1) OR
                             (W2.id_situacao_item_nc = 3 OR
                             W2.id_solucao_definida is not null))
                      UNION
                      SELECT /*+ INDEX(W5 I0_NC_TIPO_ITEM_NC) */
                       W1.cd_consultora,
                       W1.dc_nome_consultora,
                       fnc_busca_telefone(w1.CD_CONSULTORA, 1) TELEFONE1,
                       fnc_busca_telefone(w1.CD_CONSULTORA, 2) TELEFONE2,
                       fnc_busca_email(w1.CD_CONSULTORA) EMAIL,
                       W1.OBSERVACAO observacao,
                       W1.nm_notificacao_cn,
                       sum(W4.qt_produto_nf *
                           W4.vl_unitario_final_produto_nf) OVER(PARTITION BY W1.cd_consultora, W1.nm_notificacao_cn) vl_total_final,
                       W1.dt_notificacao,
                       sum(W4.qt_produto_nf) OVER(PARTITION BY W1.cd_consultora, W1.nm_notificacao_cn) qt_produto_item_nc,
                       'ATENDIDO' sg_notificacao,
                       W5.dc_tipo_item_nc ID_SITUACAO,
                       W_qtd_registros qtd_registros
                        FROM T_BLOQUEADA                W1,
                             nc.t_nc_item_notificacao_cn W2,
                             nc.t_nc_produto_item_nc     W3,
                             nc.t_nc_produto_item_nf     W4,
                             nc.t_nc_tipo_item_nc        W5
                       WHERE W1.dt_atendimento_notificado is not null
                         and W1.nm_notificacao_cn =
                             W2.nm_notificacao_cn
                         and W2.cd_tipo_item_nc = W5.cd_tipo_item_nc
                         and W2.nm_notificacao_cn =
                             W3.nm_notificacao_cn(+)
                         and W2.nm_item_notificacao_cn =
                             W3.nm_item_notificacao_cn(+)
                         and W3.nm_notificacao_cn =
                             W4.nm_notificacao_cn(+)
                         and W3.nm_item_notificacao_cn =
                             W4.nm_item_notificacao_cn(+)
                         and W3.nm_sequencia_produto_item_nc =
                             W4.nm_sequencia_produto_item_nc(+)
                             )T2
    ---- here with NDS   I changed order by
                       ORDER BY DECODE(p_nm_asc_desc,0,DECODE(p_nm_col_ordem ,1, cd_consultora,2,dc_nome_consultora)) ASC, --,8,vl_total_final)) ASC,
                       DECODE(p_nm_asc_desc,1,DECODE(p_nm_col_ordem ,1, cd_consultora,2,dc_nome_consultora)) desc --,8,vl_total_final)) DESC
                             ) T1
               where rownum <= W_TO_REC)
             where r_linha >= W_FROM_REC;Is It Query very much great and how can I to pass parameters w_DTA_INI ,w_DTA_FIM, W_TO_REC,W_FROM_REc ....etc
    TIA

    I did (some time ago and it was a packaged procedure) something like
    Procedure p(p_one in datatype,p_two in datatype,p_dataset out sys_refcursor) is
      the_sql varchar2(32000);
      the_cursor sys_refcursor;
    begin
      the_sql = 'WITH NOTIFICACAO AS( ' ||
                '      SELECT ' ||
                '       t1.cd_consultora, ' ||
                '                               where       t1.dt_notificacao_cn >= to_date(''01/09/2006'',''dd/mm/yyyy'') ' ||  -- note the ''
                '           where rownum <= :W_TO_REC) ' ||   -- parameter 1
                '         where r_linha >= :W_FROM_REC ';     -- parameter 2
      open the_cursor for the_sql using p_one,p_two;  -- just by the book
    end p;if I remember correctly
    Regards
    Etbin

  • Difference Ref cursor with/with out using clause

    Hi everyone,
    When I am using dynamic sql with USING clause ,the results are not sorted in Ascending order.
    DECLARE
    TYPE emp_refcursor IS REF CURSOR;
    emp_rc emp_refcursor;
    TYPE v_emp_id IS TABLE OF number INDEX BY PLS_INTEGER;
    TYPE v_last_name IS TABLE OF varchar2(50) INDEX BY binary_integer;
    V_empno v_emp_id;
    v_ename v_last_name;
    p_deptno number := &U_DEPTNO;
    v_limit number := 10;
    v_ordcolumn varchar2(20) := 'employee_id';
    v_stmt varchar2(1000);
    BEGIN
    v_stmt :=
    'select employee_id,last_name from employees
    where department_id = :x order by :y ';
    dbms_output.put_line(v_stmt);
    OPEN emp_rc FOR v_stmt USING p_deptno,v_ordcolumn;
    LOOP
    FETCH emp_rc BULK COLLECT INTO v_empno,v_ename LIMIT v_limit;
    EXIT WHEN v_empno.count = 0;
    FOR I IN v_empno.first .. v_empno.last
    LOOP
    dbms_output.put_line(v_empno(i)||' '||v_ename(i));
    END LOOP;
    END LOOP;
    END;
    When I use dynamic sql with out USING cluase,results are sorted in Ascending order.
    DECLARE
    TYPE emp_refcursor IS REF CURSOR;
    emp_rc emp_refcursor;
    TYPE v_emp_id IS TABLE OF number INDEX BY PLS_INTEGER;
    TYPE v_last_name IS TABLE OF varchar2(50) INDEX BY binary_integer;
    V_empno v_emp_id;
    v_ename v_last_name;
    p_deptno number := &U_DEPTNO;
    v_limit number := 10;
    v_ordcolumn varchar2(20) := 'employee_id';
    v_stmt varchar2(1000);
    BEGIN
    v_stmt :=
    'select employee_id,last_name from employees
    where department_id = '||p_deptno ||
    ' order by '||v_ordcolumn;
    dbms_output.put_line(v_stmt);
    OPEN emp_rc FOR v_stmt;
    LOOP
    FETCH emp_rc BULK COLLECT INTO v_empno,v_ename LIMIT v_limit;
    EXIT WHEN v_empno.count = 0;
    FOR I IN v_empno.first .. v_empno.last
    LOOP
    dbms_output.put_line(v_empno(i)||' '||v_ename(i));
    END LOOP;
    END LOOP;
    END;
    P.S :---- department_id (used) = 50;
    Please can some one explain why this is happening like this.
    Thanks
    Raghu
    --------------------------------------------------------------------------------

    Hi sundar,
    I am new to oracle and learning/trying to get the same output by using differnt methods,rather than using FOR LOOP ,I tried to use ref cursor with dynamic sql.I am in a belief that ref cursor's with dynamic sql are faster than FOR LOOP,irrespective of the size of data.Can you correct me if I am wrong.
    Coming back to ur reply,how should my statement look like,when using ref cursor
    with USING claus to sort data by asc/desc order.
    Thanks in advance
    Raghu

  • Performance problem with sproc and out parameter ref cursor

    Hi
    I have sproc with Ref Cursor as an OUT parameter.
    It is extremely slow looping over the ResultSet (does it record by record in the fetch).
    so I have added setPrefetchRowCount(100) and setPrefetchMemorySize(6000)
    pseudo code below:
    string sqlSmt = "BEGIN get_tick_data( :v1 , :v2); END;";
    Statement* s = connection->createStatement(sqlStmt);
    s->setString(1, i1);
    // cursor ( f1 , f2, f3 , f4 , i1 ) f for float type and i for interger value.
    // 5 columns as part of cursor with 4 columns are having float value and
    // 1 column is having int value assuming 40 bytes for one rec.
    s->setPrefetchRowCount (100);
    s->PrefetchMemorySize(6000);
    s->registerOutParam(2,OCCICURSOR);
    s->execute();
    ResultSet* rs = s->getCursor(2);
    while (rs->next()) {
    // do, and do v slowly!
    }

    Hi,
    I have the same problem. It seems, when retrieving cursor, that "setPrefetchRowCount" is not taking into account by OCCI. If you have a SQL statement like "SELECT STR1, STR2, STR3 FROM TABLE1" that works fine but if your SQL statement is a call to a stored procedure returning a cursor each row fetching need a roudtrip.
    To avoid this problem you need to use the method "setDataBuffer" from the object "ResultSet" for each column of your cursor. It's easy to use with INT type and STRING type, a lit bit more complex with DATE type. But until now, I'm not able to do the same thing with REF type.
    Below a sample with STRING TYPE (It's assuming that the cursor return only one column of STRING type):
    try
      l_Statement = m_Connection->createStatement("BEGIN :1 := PACKAGE1.GetCursor1(:2); END;");
      l_Statement->registerOutParam(1, oracle::occi::OCCINUMBER, sizeof(l_CodeErreur));
      l_Statement->registerOutParam(2, oracle::occi::OCCICURSOR);
      l_Statement->executeQuery();
      l_CodeErreur = l_Statement->getNumber(1);
      if ((int) l_CodeErreur     == 0)
        char                         l_ArrayName[5][256];
        ub2                          l_ArrayNameSize[5];
        l_ResultSet  = l_Statement->getCursor(2);
        l_ResultSet->setDataBuffer(1, l_ArrayName,   OCCI_SQLT_STR, sizeof(l_ArrayName[0]),   l_ArrayNameSize,   NULL, NULL);
        while (l_ResultSet->next(5))
          for (int i = 0; i < l_ResultSet->getNumArrayRows(); i++)
            l_Name = CString(l_ArrayName);
    l_Statement->closeResultSet(l_ResultSet);
    m_Connection->terminateStatement(l_Statement);
    catch (SQLException &p_SQLException)
    I hope that sample help you.
    Regards                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • 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.

  • Select clause with where part is needs 600 times longer to complete

    Hello.
    I have two select clauses one with where, which needs 120 seconds to complete and one without where, which completes in 0,3 seconds. I want to know why is that.
    120 seconds
    SELECT B.* FROM
    (SELECT A.OLOG, MCL_ISPROTOCOLALLOWED('LMOD', 'MCLI', A.OPRG) ALLOWED FROM  (SELECT DISTINCT OLOG, OPRG FROM FLOG WHERE FIRM = '001') A) B WHERE B.ALLOWED = '1' ORDER BY OLOG;0,3 seconds
    SELECT B.* FROM
    (SELECT A.OLOG, MCL_ISPROTOCOLALLOWED('LMOD', 'MCLI', A.OPRG) ALLOWED FROM  (SELECT DISTINCT OLOG, OPRG FROM FLOG WHERE FIRM = '001') A) B ORDER BY OLOG;Table FLOG has arround 270000 records, but only 40 of them are distinct.
    IsProtocolAllowed checks if user has a permision to view the record.
    Thank you for your help.
    Regards,
    Borut Ojcinger
    Edited by: 993896 on 14.3.2013 7:24

    Hi,
    welcome to the forum.
    Please read SQL and PL/SQL FAQ
    If you have a performance issue have a look at SQL and PL/SQL FAQ
    Additionally when you put some code or output please enclose it between two lines starting with {noformat}{noformat}
    i.e.:
    {noformat}{noformat}
    SELECT ...
    {noformat}{noformat}
    Regards.
    Al                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Ref cursors - 'with' clause

    I am working with a procedure which is returning a ref-cursor to a Java Call. Inside the procedure I see a statment like
    Open t_results for
    with rfq_companies AS
    select statement1),
    rfq_hierarchies AS
    select statement2),
    rfq_relnhierarchies AS
    select statement 3);
    Can anybody explain such an usage for opening a ref cursor ('WITH' clause)?. What is the effect of using this and how Java will interpret this?

    The procedure is still returning a REF CURSOR, regardless of the way the SELECT statements is created. There is no effect as far as Java is concerned.
    Read more on the WITH clause:
    http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/statements_10002.htm#sthref9697
    in the section: Subquery Factoring

  • 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.

  • 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

  • For update cursor with nowait

    I have a 'for update' cursor defined with 'NOWAIT'. When soem of teh records that are supposed to be fetched by teh cursor are locked by another user for update..teh pl?SQL script returns
    "ORA-00054: resource busy and acquire with NOWAIT specified" error.
    If I declare teh cursor with out 'FOR UPDATE' or did NOT put 'NOWAIT' clause, teh script hangs waiting for teh records to be unlocked.
    If the user opens a record in the front end (web app) and does not close it.. i can not run the script. Is theer any way to ignore those records that are locked by other users and query only ones that are available as part of the select statement in the cursor.

    Optimistic locking implies, essentailly, that you never lock the row. Instead, if you want to update the row, you check all the other columns of the row to see whether they have changed. In other words, you'd do a straight SELECT here and then when you went to UPDATE the data, you'd do
    UPDATE <<change some column>>
    WHERE col1=<<old col1 value>>
       AND col2=<<old col2 value>>
       AND ...If the update changed 1 row, you're set. If it changed 0 rows, someone had changed the underlying row since you SELECTED it, so you'd have to handle that condition. If it returned an error indicating that someone else had locked the row, you could handle that situation as well. If you just continue on, however, be sure that you know how to identify that this row wasn't updated so you can try to do the update the next time (assuming that makes sense).
    If all your applications take the optimistic locking approach, you're pretty much guaranteed that no one else will have teh row locked, so you don't have to handle that state nearly as robustly.
    Justin
    Distributed Database Consulting, Inc.
    www.ddbcinc.com

Maybe you are looking for

  • How to get the Sent Mail in Sent Item box of Outlook?

    Hello Experts, I am using the FM SO_DOCUMENT_SEND_API1 for sending the Email from Program. Everything is working fine. My Question is How do I get the Sent Copy of Email in Outlook Sent Item Box?? Please suggest. Thanks & Regards Jagesh

  • Row to column comma seperated

    CREATE TABLE Colors Color VARCHAR(32) INSERT into Colors SELECT 'red' from dual INSERT into Colors SELECT 'orange' from dual INSERT into Colors SELECT 'blue' from dual INSERT into Colors SELECT 'green' from dual Can i do this with out any cursor or l

  • Material Group Difference MM03  (Table MARA) and Reservation (Table RESB)

    Why material group at T-code MM03 (MARA-MATKL) difference at Table RESB ?         Table MARA-MATKL = 04         Table RESB-MATKL = 02 I checking  MM03 not change about material group. I don't know some T-code can change material group link to table R

  • What PDF export settings to use for highest possible resolution printing?

    I use indesign to create a roughly 68-page marketing booklet. The document is landscape and setup to print on 8.5" x 11" as a landscape book with facing-pages. I upload a PDF to a professional printing company to print a full bleed booklet. The book

  • My iMac Intel shuts off by itself and restarts

    Hello, This mac seems to sort of shut off on it's own. It doesn't completely turn off though. It doesn't really go through the boot process... it just goes back on as if it were sleeping. Unfortunately, it does it while I'm working on it. I could be