Where condition on a function

Hello,
I'm having little troubles while writing a query for which is needed a where condition on a function.
Here a little example:
select id_vehicle from vehicle_list where id_user = 1 and function(id_vehicle) = 1;
that function is using locator (quite heavy).
as I would like to execute the function just for the id_user = 1 and not for the whole table (like it seemed it does in the privous query) I tried this second:
select id_vehicle from (select id_vehicle from vehicle_list where id_user = 1) where function(id_vehicle) = 1;
Nothing changed, neither the execution explain.
Finally I found this syntax, that works as I would:
select id_vehicle from vehicle_list where id_user = 1 group by id_vehicle having function(id_vehicle) = 1;
Is this the only solution to achieve my goal?
Thanks in advance,
Samuel Rabini

Karthick_Arp wrote:
Samuel Rabini wrote:
Hello,
I'm having little troubles while writing a query for which is needed a where condition on a function.
Here a little example:
select id_vehicle from vehicle_list where id_user = 1 and function(id_vehicle) = 1;
that function is using locator (quite heavy). Locator? I don't get you what is that? Probably some geo/spatial stuff.
>
as I would like to execute the function just for the id_user = 1 and not for the whole table (like it seemed it does in the privous query) I tried this second:
select id_vehicle from (select id_vehicle from vehicle_list where id_user = 1) where function(id_vehicle) = 1; For oracle both the query are the same. Search the document for predicate pushing and read it.
You are in a wrong assumption that the function is applied for all the row in the table. Its only applied on the rows for which id_user is 1. How to check it? just pas id_user as and parameter to the function and print it in the function. You will get to know that. not always. it depends on many factors. The CBO might decide that the condition with the function will return less values then the id_use=1 condition. Therefore it might choose to execute the function first. An execution plan including join predicates would also show this.
There are some ways to influence the optimizers behaviour regarding function. One is to make it deterministic (if possible). Also one could give addition info to the optimizer about the function. Dynamic sampling could also be helpful, altough I'm not so sure in this case.
I myself would prefer to write the query in such a way that the optimizer is forced to execute it as late as possible.
There are different ways how to do this.
Using a subquery and a sort operation (order by, group by ) is one. That's why it was working for the op. Problem is this additional sort operation has its own performance cost.
Using COALESCE can be another way. It might be difficult rewrite the query in this case. But coalesce is one of the few commands (or the only one?) where the second parameter is not executed if the first one is fulfilling the condition.
Last but not least you can use hints to prevent the subquery rewriting.

Similar Messages

  • Issue with Dynamic WHERE condition in Cursor in FUNCTION.

    Hi All,
    I am facing an issue with cursor having dynamic WHERE condition in a function.
    Below is the FUNCTION:
    CREATE OR REPLACE FUNCTION EXCEPTION_MERGE(TABLE_NAME IN VARCHAR2, TAB_NAME IN VARCHAR2)
    RETURN VARCHAr2
    IS
    stmt_tabcols VARCHAR2(32767);
    v_columnname VARCHAR2(32767);
    CURSOR C1 IS
    SELECT 'A.'||A.COLUMN_NAME ||' = '|| 'B.'||B.COLUMN_NAME COLUMN_NAME
    FROM
    SELECT COLUMN_ID, COLUMN_NAME
    FROM USER_TAB_COLUMNS
    WHERE TABLE_NAME  = TABLE_NAME
    AND COLUMN_NAME NOT IN ('ERROR_TAB_ID','ERROR_LOAD_DATE')
    ) A,
    SELECT COLUMN_ID, COLUMN_NAME
    FROM USER_TAB_COLUMNS
    WHERE TABLE_NAME = TAB_NAME
    ) B
    WHERE A.COLUMN_ID = B.COLUMN_ID;
    BEGIN
    FOR TABCOL IN C1
    LOOP
        stmt_tabcols := stmt_tabcols ||TABCOL.COLUMN_NAME||',';
    END LOOP;
        stmt_tabcols := RTRIM(stmt_tabcols, ',');
        RETURN stmt_tabcols;
    END;
    SELECT EXCEPTION_MERGE('WC_W_TEST_FS','WC_W_TEST_FS_GBL') FROM DUAL;It throws, below error:
    ORA-06502 : PL/SQL : Numeric or value error : character string buffer too smallIf I REPLACE TABLE_NAME and TAB_NAME with hard coded values , it works fine. Can somebody look at the code and let me know the issue.
    Edited by: ace_friends22 on Sep 9, 2012 1:08 PM

    Etbin neatly demonstrating the value of posting code in a manner which makes it easy to read.
    It's obviously an naming/scoping issue. Faced with a join like this:
    where table_name = table_namethe engine looks for something called table_name in the current scope. It finds it, a column on USER_TAB_COLUMNS and applies it to both sides of the filter. It has no way of knowing that there is also a parameter called TABLE_NAME, because that is outside its current scope. Consequently the query will join every table in your schema regardless of what values you pass, and that's why you blow the buffer.
    Takw etbin's advice and name your parameter with a prefix:
    where table_name = p_table_nameThis isn't a column in USER_TAB_COLUMNS which will force the engine to look in the next scope up, which in your case is the function, where it will find your parameter and so generate a query for the passed values only.
    Cheers, APC
    Edited by: APC on Sep 9, 2012 8:03 AM

  • Where clause won't propagate over dblink / function as where condition

    Hi there,
    I've here an rather complex problem with whom google couldn't help me.
    <h3>The Situation</h3>
    I've got two databases ( local db : oracle 10XE, remote db: non-oracle) which are connected via dblink. The connection works perfectly. On local db I want to execute this query:
    select sum(revenue), year, brand1
    from revenues@remote
    where cus_encryptData('MFGR#12', 'mykey') = category -- <--
    group by year, brand1
    order by year;whereas cus_encryptData(<str>, <str>) is user defined function which turns a plaintext into a ciphertext. This function can for security and technical reasons only reside on the local db. Here is the definition:
    create or replace function cus_encryptData2(plain varchar2, pw varchar2)
    return varchar2 deterministic PARALLEL_ENABLE is [...]<h3>The Problem</h3>
    This query works, although very slowly (because a lot of data has to exchanged between remote and local db). The execution plan suggests that the where condition is not propagated to the remote db. The only thing that happens on the remote db is the column select. But when I change the query to:
    select sum(revenue), year, brand1
    from revenues@remote
    where 'dLWEfksdaAWE321asDcASd2' = category --'dLWEfksdaAWE321asDcASd2' == cus_encryptData2('MFGR#12', 'mykey')
    group by year, brand1
    order by year;the where condition is propagated and everything works as it is supposed to (only the aggregation is done locally, but thats ok).
    <h3>The Question</h3>
    Does anybody know how to get oracle to just send the result of cus_encryptData to the remote db or rather to resolve the function first before sending it to the remote db? Moreover, the solution should be as simple as possible, i.e. if possible only standard SQL.
    Thanks a lot
    Chris

    user12047719 wrote:
    I've here an rather complex problem with whom google couldn't help me.A colleague ran into the exact same type of problem, dealing with a db-link to SQL-Server some weeks ago. I created a work-around for hm, but now I'm struggling to recall what it is... Sheez... it has been a long week and it is late Friday afternoon.. ;-)
    The basic issue was to get the local SQL parser to send the literal result (of the function) to the remote server to be parsed.
    If memory serves, I winded up using dynamic SQL. Not actually dynamic string SQL, but passing the value as a bind variable instead of using a function in the SQL statement.
    So instead of something line this:
    begin
      insert into local_table select * from remote_table@external_db where col1 = funkyFoo(123);
      ...Remove the function call and pass a bind variable instead:
    begin
      localVar := funkyFoo(123);
      insert into local_table select * from remote_table@external_db where col1 = localVar;
      ...I'm not sure why Oracle behaves like this. I would have expected the driving_site hint to basically do the same - resolve the local function and use the returned value as a bind variable value in the predicate for the remote SQL.. and I vaguely recall this working when I had to use a foreign database (via the Oracle Transparent Gateway for Informix). But it could have been that the Gateway s/w was more intelligent than the generic ODBC agent typically used today...

  • Convert WHERE condition to OBIEE using available OBIEE function

    I have this WHERE condition which has to be attached to a Logical Table Source (Content Tab). This condition exists in my BO Universe and has to be applied to my OBIEE project.
    TRUNC(SYSDATE) >= NVL(QP.QP_LIST_LINES.start_date_active, TRUNC(SYSDATE))
    AND TRUNC(SYSDATE) < NVL(QP.QP_LIST_LINES.end_date_active,TRUNC(SYSDATE)+1)
    Using the functions in OBIEE, I ended up with this WHERE condition but seems not to work because when I compared the results, they are different.
    CURRENT_DATE >= IFNULL(ABCDE."Price List Lines"."Item Start Date", CURRENT_DATE ) AND CURRENT_DATE < IFNULL(ABCDE."Price List Lines"."Item End Date", CURRENT_DATE + 1)
    Please help me correct this.
    Thank you in advance.
    Message was edited by:
    user595459

    Hi, The TIMESTAMPADD function helped. I will take note of this. It's now working but noticed the performance (generating the report) is taking a long time. Would appreciate your advice. Thanks.

  • WHERE condition in OBIEE 11g

    HI gurus,
                    How can I use a WHERE condition in obiee 11g in the Column formula or in the BMM layer in the repository .
    Thanks in advance
    Reg,
    Niv

    Hi,
    In the Column formula, the functions like Case When clause (Category: Expressions) can always be used in the building the expression.
    For the above, there is always two options
    1. Derived from Physical Mappings - this will list only the physical tables that are pulled into the LTS of the logical table
    2. Derived from existing columns using an expression - this will list all the Logical tables in the RPD
    If you want to apply the filter i.e where clause on the entire table, then go to Content Tab of the LTS
    Enter your WHERE clause filters in the section - Use this "WHERE clause".....
    The above modifications will apply where clause on all the columns
    Please mark if it is helpful
    Srikanth

  • Where condition for a column in BMM

    Hi Gurus,
    I have a requirement where in the BMM(The LTS for this logical table is say 'Fact'), I need a logical column with the following definition.
    count(Dim.status) where Dim.status = ' Accepted' (I didnt add the Dim table to the LTS yet, should I?)
    I know that we can do a count(Dim.status) in the column source . but for the where Dim.status = ' Accepted' part im not sure what to do.
    Should I bring the Dim table as a LTS and define the 'where' condition in the content tab? will that work?
    but what if I have another logical column where I need dim.Status = 'Declined'( we have many more status)
    Plz help

    The suggest statement as Filter(count(Fact.Dollars) Using("dim.status = 'accepted'))
    is based on Answers, this would care about the column is available in Subject Area or not thats it.
    The same kind of functionality can get the using rpd.
    There you might need to map/add (fact source properties and then map using pencil icon on 11g add button in 10g) the dim table to the fact
    so that you can get the expression based on physical columns as
    case when dim.status = 'accepted' then Fact.Dollars else 0 end
    use Aggregate tab for sum;
    Since you are using Fact.Dollars it suppose to be sum, ROW_WIDs go by counts
    Hope this helps :) for more Qs send email
    If helps mark

  • Dynamic where condition in Select statement

    Hi,
    I have 10 fields on selection-screeen. In which ever field the user enters single values or ranges,i should pick that field dynamically and pass that field along with value range to Where condition of Select statement.How can i achieve this? Please help.
    Regards
    K Srinivas

    see the following example:
    data : begin of itab occurs 0,
             matnr like mara-matnr,
    end of itab.
    ypes: begin of ty_s_clause.
    types:   line(72)  type c.
    types: end of ty_s_clause.
    data : begin of gt_condtab occurs 0.
            include structure hrcond.
    data : end   of gt_condtab.
    FIELD-SYMBOLS <fs_wherecond> TYPE ty_s_clause.
    data:
      gt_where_clauses  type standard table of ty_s_clause
                        with default key.
    gt_condtab-field = 'MATNR'.
    gt_condtab-opera = 'EQ'.
    gt_condtab-low = '000000000000000111'.
    append  gt_condtab.
    clear  gt_condtab.
    call function 'RH_DYNAMIC_WHERE_BUILD'
      exporting
        dbtable         = space " can be empty
      tables
        condtab         = gt_condtab
        where_clause    = gt_where_clauses
      exceptions
        empty_condtab   = 01
        no_db_field     = 02
        unknown_db      = 03
        wrong_condition = 04.
    select matnr from mara into table itab where (gt_where_clauses).

  • Count(*) does not take into consideration the where condition

    the following sql function is supposed to calculate the number of rows that respect the conditions in the where clause. After I call this function I get the the total number of rows in the table. Any help would be much appreciated.
    FUNCTION NBRTRIMCOMPLETES (ETU_NO NUMBER, PRG_NO NUMBER) RETURN VARCHAR2 IS
    nbrTrimCompletes number(6);
    begin
         SELECT COUNT(*) into nbrTrimCompletes from (select * from INSCRIPTION I WHERE I.ETU_NO = ETU_NO AND I.PRG_NO = PRG_NO);
         RETURN nbrTrimCompletes;
    end NBRTRIMCOMPLETES;

    The compile can't distinguish between the column name ETU_NO an the variable ETU_NO, that's why your where condition always evaluates to true.
    Change the name of the parameters.
    FUNCTION NBRTRIMCOMPLETES (P_ETU_NO INSCRIPTION.ETU_NO%TYPE,
                               P_PRG_NO INSCRIPTION.PRG_NO%TYPE
                              ) RETURN NUMBER
    IS
      nbrTrimCompletes PLS_INTEGER;
    begin
      SELECT COUNT(*)
      into   nbrTrimCompletes
      FROM   INSCRIPTION I
      WHERE  I.ETU_NO = P_ETU_NO
      AND    I.PRG_NO = P_PRG_NO;
      RETURN nbrTrimCompletes;
    end NBRTRIMCOMPLETES;

  • Outbound merge not working with where conditions in 10g

    Hi,
    These are my database details both remote and local database
    SQL> select * from v$version;
    BANNER
    Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi
    PL/SQL Release 10.2.0.4.0 - Production
    CORE    10.2.0.4.0      Production
    TNS for HPUX: Version 10.2.0.4.0 - Production
    NLSRTL Version 10.2.0.4.0 - ProductionI am doing a merge into a remote database from a local table using below query...
    MERGE into sap_mmd_po_all@cosmic_dev.somedomainname trg using (select * from sap_mmd_cmas_po where upload_flag in ('I','U')) src
      on (trg.PO_NO=src.PO_NO and trg.LINE_DISTRIB_SEQ=src.LINE_DISTRIB_SEQ)
      WHEN MATCHED THEN
        update set
          trg.PO_STATUS_FLG=src.PO_STATUS_FLG,
          trg.SHIP_TO_FACILITY_CD=src.SHIP_TO_FACILITY_CD,
          trg.DELV_TO_PHONE_NO=src.DELV_TO_PHONE_NO,
          trg.DELV_TO_NM=src.DELV_TO_NM,
          trg.DELV_TO_ADDRESS_1=src.DELV_TO_ADDRESS_1,
          trg.PO_ITEM_NO=src.PO_ITEM_NO,
          trg.ITEM_DESCRP=src.ITEM_DESCRP,
          trg.PARTY_NM=src.PARTY_NM,
          trg.VENDOR_ITEM_ID=src.VENDOR_ITEM_ID,
          trg.PO_LN_CRTE_DT=src.PO_LN_CRTE_DT,
          trg.BILL_UOM_CD=src.BILL_UOM_CD,
          trg.COMMODITY_CD=src.COMMODITY_CD,
          trg.COMMODITY_NM=src.COMMODITY_NM,
          trg.BSNSS_UNIT_NO=src.BSNSS_UNIT_NO,
          trg.PO_LN_ORD_QTY=src.PO_LN_ORD_QTY,
          trg.DISTRIB_AMT=src.DISTRIB_AMT,
          trg.PO_LN_DEL_IND=src.PO_LN_DEL_IND,
          trg.PO_DEL_IND=src.PO_DEL_IND,
          trg.PO_TYPE=src.PO_TYPE,
          trg.DOC_DATE=src.DOC_DATE,
          trg.CRTE_DT_TM=src.CRTE_DT_TM,
          trg.UPD_DT_TM=systimestamp,
          trg.SOURCE_SYSTEM=src.SOURCE_SYSTEM,
          trg.PO_LN_LST_CHNGE_DT=src.PO_LN_LST_CHNGE_DT,
          trg.TXJCD=src.TXJCD,
          trg.PLANT=src.PLANT
          where (src.upload_flag='U')--if i remove this then it is working
      WHEN NOT MATCHED THEN
        insert( trg.PO_NO,
                trg.LINE_DISTRIB_SEQ,
                trg.PO_STATUS_FLG,
                trg.SHIP_TO_FACILITY_CD,
                trg.DELV_TO_PHONE_NO,
                trg.DELV_TO_NM,
                trg.DELV_TO_ADDRESS_1,
                trg.PO_ITEM_NO,
                trg.ITEM_DESCRP,
                trg.PARTY_NM,
                trg.VENDOR_ITEM_ID,
                trg.PO_LN_CRTE_DT,
                trg.BILL_UOM_CD,
                trg.COMMODITY_CD,
                trg.COMMODITY_NM,
                trg.BSNSS_UNIT_NO,
                trg.PO_LN_ORD_QTY,
                trg.DISTRIB_AMT,
                trg.PO_LN_DEL_IND,
                trg.PO_DEL_IND,
                trg.PO_TYPE,
                trg.DOC_DATE,
                trg.CRTE_DT_TM,
                trg.UPD_DT_TM,
                trg.SOURCE_SYSTEM,
                trg.PO_LN_LST_CHNGE_DT,
                trg.TXJCD,
                trg.PLANT)
        values( src.PO_NO,
                src.LINE_DISTRIB_SEQ,
                src.PO_STATUS_FLG,
                src.SHIP_TO_FACILITY_CD,
                src.DELV_TO_PHONE_NO,
                src.DELV_TO_NM,
                src.DELV_TO_ADDRESS_1,
                src.PO_ITEM_NO,
                src.ITEM_DESCRP,
                src.PARTY_NM,
                src.VENDOR_ITEM_ID,
                src.PO_LN_CRTE_DT,
                src.BILL_UOM_CD,
                src.COMMODITY_CD,
                src.COMMODITY_NM,
                src.BSNSS_UNIT_NO,
                src.PO_LN_ORD_QTY,
                src.DISTRIB_AMT,
                src.PO_LN_DEL_IND,
                src.PO_DEL_IND,
                src.PO_TYPE,
                src.DOC_DATE,
                systimestamp,
                src.UPD_DT_TM,
                src.SOURCE_SYSTEM,
                src.PO_LN_LST_CHNGE_DT,
                src.TXJCD,
                src.PLANT)
                where src.upload_flag='I'--if i remove this then it is working
                ;And it is throwing an error like...
    SQL Error: ORA-00904: "A3"."UPLOAD_FLAG": invalid identifierBut when I replace the remote table name with local table name then query is functioning fine...
    table structure in local database..
    CREATE TABLE SAP_MMD_CMAS_PO
       (     "PO_NO" VARCHAR2(10 BYTE) NOT NULL ENABLE,
         "LINE_DISTRIB_SEQ" NUMBER NOT NULL ENABLE,
         "PO_STATUS_FLG" VARCHAR2(40 BYTE),
         "SHIP_TO_FACILITY_CD" VARCHAR2(100 BYTE),
         "DELV_TO_PHONE_NO" VARCHAR2(50 BYTE),
         "DELV_TO_NM" VARCHAR2(100 BYTE),
         "DELV_TO_ADDRESS_1" VARCHAR2(1000 BYTE),
         "PO_ITEM_NO" VARCHAR2(100 BYTE),
         "ITEM_DESCRP" VARCHAR2(200 BYTE),
         "PARTY_NM" VARCHAR2(1000 BYTE),
         "VENDOR_ITEM_ID" VARCHAR2(100 BYTE),
         "PO_LN_CRTE_DT" TIMESTAMP (6),
         "BILL_UOM_CD" VARCHAR2(50 BYTE),
         "COMMODITY_CD" VARCHAR2(50 BYTE),
         "COMMODITY_NM" VARCHAR2(50 BYTE),
         "BSNSS_UNIT_NO" VARCHAR2(50 BYTE),
         "PO_LN_ORD_QTY" NUMBER,
         "DISTRIB_AMT" NUMBER,
         "PO_LN_DEL_IND" VARCHAR2(10 BYTE),
         "PO_DEL_IND" VARCHAR2(10 BYTE),
         "PO_TYPE" VARCHAR2(10 BYTE),
         "DOC_DATE" TIMESTAMP (6),
         "CRTE_DT_TM" TIMESTAMP (6),
         "UPD_DT_TM" TIMESTAMP (6),
         "SOURCE_SYSTEM" VARCHAR2(100 BYTE),
         "PO_LN_LST_CHNGE_DT" TIMESTAMP (6),
         "TXJCD" VARCHAR2(50 BYTE),
         "PLANT" VARCHAR2(10 BYTE),
         "UPLOAD_FLAG" VARCHAR2(1 BYTE),
          PRIMARY KEY ("PO_NO", "LINE_DISTRIB_SEQ")
    --table structure in remote database table
    CREATE TABLE SAP_MMD_PO_ALL
       (     "PO_NO" VARCHAR2(10 BYTE) NOT NULL ENABLE,
         "LINE_DISTRIB_SEQ" NUMBER NOT NULL ENABLE,
         "PO_STATUS_FLG" VARCHAR2(40 BYTE),
         "SHIP_TO_FACILITY_CD" VARCHAR2(100 BYTE),
         "DELV_TO_PHONE_NO" VARCHAR2(50 BYTE),
         "DELV_TO_NM" VARCHAR2(100 BYTE),
         "DELV_TO_ADDRESS_1" VARCHAR2(1000 BYTE),
         "PO_ITEM_NO" VARCHAR2(100 BYTE),
         "ITEM_DESCRP" VARCHAR2(200 BYTE),
         "PARTY_NM" VARCHAR2(1000 BYTE),
         "VENDOR_ITEM_ID" VARCHAR2(100 BYTE),
         "PO_LN_CRTE_DT" TIMESTAMP (6),
         "BILL_UOM_CD" VARCHAR2(50 BYTE),
         "COMMODITY_CD" VARCHAR2(50 BYTE),
         "COMMODITY_NM" VARCHAR2(50 BYTE),
         "BSNSS_UNIT_NO" VARCHAR2(50 BYTE),
         "PO_LN_ORD_QTY" NUMBER,
         "DISTRIB_AMT" NUMBER,
         "PO_LN_DEL_IND" VARCHAR2(10 BYTE),
         "PO_DEL_IND" VARCHAR2(10 BYTE),
         "PO_TYPE" VARCHAR2(10 BYTE),
         "DOC_DATE" TIMESTAMP (6),
         "CRTE_DT_TM" TIMESTAMP (6),
         "UPD_DT_TM" TIMESTAMP (6),
         "SOURCE_SYSTEM" VARCHAR2(100 BYTE),
         "PO_LN_LST_CHNGE_DT" TIMESTAMP (6),
         "TXJCD" VARCHAR2(50 BYTE),
         "PLANT" VARCHAR2(10 BYTE),
         "DELETE_FLAG" VARCHAR2(1 BYTE) DEFAULT 'N',
          PRIMARY KEY ("PO_NO", "LINE_DISTRIB_SEQ")
      )It seems to me like a bug, but not quite sure...
    your suggestions are appreciated.
    Thanks,
    Ravi Kumar
    Edited by: ravikumar.sv on Dec 14, 2009 1:31 PM
    Commented the where conditions in merge query

    Hi,
    Yes, i hit the same error....
    SQL> ed
    Wrote file afiedt.buf
      1  merge into hr.test1@test_dblink using test2 on (test1.id = test2.id)
      2  when matched then update set test1.col1=test2.col2 where test2.id=2
      3* when not matched then insert (id, col1) values(test2.id,test2.col2)
    SQL> /
    merge into hr.test1@test_dblink using test2 on (test1.id = test2.id)
    ERROR at line 1:
    ORA-00904: "A3"."ID": invalid identifier
    ORA-02063: preceding line from TEST_DBLINKBUT here is a work around...to add the where condition while joining(ON) itself.
    SQL> ed
    Wrote file afiedt.buf
      1  merge into hr.test1@test_dblink using test2 on (test1.id = test2.id and tes
    t2.id=2)
      2  when matched then update set test1.col1=test2.col2
      3* when not matched then insert (id, col1) values(test2.id,test2.col2)
    SQL> /
    2 rows merged.
    SQL>For you the condition would be...
    on (trg.PO_NO=src.PO_NO and trg.LINE_DISTRIB_SEQ=src.LINE_DISTRIB_SEQ AND src.upload_flag='U')cheers,
    Edited by: Avinash Tripathi on Dec 14, 2009 2:53 PM

  • Where condition

    Hi all,
    My 2nd select query is not working.
    Plz tell where i m wrong.
    if itab_lfa1[] is not initial.
    if p_bukrs is  initial.
      select lifnr bukrs
      from lfb1
      into  corresponding fields of table i_lfb1
      for all entries in itab_lfa1
      where lifnr =  itab_lfa1-lifnr.
      else.
      select lifnr bukrs
        from lfb1
      into  corresponding fields of table i_lfb1
      for all entries in itab_lfa1
      where lifnr =  i_lfa1-lifnr
        and bukrs eq p_bukrs.
      endif.
      endif.
    Showing the error msg in 2nd select this:
    The WHERE condition does not refer to the FOR ALL ENTRIES table.           
    But when we remove for all entries in itab_lfa1,
    then it show no error, but doesn,t able to pick all records.
    Best Regards,
    Aastha.

    hi,
    Check out in this way  ..
    call function 'CONVERSION_EXIT_ALPHA_INPUT'
              exporting
                      input = p_bukrs
              importing
                     output = p_bukrs.
    loop at itab_lfa1.
    call function 'CONVERSION_EXIT_ALPHA_INPUT'
              exporting
                      input = itab_lfa1-lifnr
              importing
                     output = itab_lfa1-lifnr.
      modify itab_lfa1 index sy-tabix.
    endloop.
    if not itab_lfa1[] is initial.
    select lifnr bukrs
    from lfb1
    into corresponding fields of table i_lfb1
    for all entries in itab_lfa1
    where lifnr = itab_lfa1-lifnr
    and bukrs = p_bukrs. " Assuming p_bukrs is declared as parameter
    endif.

  • CASE Statement in Where Condition with Multi Valued parameter in SSRS

    Hi All,
    I am little confused while using CASE statement in Where condition in SSRS. Below is my scenario:
    SELECT
    Logic here
    WHERE
    Date IN (@Date)AND
    (CASE
    WHEN NAME LIKE 'ABC%' THEN 'GROUP1'
    WHEN ID IN ('123456', '823423','74233784') THEN 'GROUP2'
    WHEN ABC_ID IS NULL THEN 'GROUP3'
    ELSE 'GROUP4'
    END ) IN (@GROUP)
    So above query uses WHERE condition with CASE statement from @GROUP parameter. I want to pass this parameter as multi- valued parameter and hence I have used CASE statement IN (@GROUP).
    For @Date one dataset will pass the available and default values and
    for @GROUP parameters, another dataset will pass the available and default values.
    But this is not working as expected. Please suggest me where I am making mistake in the query.
    Maruthu | http://sharepoint-works.blogspot.com

    Hi Maruthu,
    According to your description, I create a sample report in my local environment. It works as I expected. In your scenario, if the selected values from the Date parameter contains some of the Date field values, the selected values from the GROUP parameter
    contains some of GROUPS (‘GROUP1’,’GROUP2’,’GROUP3’,’GROUP4’) and the corresponding when statement is executed , then the dataset returns the corresponding values.
    In order to trouble shoot this issue, could you tell us what results are you get and what’s your desired results? If possible, you can post the sample data with sample dataset, then we can make further analysis and help you out.
    Thanks,
    Katherine Xiong
    Katherine Xiong
    TechNet Community Support

  • Concatenation error - when i use text column value in where condition.

    Hi,
    i am creating Materialized view using few columns from two tables and as per requirement i need to prepare select statement with where condition in another column.(new column)
    i tried like below....
    create materialized view MAIN
    refresh force on demand
    as
    select
    a.table_name,
    a.column_name,
    b.trial_name,
    'select * from '||a.table_name||' where '||a.column_name|| ' = '|| b.trial_name||';' "QUERY"
    from
    exp_csv_tB a,
    exp_csv_tr b;
    a.table name value is : monitoring_table
    a.column_name value is : study
    b.trial_name = fty777
    Materialized view created with extra column but it is not added '' (codes) to text value in where condition.
    output which i got is :
    select * from monitoring_table where study = fty777;
    but
    i need output like
    select * from monitoring_table where study = 'fty777';
    fty777 value should be in codes like 'fty777'. i read some articles but didnt get this example.
    please help.

    Try this:
    CREATE MATERIALIZED VIEW main
    REFRESH FORCE ON DEMAND
    AS
    SELECT
    a.table_name,
    a.column_name,
    b.trial_name,
    'select * from '||a.table_name||' where '||a.column_name|| ' = '''|| b.trial_name||'';'' "QUERY"
    FROM
    exp_csv_tb a,
    exp_csv_tr b;
    You have to give double single codes for semi-colons ..
    Regards..

  • Checkbox Value in where condition of query

    Hi,
    I have a check box which shows values based on the LOV's . If i check on the checkbox the values that are selected on the check box must be used in the where condition to update the table.
    Please suggest me how to take the check box values.
    Am using the below methos to update but its not happening
    Declare
    old_cohort_name varchar2(500);           
    new_cohort_name varchar2(500);
    l_cohort_id apex_application_global.vc_arr2;
    begin
    l_cohort_id := apex_util.string_to_table(:P64_CASCADE_COHORT_NAMES);
    select cohort_name into old_cohort_name from study_cohort
    where cohort_id = :p64_cohort_id;
    select :P64_COHORT_NAME into new_cohort_name from dual;
    if old_cohort_name <> new_cohort_name then
    update study_cohort
    set      
    cohort_name = new_cohort_name
    where cohort_id = :p64_cohort_id and
    cohort_id = l_cohort_id; // here is the variable i am using when checkbox is checked
    End if;
    End;
    Please suggest me how to modify the code
    Tx
    Sudhri

    Hi Sudhri,
    where cohort_id = :p64_cohort_id and
    cohort_id = l_cohort_id; // here is the variable i am using when checkbox is checked If this is the code you are actually using, then the condition would only be met if l_cohort_id = :p64_cohort_id because you are using an AND condition over the same column in the where clause, so it will only return rows when both values are the same. Then, I think that it seems not to be working for you because :p64_cohort_id and l_cohort_id have different values, and no row is getting updated then. If the values you are selecting in your checkboxes are several ids of rows to update, besides the one with id :p64_cohort_id, then maybe the condition you need is something like this:
    WHERE cohort_id = :p64_cohort_id OR instr(l_cohort_id, cohort_id) != 0;Hope that helps.
    Regards,
    Sergio

  • Num and Value in Where condition

    Hi all,
    I have table:
    create table T1
       f1 fixed (1),
       f2 boolean
    then:
       insert into T1 values (1,null)
    and query:
       select f2,Num(Value(f2,False)),Num(Value(null,False)) from 
       (select max(f1) x from t1)
       left join t1 on x=f1
       where 22 =Num(Value(f2,False))
    Statement 'select f2 from      (select max(f1) x from t1)    left join t1 on x=f1    where 22 ...' successfully executed in 0 ms.
    Result: ?;0;0
    This is a bug? Known bug?
    KR Lukasz.

    Hi Holger,
    sorry it does nothing. Query still returns rows.
    Thank you for help and explanation very much. I'm waiting to next MAXDB relase(s).
    BTW
    I have fixed this problem in that way:
    select f2,Num(Value(f2,False)),Num(Value(null,False)) from
    (select max(f1) x, 22 k from t1)
    left join t1 on x=f1
    where Num(Value(f2,False))=k
    query does not return rows but... execution plan contains &#17752;&#20562;&#17747;&#21321;&#20302;&#8279;&#18772;&#18464;††††††††††††††††††††††††. 
    Simple correction in where condition:
    select f2,Num(Value(f2,False)),Num(Value(null,False)) from
    (select max(f1) x, 22 k from t1)
    left join t1 on x=f1
    where Num(Value(f2,False))-k=0
    And execution plan is proper too.
    KR Lukasz.

  • Single quote in dynamic where condition

    BAPI_STUDENT_IDENTIFIC_ADD has a field called IDENTIFICATIONNUMBER.  This field is later used in a dynamic where condition and causes a short dump when it contains a single quote.  I will change the program that calls the BAPI to check for single quotes, but is there anything else I need to check for to ensure a correct where condition?
    Thanks,
    Dan

    Hi Dan,
    The best way to ensure correctness of syntax of a dynamic where condition is:
    Run the program in debugging mode, Get the Query that is generated dynamically and write it to some other ABAP program and perform syntax check.
    This will help you to remove all the syntax errors.
    Regards,
    Darshil

Maybe you are looking for

  • Pls help in starting a project

    Hello, I request for help in starting a sample project bc4j under JDeveloper. The folder resides in Programfiles\Oracle\Jdeveloper3.2\samples. I have been asked to go to ..\samples\bc4j directory and create user bc4j identified by bc4j, grant resourc

  • Ss12u1 on linux: relocation R_X86_64_32 against `a local symbol' can not be

    hello all, i've installed SS12u1 on a Sun x2270 under Centos 5.4. We have to recompile a (veryhuge) scientific app that compiled fine on Solaris 10 amd64 with SS12u1, so the makefiles are identical between the two machines. But, we faced the followin

  • Aperture - how can I get my colored icons back ??? I don´t like it grey in grey !!!

    Hello, is there any chance to restore the colorful icons in Aperture 3? Whatever possible reason the developers may have had, to make it all grey in grey... I don´t like it that way !!! Just the same like the loss of colorful icons since OSX Lion...

  • UC540 FXS port "CCA Hangs"

    Dear all, The port needs to be a user phone I need to be able to set it up in a hunt group etc When I go to users and extensions / users and phones the operation in progress sits there endlessly with operation in progress. The end result I need is an

  • Bass and Treble Sliders in Audiomixer disabled T60

    Hi! I just bought a used T60 with a integrated Digital HD sound card. Sound/Audio is working. Problem is: The audiomixer shows control-sliders for Bass and Treble. But they are greyed out and both set to minimum. Result is: The audio sounds pretty lo