Dynamic FROM clause

Hi, I am needing to use a dynamic "<font color="blue">FROM (insert table name here)</font>" as well. From reading several posts, it seems like I need to do this using dynamic SQL. I can pass the name of the table into the stored procedure, but I am getting confused as to how to turn the SELECT statement part of this function into dynamic SQL since the SELECT statement is already inside a cursor itself. Thank you -
<br><br><b>FUNCTION getDni4wImmStartInterface(p_board_group_id NUMBER)   RETURN interface_cnt_tbl PIPELINED
IS
--fill the cursor with available interfaces for the board_group_id passed in
CURSOR gc_intf IS
   SELECT interface
   FROM TABLE(ipfinterfaces.getinterfaceslist(p_board_group_id))
   WHERE interface NOT IN (SELECT interface FROM physical_interface WHERE board_group_id = p_board_group_id);
l_count NUMBER(10);
l_max   NUMBER(10);
BEGIN
--fetch the max # of interfaces allowed for the board group type
--passed in
SELECT bgt.max_interfaces
INTO l_max
FROM board_group_type bgt, board_groups bg
WHERE bg.board_group_id = p_board_group_id
AND bg.board_group_type_id = bgt.board_group_type_id;
--for interface in the cursor, check to see if there is an interface
--with the same C-S-G in the database that is 1 greater than the one in the cursor
FOR gc_rec IN gc_intf LOOP
SELECT count(*)
INTO l_count
"<font color="blue">FROM INT_DNI_4W_IMM c</font>
  , VIRTUAL_INTERFACE vi
  , BOARD_GROUPS bg
  , PHYSICAL_INTERFACE  pi
  , BOARD b
  WHERE b.BOARD_ID = bg.BOARD_ID
  AND b.SYSTEM_ID = vi.SYSTEM_ID
  AND vi.PHYSICAL_INTERFACE_ID = pi.PHYSICAL_INTERFACE_ID
  AND pi.SYSTEM_ID =  vi. SYSTEM_ID
  AND pi.BOARD_GROUP_ID = bg.BOARD_GROUP_ID
  AND vi.SYSTEM_ID =  bg.SYSTEM_ID
  AND c.VIRTUAL_INTERFACE_ID = vi.VIRTUAL_INTERFACE_ID
  AND bg.BOARD_GROUP_ID = p_board_group_id
  AND pi.Interface = TO_NUMBER(gc_rec.Interface) + 1;
--if there is not interface 1 greater than the one passed in, and if
--the interface passed in is not the max interface, pipe the row back.
     IF l_count = 0 AND (TO_NUMBER(gc_rec.interface) != l_max)
       THEN PIPE ROW (interface_cnt_obj (TO_NUMBER(gc_rec.interface), TO_NUMBER(l_count)));
     END IF;
END LOOP;
RETURN;
END getDni4wImmStartInterface;
</b>

Hi Vikas,
Sorry, I didn't think I could assign p_table_name to l_table_name like that. When I try to implement your suggestion, I get these errors (Is my DECLARE out of place?):<br><br>
Line # = 469 Column # = 1 Error Text = PLS-00103: Encountered the symbol "DECLARE" when expecting one of the following: begin function package pragma procedure subtype type use <an identifier> <a double-quoted delimited-identifier> form current cursor The symbol "begin" was substituted for "DECLARE" to continue. <br><br>
Line # = 474 Column # = 14 Error Text = PLS-00103: Encountered the symbol "=" when expecting one of the following: constant exception <an identifier> <a double-quoted delimited-identifier> table LONG_ double ref char time timestamp interval date binary national character nchar The symbol "<an identifier>" was substituted for "=" to continue.
<br><br>
Line # = 491 Column # = 51 Error Text = PLS-00103: Encountered the symbol "C" when expecting one of the following: * & = - + ; < / > at in is mod remainder not rem <an exponent (**)> <> or != or ~= >= <= <> and or like LIKE2_ LIKE4_ LIKEC_ between || multiset member SUBMULTISET_
<br><br>
Line # = 496 Column # = 3 Error Text = PLS-00103: Encountered the symbol "WHERE" when expecting one of the following: , from into bulk
<br><br>
Line # = 503 Column # = 27 Error Text = PLS-00049: bad bind variable 'B1'
<br><br>
Line # = 506 Column # = 3 Error Text = PLS-00103: Encountered the symbol "EXECUTE"
<br><br>
Here's my current code:<br><br><b>FUNCTION getDni4wImmStartInterface(p_board_group_id NUMBER, p_table_name VARCHAR2)   RETURN interface_cnt_tbl PIPELINED
IS
--fill the cursor with available interfaces for the board_group_id passed in
CURSOR gc_intf IS
   SELECT interface
   FROM TABLE(ipfinterfaces.getinterfaceslist(p_board_group_id))
   WHERE interface NOT IN (SELECT interface FROM physical_interface WHERE board_group_id = p_board_group_id);
DECLARE
l_count NUMBER(10);
l_max   NUMBER(10);
l_sql   LONG;
l_count NUMBER;
l_table_name := p_table_name;
BEGIN
--fetch the max # of interfaces allowed for the board group type
--passed in
SELECT bgt.max_interfaces
INTO l_max
FROM board_group_type bgt, board_groups bg
WHERE bg.board_group_id = p_board_group_id
AND bg.board_group_type_id = bgt.board_group_type_id;
--for interface in the cursor, check to see if there is an interface
--with the same C-S-G in the database that is 1 greater than the one in the cursor
FOR gc_rec IN gc_intf LOOP
l_sql := 'SELECT count(*) FROM ||l_table_name||' c
  , VIRTUAL_INTERFACE vi
  , BOARD_GROUPS bg
  , PHYSICAL_INTERFACE  pi
  , BOARD b
  WHERE b.BOARD_ID = bg.BOARD_ID
  AND b.SYSTEM_ID = vi.SYSTEM_ID
  AND vi.PHYSICAL_INTERFACE_ID = pi.PHYSICAL_INTERFACE_ID
  AND pi.SYSTEM_ID =  vi. SYSTEM_ID
  AND pi.BOARD_GROUP_ID = bg.BOARD_GROUP_ID
  AND vi.SYSTEM_ID =  bg.SYSTEM_ID
  AND c.VIRTUAL_INTERFACE_ID = vi.VIRTUAL_INTERFACE_ID
  AND bg.BOARD_GROUP_ID = :b1
  AND pi.Interface = TO_NUMBER(gc_rec.Interface) + 1;
  EXECUTE IMMEDIATE l_sql INTO l_count USING p_board_group_id;
<br><br></b>Message was edited by:
The Fabulous LB

Similar Messages

  • SQL Dev Child Reports - Dynamic From Clause Possible?

    Hi All,
    Trying to figure out this problem:
    Master Report SQL:
    select TABLE_NAME from USER_TAB_COLS where COLUMN_NAME = 'CREATION_DATE'
    Results with some table names. Now I want to use the table name to formulate my child query
    Child SQL:
    select * from :TABLE_NAME where CREATION_DATE >= SYSDATE-7
    or whatever.....but I want to somehow use the table_name dynamically.
    Thanks!
    -Brent

    I doubt that you can get dynamic from clause for Child Report if its style is table.
    But you can get dynamic one in child with style script:
    Say you have :
    Master report for list tables which select owner and table name by some condition (I omit this):
    SQL :     select owner, table_name from all_tables ..So Child Report
    SQL is follow:
        COLUMN TN NEW_VALUE TNAME ;
        select :OWNER||'.'||:TABLE_NAME as TN  from dual;
        select '&&TNAME' as tab_NAME, count(1) from &&TNAME;Hope it help.
    Edited by: K_Serge on Jan 5, 2013 5:10 AM
    Edited by: K_Serge on Jan 5, 2013 5:20 AM

  • Need help with writing a query with dynamic FROM clause

    Hi Folks,
    I need help with an query that should generate the "FROM" clause dynamically.
    My main query is as follows
    select DT_SKEY, count(*)
    from *???*
    where DT_SKEY between 20110601 and 20110719
    group by DT_SKEY
    having count(*) = 0
    order by 1; The "from" clause of the above query should be generated as below
    select 'Schema_Name'||'.'||TABLE_NAME
    from dba_tables
    where OWNER = 'Schema_Name'Simply sticking the later query in the first query does not work.
    Any pointers will be appreciated.
    Thanks
    rogers42

    Hi,
    rogers42 wrote:
    Hi Folks,
    I need help with an query that should generate the "FROM" clause dynamically.
    My main query is as follows
    select DT_SKEY, count(*)
    from *???*
    where DT_SKEY between 20110601 and 20110719
    group by DT_SKEY
    having count(*) = 0
    order by 1; The "from" clause of the above query should be generated as below
    select 'Schema_Name'||'.'||TABLE_NAME
    from dba_tables
    where OWNER = 'Schema_Name'
    Remember that anything inside quotes is case-sensitive. Is the owner really "Schema_Name" with a capital S and a capital N, and 8 lower-case letters?
    Simply sticking the later query in the first query does not work.Right; the table name must be given when you compile the query. It's not an expression that you can generate in the query itself.
    Any pointers will be appreciated.In SQL*Plus, you can do something like the query bleow.
    Say you want to count the rows in scott.emp, but you're not certain that the name is emp; it could be emp_2011 or emp_august, or anything else that starts with e. (And the name could change every day, so you can't just look it up now and hard-code it in a query that you want to run in the future.)
    Typically, how dynamic SQL works is that some code (such as a preliminary query) gets some of the information you need to write the query first, and you use that information in a SQL statement that is compiled and run after that. For example:
    -- Preliminary Query:
    COLUMN     my_table_name_col     NEW_VALUE my_table_name
    SELECT     table_name     AS my_table_name_col
    FROM     all_tables
    WHERE     owner          = 'SCOTT'
    AND     table_name     LIKE 'E%';
    -- Main Query:
    SELECT     COUNT (*)     AS cnt
    FROM     scott.&my_table_name
    ;This assumes that the preliminary query will find exactly one row; that is, it assumes that SCOTT has exactly one table whose name starts with E. Could you have 0 tables in the schema, or more than 1? If so, what results would you want? Give a concrete example, preferably suing commonly available tables (like those in the SCOTT schema) so that the poepl who want to help you can re-create the problem and test their ideas.
    Edited by: Frank Kulash on Aug 11, 2011 2:30 PM

  • How to programmatically count from a dynamic from clause ?

    Hi all,
    My report contains a user-parameter , say :from_clause, which will receive the from clause of a query from a forms application. We can have for example :from_clause = "from t_table where column_1 = value_1 order by column_2". The "from" keeword is included in the parameter value. In the before report trigger I want to make a count based on that from clause. How to achieve this goal ?
    Thank you very much indeed.

    Hi,
    It won't work. You need a control flow case, unless you want to use a hack (internal API) with OutcomeUtils.getActivityRequestOutcome(activityId).
    FacesContext context = FacesContext.getCurrentInstance();
    NavigationHandler handler = context.getApplication().getNavigationHandler();
    handler.handleNavigation(context, null, OutcomeUtils.getActivityRequestOutcome("YourViewId"));
    context.renderResponse();Regards,
    ~ Simon

  • Dynamic 'from' Clause in Native SQL

    Hi All,
    While running a select query in ORACLE, we can put the table name in '<i>from</i>' clause at the runtime-Seletion Screen Parameter .
    But I am not able to do so in SAP using Native Sql. Does SAP has any  restrictions regarding this?
    It might be possible that ,by using Embedded SQL (C/C++ precompiler ),we may be able to achive this.
    Can any body please throw light on this.
    Its Urgent.
    Thanks in Advance.
    Regards,
    Gaurav

    Hi
    <u>Assuming you can also use Open SQL.</u>
    Macroman's suggestion is OK.  in Open SQL (this is SQL of ABAP platform) but a query statement can be constituted using some dynamic clauses. Although macro coding has some restrictions it will be less time consuming using it than a dynamic query.
    <u>An example SELECT statement with dynamic clauses:</u>
    SELECT (fields) FROM (table_name_variable)
    INTO <target_fields>
    WHERE (conditions_tab) .
    For more information:
    <a href="http://help.sap.com/saphelp_47x200/helpdata/en/fc/eb3983358411d1829f0000e829fbfe/frameset.htm">Open SQL -Reading Data</a>
    *--Serdar

  • Create view with dynamic from-clause

    Dear all,
    you might have some ideas to help me out of my issue that i just "created myself" ;-)
    i have a unknown and non-constant amount of tables using the the same table-structure and i do have a master table
    that contains all names of these kind of tables. I now want to create a single view that contains all columns of each table
    and an additional column name containing the name of the corresponding table.
    I found a solution for this but only if I knew all table names while creating my view.
    Here's what I currently have:
    master_table:
    ID TABLENAME
    1 table_01
    2 table_02
    table_01:
    ID NAME
    1 eins
    2 zwei
    3 drei
    table_02:
    ID NAME
    1 one
    2 two
    3 three
    my view "tab1tab2" on these 2 table looks like this:
    ID NAME TABLENAME
    1 eins table_01
    2 zwei table_01
    3 drei table_01
    1 one table_02
    2 two table_02
    3 three table_02
    i achieved this view by using:
    CREATE OR REPLACE VIEW TAB1TAB2 ("ID", "NAME", "TABLENAME")
    AS
    SELECT id,name, 'table_01' AS tablename FROM table_01
    UNION
    SELECT id,name, 'table_02' AS tablename FROM table_02;
    Is there a way to create as many select and union statements as i do have entries (tablenames) in my master_table to achive the same results as my hardcoded view ?
    Many thanks in advance for your help
    Best regards
    majo

    Is there a way to create as many select and union statements as i do have entries (tablenames) in my master_table to achive the same results as my hardcoded view ?You can achieve this also with some xml facilities as e.g. in
    SQL> create table t1 as select empno, ename from emp where rownum <= 3
    Table created.
    SQL> create table t2 as select deptno empno, dname ename from dept
    Table created.
    SQL> create table master as (select 1 id, 't1' table_name from dual union all
                                       select 2 id, 't2' table_name from dual)
    Table created.
    SQL> create or replace view v_t
    as
    select table_name, x.*
      from (select table_name, 'ora:view("' || table_name || '")' tabs from master),
           xmltable (tabs columns id int path 'EMPNO', ename varchar2(20) path 'ENAME') x
    View created.
    SQL> select * from v_t
    TABLE_NAME              ID ENAME              
    t1                    7369 SMITH              
    t1                    7499 ALLEN              
    t1                    7521 WARD               
    t2                      10 ACCOUNTING         
    t2                      20 RESEARCH           
    t2                      30 SALES              
    t2                      40 OPERATIONS         
    t2                      50 SALES              
    8 rows selected.
    SQL> create table t3 as select object_id empno, object_name ename from user_objects where rownum <= 3
    Table created.
    SQL> insert into master values (3, 't3')
    1 row created.
    SQL> select * from v_t
    TABLE_NAME              ID ENAME              
    t1                    7369 SMITH              
    t1                    7499 ALLEN              
    t1                    7521 WARD               
    t2                      10 ACCOUNTING         
    t2                      20 RESEARCH           
    t2                      30 SALES              
    t2                      40 OPERATIONS         
    t2                      50 SALES              
    t3                  187449 ABC                
    t3                  187448 ADDRESSES_EXT_TAB  
    t3                  187446 ADDRESSES_EXT_TYP  
    11 rows selected.Note: above will work only in 11g.

  • From Clause query with form variables

    forms 9.0.4 rdbms 9.2
    Is it possible to create a From Clause query with form variables generated from another block (but in the same form)? I am not having any success.
    I searched Metalink. It appears that according to DOC ID # 69884.1, in Forms 6i, this is not possible. Metalink suggest in DOC ID 104771.1 implementating a dynamic From Clause, but when I duplicate the example on my system, I receive an Oracle error. Further investigation from the web form (DISPLAY ERROR) indicates that the system does not see the dynamic value.
    Has anyone else run into this error? Has this been fixed in forms 9.0.4 and I am just missing something? Does a dynamic from clause query work? Can anyone point me to an example or post an example or offer any advise.
    thanks in advance

    As far as I know it is not possible to use block items in a from clause query in forms 9.0.4. Here is my solution for a From-Clause-Query via the 'Query-Data-Source-Name-Property':
    To use the values of the block items in my from clause query I implemented a database package with getter and setter routines for the block item values I needed for the query.
    In the Key-Exeqry-Trigger of the From-Clause-Query-Block I set the global package variables with values of the block-items I am interested in. In the From-Clause-Query I used the values in the where-clause via package functions which return the global package variables.
    Hope my solution will work for your problem.

  • Is there a way to use dynamic built string in the "from" clause

    Hi all, im having one problem and now, im not sure how to solve it easily at all... :) Is there someone that would be so kind and put a eye on it? ..thx
    I have plsql proc, in which i have a list of table_names. For each of that table i need to run a query that will retrieve me a list of values and for each of that value i need to do something.
    If i can be more specific about the problem -> each of that table is built as key_column, value_columns, day,starttime. For a key per table there are 4 records per hour - every quarter. Im truncating those quarters to full-quarter (minutes => 0->14 = 0min; 15->29 = 15min, 30->44 = 30, 45->59=45)
    example
    i get for one key and specific hour four records at 15:01;15:16;15:31;15:46 => i truncate em to 15:00;15:15;15:30;15:45..Sometimes there is a problem with the tool that is generating those data for me, and one quarter could be moved a little - so i get data like 15:01;15:16;15:29;15:46 => after i truncate the times i get duplicates in second quarter. It also can happen like this : 23:00; 23:14; 23:29; 23:44; 23:59 => totaly bad => cos the last one supposed to be as 0:00 next day, ..and 23:14 as 23:15...So...that was a problem - and solution -> i wanted to create plsql that will find those hours in each table i ve defined, and for each problem hour i make some fixes - update the bad time ...
    ..and i have problem - can i put an dynamic built table_name in the "from" clause?
    example how i wanted to do that:
    declare
         type t_objectName     is table of varchar2(030) index     by pls_integer;
         l_tableName              t_objectName;
    begin
    l_tableName(1) := 'tmphlrgl';
    l_tableName(2) := 'tmprcfgl';
    l_tableName(3) := 'tmprcfbs';
    l_tableName(4) := 'tmpvlrgl';
    for i in (select evtime from (select day,trunc_quarter(evtime) evtime,m_id from l_tableName(i) group by day,trunc_quarter(evtime),m_id having count(*)>1) order by evtime) loop
    --some other conditions and the update...
    end loop;
    end;
    /I cannot use the l_tableName(i) for FROM ...get an error...I was thinking to build it as dynamic sql and execute immediate into some kind of object that can store mutliple lines, from which i would in the FOR cycle get the data...But im not sure if this could be done in plsql...
    thanks for your time and help..
    d.

    declare
    c sys_refcursor;
    begin
    for i in 1..4 loop
    open c for 'day,trunc_quarter(evtime) evtime,m_id
    from ' || l_tableName(i) ||
    'group by day,trunc_quarter(evtime),m_id having
    count(*)>1) order by evtime';Just to high light SELECT is missing that all
    OPEN c FOR ' SELECT day,trunc_quarter(evtime) evtime,m_id
              FROM' || l_tableName(i) ||
    'GROUP BY day,trunc_quarter(evtime),m_id  HAVING  count(*)>1)   ORDER BY evtime';

  • How to escape a single quotes from a string of dynamic sql clause?

    if a single quotes exist in a dynamic sql clause for a string,
    like
    v_string :='select tname from tab where tabtype='table'',
    there tabtype='table' will conflict with the single quote ahead.
    could somebody tell me how to escape this single quotes?
    thanks for your tips,
    frederick

    fredrick,
    To represent one single quotation mark within a literal, enter two single quotation marks. For example :
    v_string :='select tname from tab where tabtype=''table'''
    Regards,
    Srinivas

  • I want to use a dynamic schema name in the from clause but its not working.

    DECLARE
         vblQueryName VARCHAR2(20);
         vblSchemaName VARCHAR2(20);
    BEGIN
         SELECT CurrentSchemaName INTO vblSchemaName FROM HR_989_SCHEMA;
         vblQueryName:='060_525_020';
         INSERT /*+ APPEND(HP_ELIGIBILITIES,4) */ INTO HP_ELIGIBILITIES
              LVL1ID,
              LVL1Desc,
              LVL2ID,
              LVL2Desc,
              LVL3ID,
              LVL3Desc,
              LVL4ID,
              LVL4Desc
         SELECT /*+ PARALLEL(a,4) */
              LVL1ID,
              LVL1Desc,
              LVL2ID,
              LVL2Desc,
              LVL3ID,
              LVL3Desc,
              LVL4ID,
              LVL4Desc
         FROM
         bold     vblSchemaName.HP_ELIGIBILITIES a
         WHERE
              UPPER(LVL2ID) = 'XX' ;
         COMMIT;
    DBMS_OUTPUT.PUT_LINE( 'Query Executed: ' || vblqueryName);
    INSERT INTO HP_QUERYEXECLOG(QueryName) VALUES(vblQueryName);
    EXCEPTION WHEN NO_DATA_FOUND THEN NULL;
    END;
    I want to create a rules table so that the schema name in front of the table name in the from clause can be controlled by a separate table that is maintained but its not working . Help and your valuable inputs needed for this issue

    I want to use a dynamic schema name in the from clauseyou can alternatively set the current schema as e.g. in:
    declare
       vblqueryname    varchar2 (20);
       vblschemaname   varchar2 (20);
    begin
       select currentschemaname into vblschemaname from hr_989_schema;
       vblqueryname := '060_525_020';
       execute immediate 'alter session set current_schema=' || vblschemaname;
       insert /*+ APPEND(HP_ELIGIBILITIES,4) */
             into hp_eligibilities (lvl1id,
                                    lvl1desc,
                                    lvl2id,
                                    lvl2desc,
                                    lvl3id,
                                    lvl3desc,
                                    lvl4id,
                                    lvl4desc
          select /*+ PARALLEL(a,4) */
                lvl1id,
                 lvl1desc,
                 lvl2id,
                 lvl2desc,
                 lvl3id,
                 lvl3desc,
                 lvl4id,
                 lvl4desc
            from hp_eligibilities a
           where upper (lvl2id) = 'XX';
       commit;
       dbms_output.put_line ('Query Executed: ' || vblqueryname);
       insert into hp_queryexeclog (queryname)
       values (vblqueryname);
    exception
       when no_data_found
       then
          null;
    end;

  • How to set dynamic WHERE clause to VO from backingBean?

    Hi,
    Can any one let me know the best way to add the dynamic WHERE clause in to VO query.
    I have created AM (with AMImpl.java) & VO (with VOImpl.java & VORowImpl.java) in my model project. I suppose to set the WHERE condition at runtime while the user click the search button. I am handling the user button click at UI layer backingBean. From the backing bean I could able to get the objct of the VO and set the where clause by below code.
            ValueExpression valueExp = elFactory.createValueExpression(elContext, "#{bindings.UserSearchVO1Iterator}", Object.class);
            DCIteratorBinding dcIter = (DCIteratorBinding)valueExp.getValue(elContext);
            ViewObject userSearchVO = dcIter.getViewObject();
            userSearchVO.setWhereClause("lower(usr_login) LIKE ':1' and usr_udf_suid like ':2' ");
            userSearchVO.executeQuery();But as I fear this is not the right way to do it. So I am creating the cutom method inside the VOImpl.java and triggring that method by creating one more cutom method in AMImpl.java. But I dont know how to invoke this AM method from backingBean.
    AMImpl method
    public void initDetails()
            UserSearchVOImpl vo = getUserSearchVO1();
            vo.initQuery();
    VOImpl method
        public void initQuery()
            setWhereClause("lower(usr_login) LIKE 'a%' and usr_udf_suid like '%1144%'");
            executeQuery();
        }Can any one guide me which is the best way to set the where clause to VO? How to call the AM method from backingBean?
    Thanks
    kln

    i am new to oracle 11g i writing a stored procedure in which i have made use of case in where clause to pass my parameter value v_toStoreID
    i have googled a lot regarding that i found that to use case in where clause it should be like this
    where
    case  column_value
    when 0
    then value1
    else
    value2
    end
    this my query
    SELECT ITMID as ItemId,
    NVL(OrderDtl.PackageID, 0) PackageId,
    OrderDtl.OrdDtlID,
    (CASE NVL(OrderDtl.PackageID, 0)
    WHEN 0
    THEN 1
    ELSE 0
    END) as PackageFlag,
    ivitem.Code ItemCode,
    ivitem.ITMNAME AS itemName,
    IvPatientIssueMst.IssueNo Issue_No,
    to_char(Issuedate, 'DD/MM/YYYY') IssueDate,
    OrderDtl.OrdQty,
    NVL(OrderDtl.AllocationID, 0) Package,
    OrderDtl.ServiceAmount MRP
    FROM IvPatientIssueMst
    JOIN OrderMst
    ON IvPatientIssueMst.OrderId = OrderMst.OrdId
    JOIN OrderDtl
    ON OrderDtl.OrdID = OrderMst.OrdId
    JOIN ivitem
    ON ivitem.ITMID = OrderDtl.DrugId
    LEFT JOIN IVPatientIndentMst
    ON IVPatientIndentMst.IndentID = IvPatientIssueMst.IndentId
    WHERE OrderMst.OrdVisitID = 395899
    AND
    *(CASE IvPatientIssueMst.StoreId*
    when NVL(IvPatientIssueMst.StoreId, 0)=0
    THEN v_toStoreID
    ELSE  IVPatientIndentMst.ToStoreID
    END)
    ORDER BY ivitem.ITMNAME;
    it is not working please someone help

  • Dynamic Where clause - from third party system

    I have internal table A with fields I am getting from legacy system
    field1
    field2
    field3
    field4
    fieldn
    and i am getting a condition table (Where clause conditions) from a legacy system thru an RFC call.
    and in the RFC i need to delete records from internal table A using this where clause
    and where clause condition table(is 72 char length single field table) from legacy system looks like the following
             ( FIELD1                          BETWEEN '01' AND '05' ) AND
         FIELD1                         NE '06'
         AND ( FIELD4                     EQ 'BU' )
         AND ( FIELD5                      BETWEEN '001' AND '009' )
    How could i delete entries from internal table A using this where clause conditon table mentioned above

    Hi a®s,
    yes, thats what I thought of: Generate subroutine Pool.
    I did not elaborate on the fact that dynamic where clauses are allowed only for database selections. That means that FUNCTION 'FREE_SELECTIONS_WHERE_2_RANGE' can't be used either.
    But if you generate a subroutine, you can generate TYPE and DATA declarations as well. This gives you the ability to have static where condition for the DELETE itab WHERE statement.
    If the type vaies during runtime, the generation may vary too.
    I think you are able to do the coding for this.
    On the other hand, Thomas' 'slick' proposal using a temporary database table and a subsequent SELECT ... WHERE (<dynamic where clause) may be easier to implement.
    BTW: Are ther release notes on ABAP720?
    Regards,
    Clemens

  • How to change tables in from  clause dynamically

    Hi,
    I have to add some join conditions in where clause and tables in from clause based on some input parameters and data in other tables.
    How can i achieve this ? I must use procedure/function or dynamic query preparation or any more alternatives?
    Regards,
    Krishna

    Yes, you can use dynamic sql for that.
    But be aware that you'll be needing to concatenate the table names in your FROM-clause, you cannot bind them...
    So you'll be trashing the shared pool.
    Maybe alternative approaches are possible, but you provide too little input for my crystal ball here...

  • Need to know the column names in my dynamic select clause

    Dear All,
    Please go through the following code. While executing the following code i am getting an error saying that dbms_sql.describe_columns overflow, col_name_len=35. Use describe_columns2.
    Please guide me how to proceed further. Or please help me, how can i get the column names when i issue a dynamic select clause.
    DECLARE
    CUR INTEGER;
    COL_CNT INTEGER ;
    A INTEGER;
    SEL_CLAUSE VARCHAR2(2000);
    DESC_T DBMS_SQL.DESC_TAB;
    REC DBMS_SQL.DESC_REC;
    b number;
    BEGIN
    SEL_CLAUSE := 'SELECT 1,2,DECODE(1,1,''ONE'',2,''TWO'',3,''THREE'') FROM DUAL';
    --'SELECT ROWID,PARA_SUB_CODE,DECODE('||''''||'ENG'||''''||','||''''||'ENG'||''''||',PARA_NAME,PARA_BL_NAME),NULL,NULL FROM PCOM_APP_PARAMETER';
    --'SELECT 1,2,DECODE(1,1,''ONE'',2,''TWO'') FROM DUAL';
    DBMS_OUTPUT.PUT_LINE( SEL_CLAUSE );
    CUR := DBMS_SQL.OPEN_CURSOR;
    DBMS_SQL.PARSE(CUR,SEL_CLAUSE,DBMS_SQL.NATIVE);
    DBMS_SQL.DESCRIBE_COLUMNS(CUR,COL_CNT,DESC_T);
    B := desc_t.first;
    FOR J IN 1..COL_CNT
    LOOP
    DBMS_OUTPUT.PUT_LINE('J := '||J || ' COL CNT ' || COL_CNT);
    END LOOP;
    BEGIN
    A := DBMS_SQL.EXECUTE(CUR);
    EXCEPTION
    WHEN OTHERS THEN
    NULL;
    END;
    END;
    Regards,
    Balaji

    Is there any way can i have it directly??It does not work with static SQL either. Dynamic SQL is no different.
    SQL> select 1 x from dual where x = 1 ;
    select 1 x from dual where x = 1
    ERROR at line 1:
    ORA-00904: "X": invalid identifier
    SQL>As suggested already, you will need to use alias if you want your select expression to be referred in the where clause.
    SQL> BEGIN
      2      FOR rec IN (SELECT *
      3                  FROM   (SELECT 1,
      4                                 2,
      5                                 DECODE(1, 1, 'ONE', 2, 'TWO', 3, 'THREE') "DECODE(1, 1, 'ONE', 2, 'TWO', "
      6                          FROM   DUAL)
      7                  WHERE  "DECODE(1, 1, 'ONE', 2, 'TWO', " = 'ONE')
      8      LOOP
      9          NULL;
    10      END LOOP;
    11  END;
    12  /
    PL/SQL procedure successfully completed.
    SQL>Message was edited by:
    Kamal Kishore

  • Dynamic WHERE clause in SELECT statement

    Hi,
    I need to extract (SELECT) all the products in different salesorganizations. Since a product can be available in more than 1 salesorg I have created several properties in the PRODUCT dimension - 1 for each salesorganization (naming: Sxxxx where xxxx is the salesorganization number).
    Since I need to prefix the salesorganization property with an "S" I have created a property on the SALESORG dimension called SALESORG.
    Therefore I need to create a dynamic WHERE clause in the SELECT statement. Currently my script is:
    *SELECT(%SORG%, "[SALESORG]",SALESORG, [ID]=%SALESORG_SET%)
    *SELECT(%PROD%, "[ID]",PRODUCT, [%SORG%]="X")
    My first SELECT find the Sxxx (equal to the property I need in the PRODUCT dimension). My second SELECT uses the variable in the first SELCT statement to use the correct property for the WHERE clause.
    Unfortunately the code is not validated - any suggestions?
    /Lars

    Hi Lars,
    If you run it from a DM package without validating it, does it still work? I would bet it does.
    If this is the case I would open a message with SAP (it would be an enhancement request). Until they fix the validation code, you would just have to live with the script not validating.
    Cheers,
    Ethan

Maybe you are looking for

  • How to do two sided printing automatically with HP 7520 printer

    All that I am trying to do is to make my printer do two sided or double sided printing.  No matter what I check IT DOES NOT WORK.  I checked "2-sided, 1 to 2, NOTHING.  What amazes me is that this worked until recently and now it just will not do dou

  • "unable to start Dolby audio driver on windows 7"

    when i try to open Dolby Advanced audio it says _-"Unable to start the Dolby audio driver. Please restart the computer or reinstall the driver if the problem persists"-_ thats's what it says to me. now i do have the driver but it doesn't appear in th

  • MY ITUNES WONT CONNECT TO THE INTERNET!

    even though the internet is conected i cant get song info. i can right click on songs and press get info but it fails. i cant even connect to itunes store from itunes. basicly my itunes cannot conect to the internet. PLEASE HELP.

  • Outofmemory while creating a new object of file with size more than 100 MB

    I have created an application which generates a report by getting the data from our archived files (.zip file).By the time, the application is reaching a file with size more than 100 mb, it is running out fo memory while creating the object of that p

  • Problem with Snooze when two calendar event pop up

    When two calendar event pop up at the same time in  notification and you press snooze a couple of time on both of them. Eventualy one of them wont pop up again in notification.