Using select list value as column name in SQL

Folks,
Thanks in advance for any help with this
I have a select list with two values (Instance and Username) created by
STATIC2:Username;USERNAME,Instance;INSTANCE
I am trying to pass the value of this (:P2_SELECT) and use it as a column name in a SQL query as below
select USERNAME,
INSTANCE
from table_name
where :P2_SELECT like '%'||:P2_TEXTSEARCH||'%'
When I substitue the :P2_SELECT for one of the values (either instance or username) this works fine
I suspect it is due to how Application Express interprets the value of :P2_SELECT
Any help would be much appreciated!
Gareth

Thanks Munky that worked a treat!
The next hurdle I have now is that because I have changed the region type to "PL/SQL Function(returning SQL Query)" there is no longer the option to add sorting to the columns as I have had to change the Source option to "Use Generic Column Names (parse query at runtime only)"
I will have a scout around and see how I can get around this
Gareth

Similar Messages

  • Need to use Select List value as column name

    I want to have a WHERE ? IS BETWEEN ? AND ? clause.
    I am using the PL/SQL Query returning a SQL Query as a report. This uses bind variables for items I had set on my form..... If I hardcode something like:
    'WHERE STARTDATE IS BETWEEN '||
    'TO_DATE(:P1_START,''dd-MON-YYYY HH24:MI'') AND '||
    'TO_DATE(:P2_END,''dd-MON-YYYY HH24:MI'')';
    I have no problem, but I have 2 date columns, STARTDATE and ENDDATE, and would like to use the value in a select list and not have to hardcode "STARTDATE" in there. I have not been able to do this, does anyone know how to use a bind variable as a column name? From reading some posts I think it might not be possible.

    Heather,
    You're on the right track, just glue in the column name so that it becomes part of the returned query string from the function (...'WHERE '||:COLNAME||' IS BETWEEN '|| ...).
    Note that the bind variable is not part of the returned query string, but the column name obtained from the bind variable when the function executes does become part of the query string.
    Scott

  • Using Select List value for building report

    I have an interactive report form. I have a "After Header" (LOAD) process that run sql commands that will populate a table with the data that the report needs for a given week.
    I have a Select List item that is run as a "Before Header" that gets a list of dates from a table. The dates only contain the first day of the week for the past two years. It is called "WEEK_OF" table and the column is called "WEEK_OF_DATE".
    The default value for the Select List is the first day of the current week. And then all of the first day of the week from the WEEK_OF table.
    I would like the LOAD process to use the value in the Select List. So at start up I would like the List to show the current week and report to begin with data from the current week.
    So I have tried to use the variable :WEEK_OF_DATE (Item name) as the beginning date for the report. However :WEEK_OF_DATE is null.
    Also, after I have the report displayed, I would like to select a new date from the list and have the report automatically refresh with that new data.
    Any Ideas what I am doing wrong?

    Hi Lyle,
    When setting a default value for a select list that is to be used to filter a report, I have found it best to do that using a computation, conditional on the item being NULL and running Before Header. If other computations rely on this value, then it should have the lowest sequence number to ensure that the value is available for those.
    Andy

  • Refresh PL/SQL Report Region (not Page) using Select List value

    Hi,
    I've got a report region based on a 'PL/SQL function body returning a SQL query'which gets generated on selecting a value from a Select list item, The Select List action is 'Redirect and Set value' but this causes the whole page to refresh rather than just the report region. I've tried to refresh the report only using a dynamic action on the Select List item (Action now reset to  'None') but now the report is not appearing on choosing from the List. Can anyone suggest a solution that will allow me to refresh this report without refreshing the page? I am using APEX 4.2.2 and the report syntax is as follows:
    DECLARE
      v_statement VARCHAR2(500);
    BEGIN
      SELECT query_text
        INTO v_statement
       FROM sql_queries
       WHERE query_id = :P2_QUERY ;
       RETURN v_statement ;
    END ;
    where P2_QUERY is Select List Item,
    regards,
    Kevin.

    KevinFitz wrote:
    The report region being displayed is conditional on P2_QUERY item being NOT NULL. I assume the region not appearing is because the Action for the Select List Item is set to None and so P2_QUERY is always NULL.
    No, the region is not appearing because it is conditional on P2_QUERY being NOT NULL. This means that the report region never exists on the page shown in the browser, so it can't be dynamically refreshed. (Dynamic refresh doesn't evaluate region conditions, and it only re-renders the report content, not the entire region.)
    Remove the condition on the report region, check the refresh is working, then reconsider exactly what the requirements here are. If you want the region to appear only when P2_QUERY has a value, and you want it to be refreshed without submitting and re-rendering the page, then the region needs to be hidden rather than conditionally rendered, and shown via a dynamic action when P2_QUERY gets a value.
    I tried adding an additional Set Value True Action for the DA event but got an error as listed above,
    All irrelevant if Page Items to Submit on the region is used properly.

  • Using select list as default value in tabular form.

    Hi,
    I am using Application Express 4.1.0.00.32. I have two questions that are related.
    I have a Select item *'P1_SELECT'* and a tabular form My Items.
    Question 1. The My Items tabular form col1 Attributes are set Display As Text Field, and the Tabular Form Attributes are set Default Type = item(application or page item name), Default = P1_SELECT. I have checked the session state value is set on P1_SELECT ie. Fred. What I need to know is, why, when adding a row to the tabular form My Items does col1 not display 'Fred' as the default value from the select item P1_SELECT? I can change col1 of the Tabular form to be Display as Text (save state) and this will work. However that leads me on to:
    Question 2. After adding say 3 rows to the form, I then change the select P1_SELECT value to Bob and Bob is now set in session state on the P1_SELECT item, but when I again add row to the form the value Fred is still the value not Bob. It seems that the tabular form keeps the default value as Fred and not Bob. How can I get this to look or work like:
    col1_
    Fred
    Fred
    Fred
    Bob
    Your help is needed.
    Thanks.

    Howard (DBA in Training) wrote:
    Do you submit the page or set the value after changing the selection? If not, the display value seems to be Bob but the working value is still Fred. That's what you are seeing right? In the "Settings" section, what do you have for "Page Action when Value Changed". I've been using "Redirect and Set Value" because I was staying on the same page after the selection.
    Additional info which might be helpful (or NOT). ====================
    NOTE: I am just a novice's novice with APEX and I had much agony with Select Lists. It was challenging to have the Select List value displayed because there seem to be so many different sources of the Select List value, namely:
    1) the current value in the session state
    2) the value you can specify in "Source value or expression" in the "Source" section of the Select List item
    3) the value you can specify in the "Post Calculation Compution" in the "Source" section of the Select List item
    4) the value you can specify in the "Default value" of the "Default" section of the Select List item
    [Now, if I've misdescribed any of these, remember, this is from a novice's perspective.]
    It's like putting a clock (back) together. Get any of the pieces wrong and it will probably not work right.
    I had an addiitonal challenge in that I wanted the same Select List displayed on multiple pages and for the currently selected value (from the former page) to already be set on the new page when it was displayed. What fun!
    To see what I did here: http://apex.oracle.com/pls/apex/f?p=43250:101 login Dever/Ima9Dever
    Remember, I'm doing many things you will likely not need to do. I iniitalized the Select List for the first time it displayed. I copied the Select List value from old page to new page by storing it in an application item F217_SYS_NIC_NM.
    Best wishes,
    HowardHi Howard,
    You don't have submit the page for just setting one item's session state. you can use a Dynamic Action OR use Page Items to Submit property if available (this is available in various places such as sql region,chart region etc)
    In context to this question you don't have to do any of those..just see my example above
    Thanks

  • Alternate select lists on 2 columns and return more than 1 column

    Hi,
    I try to build 2 alternate select lists and each select list should return more than 1 column
    2 Columns PART_ID and PART_SPECIFICATION
    Now I build a select list on PART_ID like
    select part_id d,part_id r from parts;
    The result should be:
    Column PART_ID has PART_ID and PART_SPECIFICATION must be text of PART_SPECIFICATION
    The other select list based on PART_SPECIFICATION should be like
    select part_specification d,part_id r from parts;
    Now it should be displayed part_specification in PART_SPECIFICATION and part_id in PART_ID.
    This is because one user knows the part_id and another knows only the specification
    Please help me
    Siegwin

    Hi Siegwin,
      Check your application Page 7(copy of page 500)  using select list instead of plugin, it gives all values.
    and works very well,
    use ajax process to get Xml data into page items
    following are changes
    application process: getData
    application item : TEMPORARY_APPLICATION_ITEM
    create one function in page html header pull_multi_value()
    and it call on page item p7_empno on html form element attribute as onchange="pull_multi_value(this.value)";
    this may Helps you,
    Pars.

  • CPY0007: Select list has fewer columns than destination table

    Hi,
    I have two table TB in both Database A and Database B. TB in Database A has 100 columns, TB in Database B appended one more column which is nullable. I'm copy TB data from A to B using something like:
    insert into TB select * from TB@A where ...
    And I got error:
    CPY0007: Select list has fewer columns than destination table.
    Besides specify the 100 columns plus one new column, any better ways to handle this?
    Thanks a lot.

    This is kind of dangerous genarally but if you know the additional column is on the end this might work.
    insert into TB select a.*, null from TB@A a where ...If this is a regular operation, I would strongly suggest biting the bullet and specifying the column names. Using desc or all_tab_columns and a simple text editor it should take no more than five minutes, which is at least 12 hours less than you have been waiting for a workaround.

  • List tables and column names a stored procedure is querying

    Hello,
    Is there a way to list tables and column names that a stored procedure is querying, i.e, selecting from, using T-SQL?  If yes, is there a way to also show data types for the columns that a stored procedure is querying, i.e, selecting from?
    Thank you,  
    Lenfinkel

    One way to view the dependencies of an object is to use SSMS; navigate to the object, right click and select "view dependencies".  However this does not tell you what columns are being referenced by the Stored Procedure.
    One way to view what is being referenced by a stored procedure is to run something like
    select
    text
    from syscomments
    where
    id in
    (select id
    from sysobjects
    where
    name
    =[Your Object Name]
    And xtype
    in
    ('p','P')
    Please click "Mark As Answer" if my post helped. Tony C.

  • How can I list all the column names of a table by programming?

    Hi,
    Now I want to write an function which has the following features:
    Firstly, The function was given a parameter as table name.
    Then, it will lists all the columns names of the table.
    e.g
    table: person
    ---firstName------lastName----+
           Michale               Jackson
    We can get the columns 'firstname' and 'lastName' by calling the function with table name 'person'.
    And I also wonder that where I can get reference book or any other materials?
    Thanks.
    Edited by: wenjing wang on Feb 15, 2008 6:42 AM
    Edited by: wenjing wang on Feb 15, 2008 6:57 AM

    hi,
    hope the below code helps u. Just take the headee which contains the field name and split it like below and compare it with the field name u want here 'last name'.
    here,
    'First name' will be in wt_filedata1 and remaining field names in wt_filedata2, so 'do' continues.
    c_tab must be the separator, either , or + or tab etc..
    CODE:
    read table person into wl_header index 1.
    do.
        split wl_header at c_tab into: wt_filedata1 wt_filedata2.
        if wt_filedata1 <> 'lastname'.
          cnt1 = cnt1 + 1.
          wl_header = wt_filedata2.
        else.
          exit.
        endif.
      enddo.
    Please reward if it is useful.
    regards,
    sri

  • Pass Select list value to URL as a parameter

    I am trying to pass the selected value from a select list via a button to a URL.
    &P_VALUE=&P_VALUE.
    P_VALUE is set to USER SESSION.
    It shows as prevous session value. If I show the the session value is not set to the selected value.
    If I call a PDF report via a button, it displays the correct value and the session values is correct.
    If I select the button for the URL again, is shows the previous value.
    When I go back to the form and call select the button again, the correct parameter is passed to the URL.
    Any Ideas?
    Thanks,
    Jerry

    If you use substitution at the time, the button gets generated, you don't have the new value - the button is generated with the rest of the page, and then later the user changes value of the select list. You have two choices:
    1)Use Select list with submit - and transfer the user to second page using branch (which get's calculated after submit when select list has already the new value)
    2)Use Javascript to catch the onChange/onClick event of SelectList, read the current value and do the redirect from JavaScript.

  • Refresh classic report based on select list value selected

    hello,
    can anyone please help me out with this issue. I have a parameterized classic report based on a select list and I want to refresh this report whenever the select list value is changed. I am using oracle apex version 3.2. i just want to have a javascript function onchange event for the select list which refreshes my report whenever a value is selected.
    My select list item is p1_datastore
    select distinct datastore d,datastore r from my_table1 order by 1;
    My classic report query is
    select * from my_table2 where datastore = :p1_datastore order by last_updated_dt desc;
    ****************************************************thanks,
    orton

    can anyone please help me out with this issue.
    thanks,
    orton

  • How to use simple types for table column names ?

    Hi,
    can any one tell how to to use simple types for table column names?
    It is required in internationalizing of webdynpro applications.
    Regards,
    Rajesh

    Hi,
    1: define required column names in <SimpleType>
    2:use the following code to get those values
    3:bind 'text' property of Column headers to context attributes
    4:take a context attribute 'Value' as type of <SimpleType>
    5:set these values to context attributes
    IWDAttributeInfo objAttrInfo=wdContext.getNodeInfo().getAttribute(IPrivate<ViewName>View.IContextElement.VALUE);
    ISimpleTypeModifiable simple=objAttrInfo.getModifiableSimpleType();
    Map m=simple.getEnumerationTexts();
    Collection c=m.values();
    Iterator it=c.iterator();
    if(it.hasNext())
    wdContext.currentContextElement.set<att1>(it.next().toString);
    if(it.hasNext())
    wdContext.currentContextElement.set<att2>(it.next().toString);
    if(it.hasNext())
    wdContext.currentContextElement.set<att3>(it.next().toString);
    Regards
    LakshmiNarayana

  • Creating Select List with multiple columns

    I want to create a select list with multiple columns. I followed the demo application model described in the by Denes Kubicek (Currently my reference for APEX !!)
    The code is as follows:
    CREATE OR REPLACE FUNCTION getcrops(p_cropid IN NUMBER)
    RETURN VARCHAR2
    IS
    v_cropid VARCHAR2 (400);
    v_fcode VARCHAR2 (400);
    v_product VARCHAR2 (400);
    v_var VARCHAR2 (400);
    v_fname VARCHAR2 (400);
    v_acres VARCHAR2 (400);
    v_style_start VARCHAR2 (400);
    v_style_end VARCHAR2 (400);
    v_return VARCHAR2 (400);
    BEGIN
    FOR c IN (select "CROP"."CROPID" as "CROP ID",
         "CROP"."FIELDCODE" as "FIELD CODE",
         "CARROTPRODUCTLIST"."CARROTPRODUCTNAME" as "PRODUCT",
         "VARIETYLIST"."VARIETYNAME" as "VARIETY",
         "FIELD"."FIELDNAME" as "FIELD NAME",
         "CROP"."SIZEINACRES" as "ACRES"
    from     "FIELD" "FIELD",
         "CARROTPRODUCTLIST" "CARROTPRODUCTLIST",
         "VARIETYLIST" "VARIETYLIST",
         "CROP" "CROP"
    where "CROP"."CARROTPRODUCTTYPE"="CARROTPRODUCTLIST"."CARROTPRODUCTID"
    and     "CROP"."VARIETYID"="VARIETYLIST"."VARIETYLISTID"
    and     "CROP"."FIELDID"="FIELD"."FIELDID")
    LOOP
    v_cropid := TO_CHAR (c.'CROP ID', 'FML999G999G999G999G990');
    v_fcode := c.'FIELD CODE';
    v_product := c.'PRODUCT';
    v_var := c.'VARIETY';
    v_fname :=c.'FIELD NAME';
    v_acres :=c.'ACRES';
    FOR i IN 1 .. 12 - LENGTH (c."CROP ID")
    LOOP
    v_cropid := v_cropid || ' ';
    END LOOP;
    FOR i IN 1 .. 12 - LENGTH (c.'FIELD CODE')
    LOOP
    v_fcode := v_fcode || ' ';
    END LOOP;
    FOR i IN 1 .. 12 - LENGTH (c.'PRODUCT')
    LOOP
    v_product := v_product || ' ';
    END LOOP;
    FOR i IN 1 .. 12 - LENGTH (c.'VARIETY')
    LOOP
    v_var := v_var || ' ';
    END LOOP;
    FOR i IN 1 .. 12 - LENGTH (c.'FIELD NAME')
    LOOP
    v_fname := v_fname || ' ';
    END LOOP;
    FOR i IN 1 .. 12 - LENGTH (c.'ACRES')
    LOOP
    v_acres := v_acres || ' ';
    END LOOP;
    v_return := v_cropid || v_fcode || v_product || v_var || v_fname || v_acres;
    END LOOP;
    RETURN v_return;
    END;
    I created this anonymous Pl/SQL function at a application level ..Then I followed up to create a select list with a function inside. However I could not create select list with the command suggested in the demo which is
    select getcrops(cropid) d, cropid r from crop;
    APEX (2.1) returns a error message. What am I missing ? Should the function be called from somewhere else after creating a regular select list..? Where the functions (Pl/SQL) should be ideally stored for application level access..? and for across application level access ? How can I check the function works good. Help is appreciated.

    Still really one column.
    If they need to be independent then you've got to have three selection lists.
    %

  • How use select list whit ajax?

    when I use this code in my application I get this error
    XML Parsing Error: junk after document element
    <select><option value="1">- All Emps -</option></select><html lang="en-us" xmlns:htmldb="http://htmldb.oracle.com">
    --------------------------------------------------------^
    code use in application process.
    declare
    l_counter number;
    l_o_name varchar2(2000);
    begin
    owa_util.mime_header('text/xml', FALSE );
    htp.p('Cache-Control: no-cache');
    htp.p('Pragma: no-cache');
    owa_util.http_header_close;
    htp.prn('<select>');
    for rec in (select "RANDOMDATA"."CATEGORY" as "CATEGORY",
         "RANDOMDATA"."NAME" as "NAME",
         "RANDOMDATA"."ID" as "ID"
    from "RANDOMDATA" "RANDOMDATA"
    where "RANDOMDATA"."CATEGORY" = :TEMPORARY_ITEM)
    loop
    htp.prn('<option value="' || rec.id || '">' || rec.name || '</option>');
    end loop;
    htp.prn('</select>');
    end;

    Hi Andi.
    thanks for answering. But my problem dose not solved.
    XML Parsing Error: junk after document element
    <data><select><option value="1">-rec.name-</option></select></data><html lang="en-us" xmlns:htmldb="http://htmldb.oracle.com">

  • CPY-0007: Select list has fewer columns than destination table

    hello, I need your help, here is my problem is summarized in my example below
    Exemple
    SQL> copy from XX/X@BD1 to YY/Y@BD2 insert TABL1(COL1,COL2)-
    using select COL1,COL2 from TABL1
    Array fetch/bind size is 15. (arraysize is 15)
    Will commit when done. (copycommit is 0)
    Maximum long size is 80. (long is 80)
    CPY-0007: Select list has fewer columns than destination table
    DESC TABL 1
    COL1, COL2 DESC
    thank u.

    bahan wrote:
    hello, I need your help, here is my problem is summarized in my example below
    Exemple
    SQL> copy from XX/X@BD1 to YY/Y@BD2 insert TABL1(COL1,COL2)-
    using select COL1,COL2 from TABL1
    Array fetch/bind size is 15. (arraysize is 15)
    Will commit when done. (copycommit is 0)
    Maximum long size is 80. (long is 80)
    CPY-0007: Select list has fewer columns than destination table
    DESC TABL 1
    COL1, COL2 DESC
    thank u.
    00007,0, "Select list has fewer columns than destination table\n"
    // *Cause: On an APPEND operation or INSERT (when the table
    //          exists), the number of columns in the SELECT
    //          command is less than the number of columns in the
    //          destination table.
    // *Action: Re-specify the COPY command, making sure that the
    //          number of columns being selected agrees with the
    //          number in the destination table.

Maybe you are looking for

  • Notes and Location field disappear in iCal when I add invitee

    What's up with this? Also, once I add an invitee and hit Return, I can't delete the person.  I'm getting a question mark icon next to everybody, which is silly because AddressBook was used to make the suggestions I typed in. Running Snow Leopard 10.6

  • Safari won't open sites and is operating slowly

    I'm pretty new at this and admit I have no idea what to do. So, I'm unable to access many websites and the sites Safari does open, it's moving extremely slow. A couple of weeks ago, while online, I got some kind of message about a virus. When I tried

  • What are the different type of projects

    i mean how many different type of projects are there in sap implementation.. what do you mean by, enhancement project rollout project development project support project is there any thing else other than this? please clear my doubt. points would be

  • Create Directories based on File Names

    I have a Folder with all of my digital photos. All of the photos are named using a %Y%m%d_%H%M%S.jpg format. I am trying to write a script that would go through, and create folders based on the %Y%m%d portion of the name. Then move the photos into th

  • Regarding Password Sync

    hi, I have 3 solaris resources connected to IDM. I have assigened all these resources to one user with a password. I tried changing the password from the IDM and tried logging in to solaris resources and I was successful. Please let me know if i can