Problem in Dynamic LOV query

Hi,
I have a LOV in my page its query should be based on item condition.
So I tried using Apex provided Dynamic LOV Query with IF.. ELSE.. END IF condition.. But when I use this and run the page it is giving error "URL NOT FOUND".
My query is
   IF :MY_ITEM is not null THEN
   RETURN 'select ename ,eno
                from emp
                where eno = '''||:MY_ITEM||''' ';
   ELSE
    RETURN 'select ename ,eno
                from emp
                where ename = ''ALAKA''  ';
   END IF;But it is not working for me.
Please anyone help me to solve this.
Thanks
Alaka

Hi All,
It worked for me. Just I modified my code a bit. Thanks to all for help.
Just I did ,
   DECLARE
   BEGIN
         IF :MY_ITEM IS NOT NULL THEN
            RETURN 'SELECT ENAME,ENO
                        FROM EMP
                        WHERE ENAME = '''||:MY_ITEM||''' ';
       ELSE
           RETURN 'SELECT ENAME,ENO
                        FROM EMP
                        WHERE ENAME = ''ALAKA'' ';
      END IF;
      EXCEPTION
        WHEN OTHERS THEN
            HTP.PRN('ERROR'||SQLERRM);
   END;
Thanks
Alaka

Similar Messages

  • Problem with dynamic LOV and function

    Hello all!
    I'm having a problem with a dynamic lov in APEX 3.0.1.00.08. Hope you can help me!
    I have Report and Form application. On the Form page i have a Page Item (Popup Key LOV (Displays description, returns key value)).
    When i submit the sql code in the 'List of vaules defention' box. I get the following message;
    1 error has occurred
    LOV query is invalid, a display and a return value are needed, the column names need to be different. If your query contains an in-line query, the first FROM clause in the SQL statement must not belong to the in-line query.
    When i excecute the code below in TOAD or in the SQL Workshop it returns the values i want to see. But somehow APEX doesn't like the sql....
    SELECT REC_OMSCHRIJVING d, REC_DNS_ID r FROM
    TABLE(CAST(return_dns_lov_fn(:P2_DNS_ID) AS dns_table_type)) order by 1
    returns_dns_lov_fn is a function, code is below;
    CREATE OR REPLACE FUNCTION DRSSYS.return_dns_lov_fn (p2_dns_id number)
    RETURN dns_table_type
    AS
    v_data dns_table_type := dns_table_type ();
    BEGIN
    IF p2_dns_id = 2
    THEN
    FOR c IN (SELECT dns_id dns, omschrijving oms
    FROM d_status dst
    WHERE dst.dns_id IN (8, 10))
    LOOP
    v_data.EXTEND;
    v_data (v_data.COUNT) := dns_rectype (c.dns, c.oms);
    END LOOP;
    RETURN v_data;
    END IF;
    END;
    and the types;
    CREATE OR REPLACE TYPE DRSSYS.dns_rectype AS OBJECT (rec_dns_id NUMBER, rec_omschrijving VARCHAR2(255));
    CREATE OR REPLACE TYPE DRSSYS.dns_table_type AS TABLE OF dns_rectype;
    I tried some things i found on this forum, but they didn't work as well;
    SELECT REC_OMSCHRIJVING display_value, REC_DNS_ID result_display FROM
    TABLE(CAST(return_dns_lov_fn(:P2_DNS_ID) AS dns_table_type)) order by 1
    SELECT REC_OMSCHRIJVING display_value d, REC_DNS_ID result_display r FROM
    TABLE(CAST(return_dns_lov_fn(:P2_DNS_ID) AS dns_table_type)) order by 1
    SELECT a.REC_OMSCHRIJVING display_value, a.REC_DNS_ID result_display FROM
    TABLE(CAST(return_dns_lov_fn(:P2_DNS_ID) AS dns_table_type)) a order by 1
    Edited by: rajan.arkenbout on 8-mei-2009 14:41
    Edited by: rajan.arkenbout on 8-mei-2009 14:51

    I just had the same problem when I used a function in a where clause.
    I have a function that checks if the current user has acces or not (returning varchar 'Y' or 'N').
    In where clause I have this:
    where myFunction(:user, somePK) = 'Y'
    It seems that when APEX checked if my query was valid, my function triggered and exception.
    As Varad pointed out, check for exception that could be triggered by a null 'p2_dns_id'
    Hope that helped you out.
    Max

  • What is wrong with this dynamic LOV query?

    I am trying to create a dynamic LOV which contains calendar week numbers, given a bind var containing the year. If the year given is this year I want the LOV to contain all weeks up to but not including this week, if the year given is in the past I want the LOV to contain all weeks in that year.
    Here is my query;
    select display_value, week_num from
    (select decode(
    :P31_YEAR,
    to_char(sysdate, 'YYYY'), to_number(to_char(sysdate, 'IW')),
    1+to_number(to_char(to_date('31/12/' || :P31_YEAR, 'DD/MM/YYYY'), 'IW'))
    ) max_weeks,
    level week_num,
    'Week ' || level display_value
    from dual
    connect by level < 54
    ) where week_num < max_weeks
    When I try to create the dynamic LOV Apex tells me the query is invalid. It runs in TOAD and as far as I can see follows the LOV query rules.

    Try this:
    select display_value d, week_num r from
    (select decode(
    nvl(:P13_YEAR,'2007'),
    to_char(sysdate, 'YYYY'), to_number(to_char(sysdate, 'IW')),
    1+to_number(to_char(to_date('31/12/' || nvl(:P13_YEAR,'2007'), 'DD/MM/YYYY'), 'IW'))
    ) max_weeks,
    level week_num,
    'Week ' || level display_value
    from dual
    connect by level < 54
    ) where week_num < max_weeks
    Scott

  • Dynamic LOV query

    Hi,
    Anyone can share with me of how to apply dynamic LOV?
    let say user choose messagechoice value = 'A' then messagelovinput will only execute query A and display the list of LOV values.
    if user choose messagechoice value = 'B' then messagelovinput will execute query B and display its LOV values.
    Pls help..

    yuchijoyce wrote:
    actually try to pass in parameter into the functions and return a list of values into the lov, is there any sample coding for reference?:( Not sure what do you mean by this??
    But if you want that to make use of a function that can give you list of value. Then you can follow the approach mentioned by Anil, thereby you will be creating a Function in database that is going to return different query based on conditions and you can base LOV vo object on this function.
    Hope it works :)
    Thanks
    AJ

  • Dynamic LOV query will not be displayed

    Hello,
    we created the following record group
    select ename, empno from emp order by 1
    then we created a list of values depending on the record group:
    We added ename to  emp.mgr and empno to null in the LOV
    Then we changed  the emp.emg item to type CHAR and POPUP list
    When we run the form nothing is displayed in the colum of MGR and only 1 record in th tabular form is displayed.
    Please help us
    Regards

    When I save nimber with country code contact name will be displayed,
    and if I store the number without the country code and I get a call it does not show the contact name!!
    This problem exists for all Iranians!

  • Designing LOV Query Problem

    Hello APEX people,
    I posted my problem here:
    Designing LOV Query Problem
    What I have is a sequence like this:
    CREATE SEQUENCE
    DR_SEQ_FIRST_SCHEDULE_GROUP
    MINVALUE 1 MAXVALUE 7 INCREMENT BY 1 START WITH 1
    CACHE 6 ORDER CYCLE ;
    What I need would be a SQL query returning all possible values oft my sequence like:
    1
    2
    3
    4
    5
    6
    7
    I want to use it as a source for a LOV...
    The reason why I use the cycling sequence is: My app uses it to cycle scheduling priorities every month to groups identified by this number (1-7).
    In the Admin Form, I want to restrict the assignment in a user friendly way - a LOV.
    Thanks
    Johann

    Here ist the solution (posted by michales in the PL/SQL forum):
    SQL> CREATE SEQUENCE
    dr_seq_first_schedule_group
    MINVALUE 1 MAXVALUE 7 INCREMENT BY 1 START WITH 1
    CACHE 6 ORDER CYCLE
    Sequence created.
    SQL> SELECT LEVEL sn
    FROM DUAL
    CONNECT BY LEVEL <= (SELECT max_value
    FROM user_sequences
    WHERE sequence_name = 'DR_SEQ_FIRST_SCHEDULE_GROUP')
    SN
    1
    2
    3
    4
    5
    6
    7
    7 rows selected.

  • Problem writing a sql query for a select list based on a static LOV

    Hi,
    I have the following table...
    VALIDATIONS
    ID          Number     (PK)
    APP_ID          Number     
    REQUESTED     Date          
    APPROVED     Date          
    VALID_TIL     Date
    DEPT_ID          Number     (FK)
    I have a search form with the following field item variables...
    P11_DEPT_ID (select list based on dynamic LOV from depts table)
    P11_VALID (select list based on static Yes/No LOV)
    A report on the columns of the Validations table is shown based on the values in the search form. So far, my sql query for the report is...
    SELECT v.APP_ID,
    v.REQUESTED,
    v.APPROVED,
    v.VALID_TIL,
    d.DEPT
    FROM DEPTS d, VALIDATIONS v
    WHERE d.DEPT_ID = v.DEPT_ID(+)
    AND (d.DEPT_ID = :P11_DEPT_ID OR :P11_DEPT_ID = -1)
    This query works so far. My problem is that I don't know how to do a search based on the P11_VALID item - if 'yes' is selected, then the VALID_TIL date is still valid. If 'no' is selected then the VALID_TIL date has passed.
    Can anyone help me to extend my query to include this situation?
    Thanks.

    Hello !
    Let's have a look at my example:create table test
    id        number
    ,valid_til date
    insert into test values( 1, sysdate-3 );
    insert into test values( 2, sysdate-2 );
    insert into test values( 3, sysdate-1 );
    insert into test values( 4, sysdate );
    insert into test values( 5, sysdate+1 );
    insert into test values( 6, sysdate+2 );
    commit;
    select * from test;
    def til=yes
    select *
      from test
      where decode(sign(trunc(valid_til)-trunc(sysdate)),1,1,0,1,-1)
           =decode('&til','yes',1,-1);
    def til=no
    select *                                                                               
      from test                                                                            
      where decode(sign(trunc(valid_til)-trunc(sysdate)),1,1,0,1,-1)
           =decode('&til','yes',1,-1);  
    drop table test;  It's working fine, I've tested it.
    The above changes to my first idea I did because of time portion of the DATE datatype in Oracle and therefore the wrong result for today.
    For understandings:
    1.) TRUNC removes the time part of DATE
    2.) The difference of to date-values is the number of days between.
    3.) SIGN is the mathematical function and gives -1,0 or +1 according to an negative, zero or positiv argument.
    4.) DECODE is like an IF.
    Inspect your LOV for the returning values. According to my example they shoul be 'yes' and 'no'. If your values are different, you may have to modify the DECODE.
    Good luck,
    Heinz

  • Item Selection on a dynamic LOV (SQL Query)

    Hi,
    I've a dynamic LOV with an SQL query who return a list of data (one column). When i select a data in this LOV to be use as an item (sql query) in the same page the data is always null. In debug mode substitution string is null.
    FYI : when the data is selected, a button is clik to perform an sql query for a report in another page.
    Thanks. Sorry Abasolute beginner
    Message was edited by:
    user581765

    Thanks for Your help.
    The date is in fact a CHAR display (not really a date) so that is not the error.
    For your information when i select a row in the list (format char YYYYMMDD_HHMM) it seems that Apex do not catch my select in the Session state.
    I've change the item name with P2_DATE_FLOW but the problem remain.
    This is the debug log if can help
    0.03: Application 114, Authentication: CUSTOM2, Page Template: 3644802034190382
    0.06: ...Session ID 1868105032215374 can be used
    0.06: ...Application session: 1868105032215374, user=Neop
    0.06: ...Determine if user "Neop" workspace "2859608277950243" can develop application "114" in workspace "2859608277950243"
    0.06: Session: Fetch session header information
    0.06: ...Metadata: Fetch page attributes for application 114, page 3
    0.06: Fetch session state from database
    0.06: Branch point: BEFORE_HEADER
    0.06: Fetch application meta data
    0.08: Computation point: BEFORE_HEADER
    0.08: Processing point: BEFORE_HEADER
    0.08: Show page template header
    0.08: Computation point: AFTER_HEADER
    0.08: Processing point: AFTER_HEADER
    0.08: Computation point: BEFORE_BOX_BODY
    0.08: Processing point: BEFORE_BOX_BODY
    0.08: Region: Report 1
    Report 1
    0.08: show report
    0.09: determine column headings
    0.09: parse query as: CFM_MDRE
    0.12: binding: ":P2_DATE_FLOW"="P2_DATE_FLOW" value="0"
    0.14: print column headings
    0.14: rows loop: 15 row(s)
    No data found.

  • Problem in getting dynamic LOV

    hi i am trying to acheive dynamic LOV.
    i followed the steps
    1.created a static record group
    2.created a LOV and assigned with the above created static record group.
    3.in w-n-b-i trying to create the DRG
    DECLARE
       rg_id    RECORDGROUP;
       grp_col  GROUPCOLUMN;
       rg_name  VARCHAR2(25) := 'RG_NAME';
       col_name VARCHAR2(25) := 'TYPE';
       lov_id   LOV;
    BEGIN
       /* Check if the RG already exists */
       rg_id := Find_Group(rg_name);
       IF ( NOT Id_Null(rg_id) ) THEN
          Delete_Group(rg_id);
       END IF;
       /* Create instance of DRG */
       rg_id := Create_Group(rg_name);
       grp_col := Add_Group_Column(rg_id, col_name, CHAR_COLUMN, 8);
       /* Assign the DRG to the LOV */
    lov_id := Find_Lov('TYPE_LOV');
       Set_Lov_Property(lov_id, GROUP_NAME, rg_name);
    END;4.in w-v-i of type
    DECLARE
       rg_id   RECORDGROUP;
       grp_col   GROUPCOLUMN;
       tmp_gc  GROUPCOLUMN;
       rg_name   VARCHAR2(25) := 'RG_TYPE';
       col_name   VARCHAR2(25) := rg_name||'.'||'TYPE';
       n_dummy1  NUMBER;
       n_dummy2  NUMBER;
       curr_rec   INTEGER;
       err_code  NUMBER;
    BEGIN
       curr_rec := Get_Block_Property(Name_In('SYSTEM.TRIGGER_BLOCK'), CURRENT_RECORD);
       rg_id := Find_Group(rg_name);
       grp_col := Find_Column(col_name);
       /* Add the value to the DRG */
       -- Add row first./*
       Add_Group_Row(rg_id, END_OF_GROUP);
       -- Now add the value.
       Set_Group_Number_Cell(grp_col, curr_rec, To_Number(:BMM_DESC));
       /* Verify the value was added */
       n_dummy1 := Get_Group_Row_Count(rg_name);
       tmp_gc := Find_Column(col_name);
       FOR j IN 1..n_dummy1 LOOP
          n_dummy2 := Get_Group_Number_Cell(tmp_gc, j);
          IF ( nvl(n_dummy2, 9999999999) = 9999999999 ) THEN
             Clear_Message;
             Message('Add Failed');
             Message('Add Failed');
          ELSE
             err_code := Populate_Group(rg_id);
             Clear_Message;
             Message('Add Successful');
          END IF;
       END LOOP;
          MESSAGE('FIRING');MESSAGE('FIRING');
    END;the problem is the lov is not appearing at all(previously the lov was appearing along with the static value assigned)
    when i tried to add value to the item(type), i am getting the following error:
    FRM-40735 WHEN-VALIDATE-ITEM trigger raised unhandled exception ora-06502
    i am getting pop up message-error in adding group row
    i have not done this before. in the help of some contents which is present in the fourm, i have tried it.
    where i am missing?
    Please help

    there seems to be problem with the item type, varchar2 or numeric whatever. check that.

  • Problem - Creating a Dynamic LOV using duplicate value in select statement

    I am trying to create a Dynamic LOV by attempting to follow a pattern similar to the following:
    select shop_name d, shop_id r
    from shops
    order by 1
    However, I want to use the shop_name twice as in the following because I do not have any other unique identifier available such as a shop_id to associate with the shop name:
    select shop_name d, shop_name r
    from shops
    order by 1
    But I get an error where I am not allowed to duplicate the shop_name in the select statement. I read somewhere on this forum where it can be done but I can't find exactly how.
    Can someone tell or show me how to accomplish this?
    Thanks in anticipation for your answer.
    Thanks,
    Ric

    Ric,
    I just tried to do this on APEX 3.0, and it worked just fine with this SQL:
    select ename d, ename r from emp order by 1Perhaps you could put an example on apex.oracle.com or specify the error message that you're getting.
    So as long as you have uniquely aliased both columns, this should not present a problem.
    Thanks,
    - Scott -

  • LOV Query problem

    I have a very huge and a lenghty LOV Query . I am using 6i builder and when i save the module and try to reopen it , Only 3/4th of the LOV query is available and the remaining disappears . I can compile this in 6i by copying the query again but it creates a problem in 10g . ie. The Fmx file is not generating in 10g.
    Firstly ,
    I haven no idea as to why the code disappears for no reason ? IS it because its too lenghty. I am sure there are no errors because it wouldn't have compiled if there were any .
    Anybody who has come across such problems , kindly advice!
    Thank you .

    hii,
    Create a VIEW of your query in database level and then create LOV based on that VIEW.
    Regards
    PS

  • Dynamic LOV problem

    I have an application where a person gets an ID code and then fills out many questionnaires, which I'm building using Portal forms. I have a table that tracks what questionnaire has been filled out by filling in a field of the data the questionnaire was completed, e.g.:
    ID Q1Date Q2Date Q3Date Q4Date.......Q99Date
    I'd like to use a dynamic LOV for the ID field, so that instead of typing in the ID, the person can just pick their ID from a list. I could build LOVs based on a select statement like this:
    select id from idtable
    where Q1Date is null;
    But that's a lot of LOVs because I have 99 questionnaires (or it just seems like it). I tried getting around this by putting in a field on the questionnaire table that
    contains the name of the association field from idtable; so that Questionnaire1 has a field "form" that contains the value 'Q1Date'. Then I built an LOV called LOV_ID based on this select statement:
    select id from idtable
    where :l_form is null;
    Then, in the form wizard, for the ID field, I selected Combobox for the ID field, picked LOV_ID for the LOV, and picked the field "form" in the "pick the bindings for the bind variable" area.
    The problem is that the LOV doesn't refresh when a questionnaire is entered; if you enter one for ID1, for example, the LOV still shows ID1.
    Is what I want to do even possible? If so, what am I missing in building this LOV?
    Thanks much for any help, even telling me "give it up", helen

    Hi Helen,
    I understood that you have two LOVs, based on SQL queries of two tables.
    One of them depends on the other, which means that it contains a bind variable, which in the form is bound to the value of the other one.
    Using this construct, the portal forms editor automatically sets up the event handler 'onChange' of the 'Master' LOV to refresh the page when a specific value is selected. You can see this in the editor in the last section of the form field's property page.
    During the refresh, the value of the 'Master' LOV is passed to the bind variable of the 'Detail' LOV, so that in your case I think it then displays a subset of result data enclosed by the WHERE condition.
    Did I get this right so far? Is your problem that the 'Detail' field doesn't refresh on Change of the 'Master'? In that case I would quickly try to build the form again, because that should definitely work.
    I have used this mechanism shortly in an application i built, and it worked perfectly for me.
    For the use of JavaScript (or more precisely Microsoft JScript) i can recommend using Microsoft's Library at http://www.msdn.com . The 'Web Development' part contains a complete and detailed reference on all HTML elements and their properties, plus the Internet Explorer's JavaScript DOM.
    Hope to read from you soon,
    Felix

  • Dynamic LOV refresh problems

    I have a project site LOV that is set up to only show the sites relating to a particular client. The client is a dynamic LOV as well. Once the Client has been selected and the page/region refreshes the sites LOV should have the possible choices for the client showing. The code is fine as it has worked and I have got it working again but I had to change a lot of settings in the item linked to the LOV. I have a couple duplicate development apps that both work but the settings in the items are different. My question is what is the correct setting?
    Sorry if the post seems confusing.
    cheers
    Ian

    Hello
    If I understand your problem well, you are using a form based on a database table. The way it works is this: everytime the page is displayed, the database values corresponding to the record being displayed are fetched from the database (this is the setting "always - replacing any value in the session state"). This is correct as you want the page to display the most up-to-date information from the DB.
    Hence, when you submit the page in order to refresh the second LOV, that rule applies and you lose the value you just changed in the client field and things get messed up.
    Do you have this problem creating a new record or updating an existing one? I think this could work if you are creating a new record, as there is no DB values to overwrite the local values, but I am not sure if this can work if you are updating a record.
    Usually people use a "ajax" LOV refresh so the page does not need to be submitted.
    I hope this makes sense...
    Luis

  • Dynamic LOV - Function returning LOV query

    Hi All,
    For some reason I can not write a generic LOV query and want to edit where clause dynamically. Is there a way to achieve it.
    My LOV query will be
    'SELECT D,R FROM LOV WHERE ID IN (1,2,3)' for one person and
    'SELECT D,R FROM LOV WHERE ID IN (4,5,6)' for another person.
    Here entire string "1,2,3" or "4,5,6" is from a page item say :P1_ID_LIST and I can not use the bind variable like 'SELECT D,R FROM LOV WHERE ID IN (:P1_ID_LIST)'.
    If I have the option of function returning the LOV query I can use
    return 'SELECT D,R FROM LOV WHERE ID IN (' || :P1_ID_LIST || ')'
    Does there a way to acheive in Apex?
    Thanks
    Balaji

    See Re: Search on a typed in list of values for at least part of the answer.
    Scott

  • Problem with a Display Only field based on a dynamic LOV

    I have a field/item which is based on a dynamic LOV:
    select DESCRIPTION display_value, STATUSID return_value
    from CTCXFRREQS_STATUS_LOV
    order by 1
    ...and I need it to be display-only on the page. However, if I make it a display-only field, the return value is displayed, not the display value. If I change it to be a select list field, the display value is shown, as I expect and need.
    The field was based on a static LOV before, and it worked perfectly then.
    Has anyone seen this before, and have any suggestions on how to work around it?

    Hi,
    In edit item
    Display As: Display Only
    Save Session State: Yes
    Based On: Display Value of List of Values
    Named LOV: YOUR_LOV
    Regards,
    Kartik Patel
    http://patelkartik.blogspot.com/
    http://apex.oracle.com/pls/apex/f?p=9904351712:1

Maybe you are looking for