PL/SQL select list from query

Hello,
I am trying to modifying a PL/SQL process. Wherever there was a reference to the Application ID, I wanted to change it to refer to the Application Alias.
Here is the original code:
declare
   cursor app_cur is
      select aa.application_id||' - '||aa.application_name app_name,
             aa.application_id
        from apex_applications aa
       where exists (select 1
                       from profiles p
                      where p.application_id = aa.application_id);
   cursor user_app_cur (p_user number, p_app number) is
      select to_char(profile_id)
        from user_app_profiles
       where user_id = p_user
         and application_id = p_app;
   v_profile   varchar2(10);
   v_count     number := 0;
   v_class     varchar2(15);
begin
   htp.p('<table class="t3standardalternatingrowcolors" cellpadding="0" cellspacing="0">');
   htp.p('<tr><th class="t3header" >Application</th><th class="t3header" >Profile</th></tr>');
   for app in app_cur loop
      v_count := v_count + 1;
      if mod(v_count,2) = 1 then
         v_class := 't3dataalt';
      else
         v_class := 't3data';
      end if;
      open  user_app_cur(:P3_USER_ID, app.application_id);
      fetch user_app_cur
       into v_profile;
      if user_app_cur%notfound then
         v_profile := 'NONE';
      end if;
      close user_app_cur;
      htp.p('<tr><td class="'||v_class||'">'||app.app_name||
            '</td><td class="'||v_class||'">'||
            apex_item.select_list_from_query(40, v_profile,
              'select description, profile_id from profiles where application_id = '||app.application_id,
           null, 'YES', 'NONE', 'No Profile Assigned', null, null, 'NO')||
            apex_item.hidden(41,app.application_id) ||
          '</td></tr>');
   end loop;
   htp.p('</table>');
end;Here is my revised code:
declare
   cursor app_cur is
      select aa.alias||' - '||aa.application_name app_name,
             aa.alias
        from apex_applications aa
       where exists (select 1
                       from profiles p
                      where p.application_alias = aa.alias);
   cursor user_app_cur (p_user number, p_app varchar2) is
      select to_char(profile_id)
        from user_app_profiles
       where user_id = p_user
         and application_alias = p_app;
   v_profile   varchar2(10);
   v_count     number := 0;
   v_class     varchar2(15);
begin
   htp.p('<table class="t3standardalternatingrowcolors" cellpadding="0" cellspacing="0">');
   htp.p('<tr><th class="t3header" >Application</th><th class="t3header" >Profile</th></tr>');
   for app in app_cur loop
      v_count := v_count + 1;
      if mod(v_count,2) = 1 then
         v_class := 't3dataalt';
      else
         v_class := 't3data';
      end if;
      open  user_app_cur(:P3_USER_ID, app.alias);
      fetch user_app_cur
       into v_profile;
      if user_app_cur%notfound then
         v_profile := 'NONE';
      end if;
      close user_app_cur;
      htp.p('<tr><td class="'||v_class||'">'||app.app_name||
            '</td><td class="'||v_class||'">'||
            apex_item.select_list_from_query(40, v_profile,
              'select description, profile_id from profiles where application_alias = '||app.alias,
           null, 'YES', 'NONE', 'No Profile Assigned', null, null, 'NO')||
            apex_item.hidden(41,app.alias) ||
          '</td></tr>');
   end loop;
   htp.p('</table>');
end;Here is the error:
ORA-06550: line 1, column 153: PL/SQL: ORA-00904: "F109NEWNAME": invalid identifier ORA-06550: line 1, column 7: PL/SQL: SQL Statement ignored
I think that the problem is in the table/LOV generation near the end, but I don't fully understand the apex_item.select_list_from_query function as it is written (I didn't write it).
Any help is greatly appreciated.
Thanks,
Matt

Hi Matt,
This line:
'select description, profile_id from profiles where application_alias = '||app.aliaswould become:
select description, profile_id from profiles where application_alias = F109NEWNAMEif F109NEWNAME was the app_alias. SQL would see F109NEWNAME as a variable as it is not in quotes. Therefore, you should change the line to:
'select description, profile_id from profiles where application_alias = ''' || app.alias || ''''to end up with:
select description, profile_id from profiles where application_alias = 'F109NEWNAME'which would make more sense
Andy

Similar Messages

  • Display select list from query on manual tabular form

    Hello,
    I'm trying to display a select list from query on a manual tabular form. I'm using a collection to store the data. I can't seem to get the query to work. I can display the item as a text item. Any help would be appreciated. Thanks, Elizabeth.
    SELECT
    -- Notice how I'm keeping the idx value the same as the column value in the collection. This helps to keep things organized
    -- I also apply an id to each entry
    -- I append the error value to the empname and sal
    -- The Seq_id. Usefull when hiding rows (for delete) and then submitting from
    apex_item.hidden(1,x.seq_id, null, x.seq_id || '_seq_id') ||
    -- The Primary Key of the column
    apex_item.hidden(2, x.ceah_people_id, null, x.seq_id || '_ceah_people_id') || x.ceah_people_id ceah_people_id,
    -- Employee Name
    case when x.seq_id = -1
    then
    apex_item.select_list_from_query (3,
    NULL,
    'select distinct language_name d, '
    || 'language_id r from foreign_language',
    'style="width:170px" ' ,
    'YES',
    '0',
    '- Select Language -',
    'x.seq_id_' || LPAD (9900 + LEVEL, 4, '0'),
    NULL,
    'NO'
    else
    apex_item.text (3,(select language_name from foreign_language where x.language_id = foreign_language.language_id),
    80,
    100,
    'style="width:170px" readonly="readonly"',
    'f32_' || LPAD (ROWNUM, 4, '0')
    end
    || err.language_id language_id,
    /* apex_item.text(3,x.language_id,null, null, null, x.seq_id || '_language_id') || err.language_id language_id,
    -- Employee Salary
    apex_item.text(4,x.proficiency, null, null, null, x.seq_id || '_proficiency') || err.proficiency ||
    -- Store the sql action type as well.
    apex_item.hidden(50,x.sql_action_typ, null, x.seq_id || '_sql_action_typ_id') proficiency,
    -- Last but not least the row error
    err.row_error
    FROM (SELECT ac.c001 seq_id,
    ac.c002 ceah_people_id,
    ac.c003 language_id,
    ac.c004 proficiency,
    ac.c049 modifiable_flag,
    ac.c050 sql_action_typ
    FROM apex_collections ac
    WHERE ac.collection_name = 'DATA_COLLECTION'
    ORDER BY ac.seq_id) x,
    -- Error Collection
    (SELECT ac.seq_id seq_id,
    ac.c002 ceah_people_id,
    ac.c003 language_id,
    ac.c004 proficiency,
    ac.c050 row_error -- Useful when individual data is correct, however the row of data is not. Ex: start/end dates
    FROM apex_collections ac
    WHERE ac.collection_name = 'ERROR_COLLECTION'
    ORDER BY ac.seq_id) err
    WHERE x.seq_id = err.seq_id(+)

    I got so frustrated I started over. I'm following the how to create a manual form.
    http://www.oracle.com/technology/products/database/application_express/howtos/tabular_form.html#MANUAL
    The problem I'm now having is even though I display items as hidden, there is a column holder on the report for them. If I go into the report attributes and toggle the show attribute off I cannot reference an items value in my logic. I used /&nbsp/ for the column heading but I still get the little sort arrow where the column heading should be. I tried to toggle the sort attribute off but the sort arrow still shows up. How can I use the apex_item.hidden and not get a place holder for the column on a report? Thanks, Elizabeth
    Here is the code I'm using to generate the report:
    select x.ceah_people_lang_id,
    x.language_id,
    x.proficiency,
    x.ceah_people_id
    from (
    select apex_item.hidden(1,ceah_people_lang_id) ceah_people_lang_id,
    apex_item.select_list_from_query(2,language_id,'select language_name, language_id from foreign_language') language_id,
    apex_item.select_list_from_query(3,proficiency,'select name, id from proficiency') proficiency,
    apex_item.hidden(4,ceah_people_id) ceah_people_id
    from ceah_people_language where ceah_people_language.ceah_people_id = :P152_person_id
    union all
    select apex_item.hidden(1,null) ceah_people_lang_id,
    apex_item.select_list_from_query(2,null,'select language_name, language_id from foreign_language') language_id,
    apex_item.select_list_from_query(3,null,'select name, id from proficiency') proficiency,
    apex_item.hidden(4,null) ceah_people_id
    from dual) x

  • Select list from query in report

    Hello everybody,
    I want to include a select list from a query in a report's colomn, but the select list should only be displayed conditionally. I wanted to do this with the help of "case when" in the corresponding SQL statement.
    The select list itsself works, but when I combine it with "case when" I always get the error message:
    ORA-01427: single-row subquery returns more than one row
    The select statement is as following:
    select
    htmldb_item.checkbox(1,rownum) " ",
    x.idee,
    x.stunden_ilp,
    x.stunden_ild,
    x.stunden_ilm,
    x.stunden_ief,
    x.stunden_ir,
    x.pe_id,
    x.l_art_id,
    x.version_id
    from (
    select
    (select case
    when (select name from cn_pl_projektidee s01
    where s01.idee_id = '2') IS NULL then
    (select distinct htmldb_item.select_list_from_query(5,name,'select distinct name from cn_pl_projektidee') name from cn_pl_projektidee s01
    where s01.idee_id = t1.idee_id)
    else
    (select distinct htmldb_item.text(5,name) name from cn_pl_projektidee s01
    where  s01.idee_id = t1.idee_id)
    END from cn_pl_std_peplanung t1) Idee,
    from cn_pl_std_peplanung t1, cn_pl_projektelemente z1, cn_pl_version u1, cn_pl_projektidee s1
    where t1.version_id = '&P6_VERSION_WAHL.'
    and t1.pe_id ='&P6_HELP_PRODET.' 
    and t1.l_art_id ='&P6_L_ART_ID.'
    group by t1.pe_id, t1.version_id, t1.idee_id, t1.l_art_id) x
    order by x.ideeDoes anybody know what could be the problem or what other solutions I could try??
    Greetings!
    Patrick

    Found 2 ways to solve it:
    *1. dynamic action (JQuery)*
    $("#f20_1234 option[value=13]").attr('selected', 'selected');
    *2. process*
    BEGIN
    HTP.p('<script type="text/javascript">');
    --HTP.p('problem()');
    HTP.p('html_SetSelectValue(''f20_903'',188)');
    HTP.p('html_SetSelectValue(''f20_903'',189)');
    HTP.p('</script>');
    END;

  • A select list from query question

    Hello all - I've looked in detail at a great deal of posts on this subject and believe what I am trying to achieve is not unusual or out of scope. Therefore it's likely me mis-interpreting something and I'd be grateful for anybody's input.
    I have the following as a column in a report
    apex.select_list_from_query( 21,
              a.reserved_by,
              'select g.user_name,g.user_id
              from users g, user_roles h
         where g.user_id=h.user_id and h.role_id in (2,3)'
         , null ,
         'YES',
         '-1',
         '- Not Reserved -') slov1 ,
    If 'reserved_by' is null, I want '- Not Reserved -' to appear in the select list, otherwise I want the value in user_name. Where reserved_by is not null, I get the appropriate user_name returning the appropriate user_id. Where reserved_by is null, I get null returning null in the select list.
    '- Not Reserved -' which is the value I've tried to assign to p_null_text, also appears in the select list and returns '-1' . However '-Not Reserved-' only appears as an extra option, rather than becoming the display value for reserved by=null.
    So, if the values in reserved_by are 'user1','user2' and null and the P_query returns
    'user1',1
    'user2',2
    'user3',3
    my select list for the row having reserved_by=NULL looks like
    user1
    user2
    user3
    - Not Reserved -
    NULL (ie blank).
    Following a suggestion in a thread from 2005(!), I changed the p_query to
    'select g.user_name,g.user_id
    from users g, user_roles h
    where g.user_id=h.user_id
    and h.role_id in (2,3) union ALL
    SELECT ''- Not Reserved -'' user_name, 0 user_id from dual',
    null, NO'
    and set p_show_null to 'NO'. This achieves the functionality I want. So perhaps, though I can't figure out what I was doing wrong with the 'correct' usage. Anyway, I'll post this in case it proves useful to others!
    Toby

    Hi Apex Experts,
    can some one suggest me an alternate way to achieving this. I really have no idea on how to take this forward. :(
    Any help/pointers will be highly appreciated.
    Thanks,
    Satya.
    Edited by: Chaitu_Apex on May 13, 2010 3:50 AM

  • Trouble using pipelined function in an select list lov query

    I'm trying to use a pipelined function in a select list lov query but i cet the error
    "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."
    my query is as follows :
    SELECT gt.navn d, gt.GEOGRAPHY_TYPE_ID r
    FROM GEOGRAPHY_TYPE gt
    WHERE gt.kode NOT IN (1)
    and gt.kode in (select lov_value from table(RAPPORT_FILTER_PKG.GET_RAPPORT_FILTER_VALUE_PIP (
    SYS_CONTEXT ('rapport_filter_ctx','filter_id'),'GEOGRAPHY_TYPES')) )
    ORDER BY gt.navn DESC
    if i use a discrete values '80' instead of the call to
    SYS_CONTEXT ('rapport_filter_ctx','filter_id')
    i don't get eny errors, but then the LOV isn't as dynamic as i has to be
    any idears???
    Edited by: [email protected] on Dec 1, 2008 8:50 AM
    Edited by: [email protected] on Dec 1, 2008 11:17 AM

    nope that doesn't do it either
    contains a syntax errror at
    SYS_CONTEXT (('rapport_filter_ctx',:P500_RAPPORT_FILTER_ID),'GEOGRAPHY_TYPES'))
    my theory is that it's got something to do with the way APEX binds values because
    the query
    SELECT gt.navn d, gt.GEOGRAPHY_TYPE_ID r
    FROM GEOGRAPHY_TYPE gt
    WHERE gt.kode NOT IN (1)
    and gt.kode in (select r from table(RAPPORT_FILTER_PKG.GET_RAPPORT_FILTER_VALUE_PIP ('80','GEOGRAPHY_TYPES')) )
    ORDER BY gt.navn DESC
    works fine in both TOAD and in APEX but as soon as i replace th '80' with :P500_RAPPORT_FILTER_ID then, apex won't accept the code??????
    Edited by: [email protected] on Dec 3, 2008 7:54 AM

  • Blocking Session -  blocked SQL - SELECT SYSDATE   FROM SYS.DUAL

    Oracle 10.0.0.4g
    When database execute some big and long queries/operations my system is slow and some users wait, can’t work (they work with some Oracle forms applications ) because I often have blocking session.
    I found up that this blocking sessions block only this query of another user:
    SELECT SYSDATE   FROM SYS.DUAL
    Or:
    +10-АВГ-2009 08:51:10 User X1 ( SID= 222 ) with the statement: SELECT ... is blocking the SQL statement on Y1 ( SID=333 ) blocked SQL -> SELECT SYSDATE FROM SYS.DUAL+
    When I kill one of the blocking session another session take his place and do the same:
    +10-АВГ-2009 08:53:10 User X2 ( SID= 444 ) with the statement: SELECT ... is blocking the SQL statement on Y2 ( SID=555 ) blocked SQL -> SELECT SYSDATE FROM SYS.DUAL+
    When long queries finished everything is OK.
    Please Help Me!!!

    I create ASH report:_
    Top User Events
    Avg Active
    Event Event Class % Activity Sessions
    enq: TM - contention Application 55.87 0.96
    db file sequential read User I/O 18.87 0.32
    CPU + Wait for CPU CPU 16.33 0.28
    db file scattered read User I/O 3.02 0.05
    Top Event P1/P2/P3 Values
    Event % Event P1 Value, P2 Value, P3 Value % Activity
    Parameter 1 Parameter 2 Parameter 3
    enq: TM - contention 55.87 "xxxxxxxxxxxxxxxxxxxx" 38.35
    name|mode object # table/partition
    "1111111111","xxxxxxx","0" 17.44
    db file sequential read 19.21 "xxxxxxxxxxxxxxx’’ 0.00
    file# block# blocks
    db file scattered read 3.03 "xxxxxxxxxxxxxxxxxxxxxx’’ 0.01
    file# block# blocks
    Top SQL Statements …………..
    SQL ID Planhash % Activity Event % Event
    fnxxxxxxxxx N/A 25.09 enq: TM - contention 23.47
    ** SQL Text Not Available **
    N/A 25.09 db file sequential read 1.19
    ** SQL Text Not Available **
    byxxxxxxxxxxxxx 1111111 10.11 enq: TM - contention 7.43
    SELECT SYSDATE FROM SYS.DUAL
    db file sequential read 2.10
    fnxxxxxxxxx 11111111111 2.57 enq: TM - contention 2.16
    ** SQL Text Not Available **
    Top DB Objects
    Object ID % Activity Event % Event
    Object Name (Type) Tablespace
    11111 10.33 enq: TM - contention 10.30
    XXXXXXXXXXXXXXXXXXXXXXXX (INDEX) CC
    99999 10.18 enq: TM - contention 10.16
    XXXXXXXXXXXXXXXXXXXXXXXXX (INDEX) IND
    933333 6.67 enq: TM - contention 6.55
    FFFFFFFFFFFFFFFF (TABLE) T3
    114545 3.88 enq: TM - contention 3.85
    RRRRRRRRRRRRRRRRRRRRRR (INDEX) JJJ
    1136664 2.96 enq: TM - contention 2.93
    FFFFFFFFFFFFFFFFFFFFFFFFF (INDEX) G
    How to found sql text that is not available ** SQL Text Not Available **?
    What to do whit this Top DB Objects that have enq: TM - contention event?
    And how to solve this problem?

  • Populate Select List from Checkboxes?

    How do I populate a Select List from a checkbox set's checked display values and submitted values?
    I'm guessing I need to parse the colon-delimited values, but I have no idea how to get the display values, or how to put all of that into the Select List.
    Any ideas?
    Cheers,
    Ben

    Hello,
    Every select list item can be based on LOV. You can read more about it in here - http://download-uk.oracle.com/docs/cd/B31036_01/doc/appdev.22/b28550/bldapp.htm#CHDFGFHI
    If you are trying to populate a select list, using JavaScript, you can see a good example in here - http://htmldb.oracle.com/pls/otn/f?p=11933:37
    Hope this helps,
    Arie.

  • Populating a SELECT list from an Oracle Table

    Hello,
    I would like to populate a second SELECT list on
    a web page based on the selected value in the first
    SELECT list. I would like to take the value
    that the user selects in the first SELECT list and
    use it in a WHERE clause to bring back distinct
    values to display in the second SELECT list.
    I would like to do this all on a single page. As
    soon as the user selects a value in the first SELECT
    list, then the correct values retrieved from the
    database would appear in the second select list.
    Is this possible? Do you have sample code or ideas??
    I can write JavaScript to get the selected value, but
    I cannot get to Oracle data from the JavaScript environment.
    I can write PL/SQL or Java procedure to access
    Oracle data, but I cannot make the complete connection.
    Help, please.
    thanks
    paul

    Unless you can get every combination back in the first SQL statement, you'd have to do something along the lines of
    - Have the JavaScript submit the page as soon as the first pull-down is selected
    - Have the response be a page identical to the first page, but with the second pull-down populated.
    The other option would be to have a Java applet that can make the second query and return results. Since applets can't connect to the database by default, you'd have to have an app server that would do the actual query.
    Justin
    Distributed Database Consulting, Inc.
    www.ddbcinc.com/askDDBC

  • HTMLDB 2.0 bug - tabular forms - select list from named LOV

    Hi!
    Changing a column in a tabular form to 'select list (named lov)' gets the following error in HTMLDB 2.0 when you try to add a row (to an empty table in my case):
    PL/SQL error at column 133.
    Create a table and then create a tabular form on it. Then change a report column to be a 'select list (named lov)'. Save and run the form and the error occurs.
    Thanks!
    Dave Venus

    Brian,
    This example:
    http://htmldb.oracle.com/pls/otn/f?p=31517:176
    and this example:
    http://htmldb.oracle.com/pls/otn/f?p=31517:160
    may help you.
    Denes Kubicek
    http://deneskubicek.blogspot.com/
    http://www.opal-consulting.de/training
    http://apex.oracle.com/pls/otn/f?p=31517:1
    -------------------------------------------------------------------

  • How to write a PL/SQL select list with submit page?

    Let's we need some select list that are related with each other. I wrote such a code.
    declare
    gn_start_id number := 0;
    glabel1 VARCHAR2(100) := 'Group ';
    glabel2 VARCHAR2(100) := 'Property';
    begin
    htmldb_application.g_f01(1) := 100;
    htp.p('<BR>');
    htp.p
    ( glabel1 || ' : ' ||
         htmldb_item.select_list_from_query
         p_idx => 1,
         p_value => '--Select a value--',
         p_query => 'SELECT m.vproperty, m.NMAP_PK_ID
              FROM table m
              WHERE m.ngroupid = ' || to_char(gn_start_id),
         p_show_null => 'NO',
         p_null_value => 0)
    htp.p('<BR>');
    htp.p
    ( glabel2 || ' : ' ||
         htmldb_item.select_list_from_query
         p_idx => 2,
         p_value => '--Select a value--',
         p_query => 'SELECT m.vproperty, m.NMAP_PK_ID
              FROM table m
              WHERE m.ngroupid = ' || to_char(htmldb_application.g_f01(1)),
         p_show_null => 'NO',
         p_null_value => 0)
    end;
    However, I am not able to submit page automaticly, when user select a value from the select list?
    How can I do this? Thankz

    I found such a solution.. thanks
    htp.p('</TD><TD>');
    htp.formselectopen(cname => 'v_status', cattributes => 'class="ddl" onChange="javascript:update_status(this.value)"');
    FOR rec IN cur_status LOOP
    IF rec.status_id = v_status THEN
    htp.formselectoption(cvalue => rec.status_name, cattributes => 'value="' ||
    rec.status_id || '"', cselected => 'TRUE');
    ELSE
    htp.formselectoption(cvalue => rec.status_name, cattributes => 'value="' ||
    rec.status_id || '"');
    END IF;
    END LOOP;
    htp.formselectclose;

  • SQL Select and From Functions

    Can sql aggregate functions be added to an interface select clause and from clause.
    I want to have a datasource where one of the columns is an aggregate such as a count, which would need the ability to indicate a from clause function group by, or having by. In the Designer Diagram tab for the interface, it seems you can only apply sql functions to where clause joins or filters.
    I want to have a query such as follows as my datasource
    select columnA, count(*) as thecount
    from table x
    group by columnA
    order by thecount asc
    and ultimately
    select columnA, thecount
    from (select columnA, count(*) as thecount
    from table x
    group by columnA
    order by thecount asc)
    where rownum <1001
    Can this be done in the ODI Designer, without creating a physical custom view on the database?

    Hi lpantuso,
    Aggregate functions are added by ODI automatically. In this case you would want mappings like this:
    TARGET_COL_1: columnA
    TARGET_COL_2: count(*)
    ODI will generate something like this:
    select     
       columnA,
       count(*)
    from     MY_TABLE MY_TABLE
    where     
         (1=1)
    Group By MY_TABLE.columnA
    The subselect, however, isn't handled out of the box. In general ODI isn't quite as friendly with ordering clauses since order by is not relational. (Sets aren't ordered.) To get only the first 1000 columnA values, you'll probably need to create a view or break it into 2 separate interfaces.
    Regards,
    Matt

  • Selecting Randoms from Query of Queries

    I can create a query that selects random records
    <cfquery....>
    select top 10 * from table order by newid() <!--- SQL
    Server --->
    </cfquery>
    or
    <cfquery....>
    select top 10 * from table order by rand() limit 10 <!---
    MySQL--->
    </cfquery>
    However, is there a way to cache a query then select random
    records from it?
    I want to cache the overall query that retrieves all the
    records, then
    randomly pull
    from that cached query.
    If I use newid() or rand(), the query bombs on the
    parentheses.
    Any suggestions?
    Tami

    well, it's not really a query of queries... more like a query
    of a cached
    query :)
    "DixieGal" <[email protected]> wrote
    in message
    news:ffsn1b$***$[email protected]..
    |I can create a query that selects random records
    | <cfquery....>
    | select top 10 * from table order by newid() <!--- SQL
    Server --->
    | </cfquery>
    |
    | or
    | <cfquery....>
    | select top 10 * from table order by rand() limit 10
    <!--- MySQL--->
    | </cfquery>
    |
    | However, is there a way to cache a query then select random
    records from
    it?
    | I want to cache the overall query that retrieves all the
    records, then
    | randomly pull
    | from that cached query.
    |
    | If I use newid() or rand(), the query bombs on the
    parentheses.
    |
    | Any suggestions?
    |
    | --
    |
    | Tami
    |
    |

  • SQL select group by Query

    Suppose a table T1 has 2 columns C1 and C2 and data as follows:
    C1 C2
    == ==
    1 A1
    1 A2
    2 B1
    2 B2
    2 B3
    3 C1
    4 D1
    4 D2
    I want to write a SQL query to select data and display as follows (i.e. grouped by C1, but C2 should display as single field with say '-' seperator):
    C1 C2-Details
    == ========
    1 A1-A2
    2 B1-B2-B3
    3 C1
    4 D1-D2
    Please help.
    Thanks in advance
    Goli

    Your query maybe like this
    SELECT c1,
    LTRIM(MAX(SYS_CONNECT_BY_PATH(c2,'-'))
    KEEP (DENSE_RANK LAST ORDER BY curr),'-') AS employees
    FROM (SELECT c1,
    c2,
    ROW_NUMBER() OVER (PARTITION BY c1 ORDER BY c2) AS curr,
    ROW_NUMBER() OVER (PARTITION BY c1 ORDER BY c2) -1 AS prev
    FROM t1)
    GROUP BY c1
    CONNECT BY prev = PRIOR curr AND c1 = PRIOR c1
    START WITH curr = 1;

  • LOV an SQL : how to configure a select list to get all records

    Hello,
    I am using Oracle 10g with APEX 2.0.
    Here is my question:
    I have a report and I am using 3 text fields and a select list to search through a join of two tables. The select list is composed of a "list of values" and the parameter, which is used in the SQL-sentence, has a numeric value.
    Result table after the join operation looks like this:
    Field1 Field2 Field3 Field4 (By assuming the field3 is the one which used in the select list.)
    21a this 1000 bn
    21a that 1001 vb
    33c thus 1012 ct
    What I want to do is to set another parameter-value pair in the select list to let user choose the "ALL" of the mentioned items in the select list so that the search will return all the records without having taken this select list-field into consideration.
    Is it possible to do it with LOV and SQL? Do I need any other functions? or configurations?
    Thanks in advance,
    Sedef

    Hi user630478!
    I always use a select list with submit and the option to get a NULL-Value for such things. To solve your problem do the following things:
    1.) Create two named LOVs. One as you already did and another one for all values.
    2.) Your select list with submit should be configured to show a NULL-Value e. g. it shows ALL with the value 0.
    3.) Create two conditional branches that work together with your select list. One that show the normal results if a user has clicked on a normal value and the second should act only if a user has clicked on ALL.
    4.) Write a process that switches the LOVs in your select list from one to the other. This process should only be fired if the second conditional branch has been actived.
    Maybe if I understood right that's what you want to know.
    yours sincerely

  • How to default a value in a select list

    Hi
    I have an item on the page which is displayed as a select list.
    The select list has an lov that returns 3 values as follows:
    ACAD1M
    ACAD2H
    ACAD3T
    the sql for this lov is as follows:
    select CAL_TYPE d,cal_type r
    from igs_ca_type
    where s_cal_cat='ACADEMIC'
    It needs to return the values in the order as shown above, however if the user does not select anything from the select list, I want it to default to the value in the middle of the list(ACAD2H)
    I tried using default on the item but I could not get this to work.
    Could someone explain how I can get the select list in HTMLDB to default to the value that I want regardless of which position it appears in the select list it always seems to default to the value at the top of the list.

    Hello Kay,
    A default value for a select list must be set to a legitimate returned value from the select list LOV query.
    The default value should be set in the item "Default" section. In the "Default Value" field you should enter your query – in a form of a PL/SQL Function Body – and set the "Default Value Type" field accordingly.
    The following is an example of code I'm using to set the default value of a select list to be the first displayed option (set by the user, and recorded in the dispord column):
    declare
      l_sno  number;
    begin
      select sno
      into l_sno
      from mis_mess_users
      where dispord = (select min(dispord)
                     from mis_mess_users);
      return l_sno;
    end;Using the same principle, you can use any query that will give you the result you need.
    Regards,
    Arie.

Maybe you are looking for