Search code examples
oracleoracle-sqldeveloperoracle-apex

how to make the output from checkbox to select statment?


I am currently using apex 19.1. I have this problem where I can't (or don't know how to) select certain columns from checkbox meaning I have this checkbox

checkbox

which gives me the ability to check the columns names I want to use that output (:P3_COLUMN) from the check box to select a specific columns in a table. My solution was :

select :P3_COLUMN
 from INPUT_TABLE$

I also tried :

select case :P3_COLUMN when 'currency' then currency when 'nationality'       then nationality end as test from input_table  

which gave me this output

SQL Statment output picture

and

DECLARE
str varchar2(100);
BEGIN
str := 'select ' || replace(:P3_COLUMN, ':', ',') || ' from input_table';
execute immediate str;
END;

which gave me this error

SQL STATMENT ERROR PICTURE

I don't know what to do, any help will be really appreciated.


Solution

  • Here's a walkthrough (my page is #51). Suppose that we want to display some column from Scott's DEPT table.

    • create a region whose type is classic report
    • create a page item (let's call it P51_COLS which is a select list item; its source is a query which looks like this:

      select column_name d,
             column_name r
      from user_Tab_columns
      where table_name = 'DEPT'
      

      Page action on selection should be "Submit page"

    • region's source should be a PL/SQL function body that returns a SQL query and look like this:

      return 'select case when :P51_COLS = ''DEPTNO'' then to_char(deptno )
                          when :P51_COLS = ''DNAME''  then dname
                          when :P51_COLS = ''LOC''    then loc
                     end as result 
              from dept';
      

      Its "Page items to submit" should be set to P51_COLS

    That's it ... run the page; select any column from the select list item and the result should be displayed.

    Yes, I know - the query itself looks stupid as you have to name all cases. For some reason, Apex expects literally return 'select ...' statement. Concatenation, replace function, ... won't work. Perhaps someone knows why or - even better - can demonstrate how to workaround it. Meanwhile, try what's been written above.