Selection of column dynamic Collection

Hi gurus,

I have a little problem with a collection.

I have a collection with a type of pins. The selected cell may contain 28, 29,..., 33.

Later, I want to count the lines of the following collection, where (in this example) c033 is not null. The variable is then used as a string, not a column.

How can I use the variable as a column in the 'where' - clause?

Here is my sql query:

declare
l_type_position varchar2 (4);  -content will be: c033
l_types number (3.0)

Start

-Select the dynamic column for the next newsletter

Select 'c0 ' | (c009) - c009 = 33
in l_type_position
of apex_collections

where collection_name = "UPLOAD_HEAD";

Select count (l_type_position)
in l_types
of apex_collections

where collection_name = "SPREADSHEET_CONTENT."
-folowing line error occurse

and l_type_position is not null;   -= and c033 is not null;

end;

Thanks for help.

This can be done using lexical replacement and dynamic SQL (as always, check for possible code SQL injection):

declare

  l_type_position varchar2(4);  --content will be: c033
  l_types number(3,0);

begin

  -- select the dynamic column for the next statement
  select 'c0'||(c009)   -- c009 = 33
  into l_type_position
  from apex_collections
  where  collection_name = 'UPLOAD_HEAD';

  -- check for SQL injection
  l_type_position := dbms_assert.simple_sql_name(l_type_position);

  -- count collection rows
  execute immediate q'{
      select count(}' || l_type_position || q'{)
      from apex_collections
      where  collection_name = 'SPREADSHEET_CONTENT'}'
    into
      l_types;
   ...
  end;

However, it is possible that it is a question of XY. If further information on the nature of the obligation provided that it might be possible to identify a clearer and more secure solution using SQL static.

Tags: Database

Similar Questions

  • Need help to display columns dynamically

    Hi all

    I have a requirement to display columns dynamically for query below
    ====================================================
    1. SELECT * FROM
    2 (SELECT jrgm.resource_name, fu.email_address,
    JRG.group_name 3,.
    4 max (decode (frv.responsibility_name, 'Customer Support Specialist_PRD', 'Y', ' don't)) Cust_Suppo
    5 max (decode (frv.responsibility_name, 'Internet Expenses_US', 'Y', ' don't)) Internet_Expenses_US,.
    6 max (decode (frv.responsibility_name, 'Internet Procurement_US', 'Y', ' don't)) Internet_Procureme
    7 max (decode (frv.responsibility_name, 'Email Center Console Agent', 'Y', ' don't)) Email_Center_Ag
    8 max (decode (frv.responsibility_name, 'Email Center Agent_PRD', 'Y', ' don't)) Email_Center_Agent_
    9 max (decode (frv.responsibility_name, 'Customers online CS User_PRD', 'Y', ' don't)) Customers_Onl
    10 max (decode (frv.responsibility_name, 'Email component Message Center', 'Y', ' don't)) Email_Cente
    Jtf_rs_group_members_vl jrgm 11,
    12 jtf_rs_groups_vl jrg,
    13 jtf_rs_defresources_vl jrdv,
    14 fnd_user_resp_groups furg,
    15 fnd_responsibility_vl LIF,
    16 apps.fnd_user fu
    17. WHERE the jrgm. GROUP_ID = jrg. GROUP_ID
    18 AND jrdv.resource_id = jrgm.resource_id
    19 AND jrdv.user_id = fu.user_id
    20 AND fu.user_id = furg.user_id
    21 AND furg.responsibility_id = frv.responsibility_id
    22 AND furg.responsibility_application_id = frv.application_id
    23 AND (fu.end_date IS NULL or TRUNC (fu.end_date) > = TRUNC (SYSDATE))
    24 AND (frv.end_date IS NULL or TRUNC (frv.end_date) > = TRUNC (SYSDATE))
    25 AND (furg.end_date IS NULL or TRUNC (furg.end_date) > = TRUNC (SYSDATE))
    26 AND jrg. GroupName like '% C '.
    27 AND jrgm.resource_name = 'Anderson, Jonathan P '.
    28 GROUP BY jrgm.resource_name, fu.email_address,.
    29 jrg.group_name)
    30 * ORDER BY 3
    ====================================================================
    above the line 4-10 I hard coded column names instead of that I need to display columns dynamically
    I have to write something like...
    Max (decode (frv.responsibility_name, (select fcl.meaning from fnd_common_lookups where fcl.meaning = frv.responsibility_name fcl), 'Y',' don't)) fcl.meaning
    Could you please suggest me a solution for this...

    Thank you
    GRISSA
  • get the names of the columns dynamically

    Hi gurus,
    I have the list item filled with lots of names of a table schema.
    I did grid in oracle 10g and I want to fill in the grid with the data that should come at least four/more columns.
    I want to get the trigger list change when whenever any name a table is selected/changed.

    How can I get the names of the columns dynamically
    Please give me the step by step process
    for the filling of the grid...

    Hello

    If you want to get the details of the column, and then use the USER_TAB_COLUMNSview.

    SELECT COLUMN_NAME, DATA_TYPE FROM USER_TAB_COLUMNS WHERE TABLE_NAME = 
    

    Kind regards

    Manu.

  • Returns the selected table column header

    I don't know there is probably a way to do this.  But I have not yet found.

    I am building an application that will act as a sort of "universal" reports generator for a MySQL database tables.

    At startup, a drop-down list box is filled with the names of tables in the database.  When the user selects one of these tables, the column names are taken from the base and used to fill the column headers for the table of LabVIEW.

    The idea is that the user can select this column and enter the constraints of filter in a text box.  These constraints will then be added to the WHERE statement for this column.

    So far I've been able to find a way to return the Active cell or a selection of cells, when the user clicks on the actual data of the table.

    Is there a direct way to retrun a selected in LabVIEW column header value?

    I am dreaming that there may be some sort of workaround using transparent controls over the headers.  But because different tables will have a different number of columns that the user defines the width, I'm not really sure that it will work more.

    If you the editable headers, this allows Active cells specify that your column is - 1 column selected active line is the selected column. You may need to use the mouse down? to filter the possibility for the user to change the right column headings.

  • Possible to use a wildcard to select all columns?

    I have a large table dénormalisée with 108 columns.  I know I can "select * from ' to display all values in column, but is there a shorthand notation to select all columns except the first?

    I know that I can:

    Select * from table;

    But if I don't want col1, I do this:

    Select col2,

    col3,

    COL4,

    ...

    col107,

    col108

    table;

    Is it possible to do something like that? :

    Select (* less col1) table.


    The reason why I ask, is that I write a few features to "clone" the rows of the table.  I wrote an insert that looks like this:

    Insert into my_table (col2, col3, col4,... col107, col108)

    Select col2, col3, col4,... col107, col108

    from my_table

    where col1 = 123;

    I do not insert col1 in the table because I have a trigger and sequence that it will fill in automatically.

    Is there a shorthand notation that I could use here to avoid having to type "col2, col3, col4,... col107, col108 '?

    There is no wildcard character that will do what you ask, but this does not mean that you must manually type the 100 column names.

    Instead of doing something like this:

    SELECT column_name | ',' Of all_tab_columns WHERE table_name = 'YOUR_TABLE_NAME_HERE' AND column_id > 1 ORDER BY column_id

    Cut and paste the results in your SQL statement as required.

  • Select the column name when the value = something

    Is there a way to select the column name when there is a specific value in it?

    As follows:

    create table (abc123)

    COLUMN1 VARCHAR2 (50).

    COLUMN2 VARCHAR2 (50).

    Column3 varchar2 (50)

    );

    insert into abc123 values ('yes', 'Yes', 'No');

    insert into abc123 values ('no', 'Yes', 'No');

    INSERT INTO ABC123 VALUES ('no ',' no', 'No');

    insert into abc123 values ('yes', 'Yes', 'Yes');

    SELECT CASE WHEN COLUMN1 = 'Yes' THEN - the name of the column would be here somehow?

    WHEN COLUMN2 = 'Yes' THEN - the name of the column would be here somehow?

    WHERE Column3 = 'Yes' THEN - the name of the column would be here somehow?

    Another null

    finish as abc123 columnname

    final results for the just Column1 would be:

    COLUMN1

    NULL VALUE

    NULL VALUE

    COLUMN1

    I'm not sure what I use to get the name of column in there

    Thank you.

    Hello

    708631 wrote:

    Is there a way to select the column name when there is a specific value in it?

    As follows:

    create table (abc123)

    COLUMN1 VARCHAR2 (50).

    COLUMN2 VARCHAR2 (50).

    Column3 varchar2 (50)

    );

    insert into abc123 values ('yes', 'Yes', 'No');

    insert into abc123 values ('no', 'Yes', 'No');

    INSERT INTO ABC123 VALUES ('no ',' no', 'No');

    insert into abc123 values ('yes', 'Yes', 'Yes');

    SELECT CASE WHEN COLUMN1 = 'Yes' THEN - the name of the column would be here somehow?

    WHEN COLUMN2 = 'Yes' THEN - the name of the column would be here somehow?

    WHERE Column3 = 'Yes' THEN - the name of the column would be here somehow?

    Another null

    finish as abc123 columnname

    final results for the just Column1 would be:

    COLUMN1

    NULL VALUE

    NULL VALUE

    COLUMN1

    I'm not sure what I use to get the name of column in there

    Thank you.

    Thanks for posting the CREATE TABLE and INSERT for the sample data.

    Don't forget to post the exact results you want from these sample data.  If the results depend on the parameters you want to pass a run time, then give a few different examples, with the the desired results of each.

    You can hardcode the values you want, such as the column names in a query.  For example:

    SELECT CASE WHEN column1 = 'Yes' THEN 'Column1' END like y1

    CASE WHEN column2 = 'Yes' THEN 'Column2' END like y2

    CASE WHEN Column3 = 'Yes' THEN 'Column2' END like y3

    , a. *-If wanted

    Of abc123 one

    ;

  • 2nd selection list column

    Dear Sir

    Not sure if possible, I found 1 result of valid research.
    He spoke of the concatting columns.

    What I want is to select 2 columns in the select list 1.
    He said that it would be possible, by the following code
     select column1||' '||column2,
    from table1
    but I have an error: wrong number of columns selected in the SQL LOV query. See the examples of valid conclusions
    is this impossible, or am I wrong?

    LOV must have 2 columns. A screen and back.

    select product_name d, product_id r
    from product
    

    Your of returns only one. If your display and back are the same then try this:

    select column1||' '||column2 d,
    column1||' '||column2 r
    from table1
    
  • Select default columns

    From the expensive

    At the Summit, I have a report based on a table, by default all columns are plurarite. The user can select the columns to be dispalyed the Actions-> Select columns. Here I want to customize the columns default to be copied, and at the same time that the user should be able to select all the columns of shares-> Select columns.

    Dennis

    Select them columns (and other features of IR) how you want to display them by default, and then click Actions-> Save the report.

    The pop of the Save list, choose "as default report parameters"

  • Select the columns not in the group by clause

    Hello

    My version of DB is 10.0.2

    I have query, where in I need to select two columns more but that should not be part of the group by Clause.

    Does perform a work around?
    SELECT  F.custnum, 
      V.Import_date,
     -- F.ErledigtMM,F.ErledigtGrundMM, (Columns to be selected additionally)
      nvl(sum(nvl(round(V.VerAuf16/1000,2), 0)  +nvl(round(V.VerAuf17/1000,2), 0)  + nvl(round(V.VerAuf18/1000,2), 0)  + nvl(round(V.VerAuf19/1000,2), 0)  + nvl(round(V.VerAuf20/1000,2), 0)  + nvl(round(V.VerAufKAPUn/1000,2), 0)  + nvl(round(V.VerAufKAPVz/1000,2), 0) ), 0)  Mandantenforderung,
      nvl(sum(nvl(round(V.VerAuf4/1000,2), 0) ), 0) Inkassokosten,
      nvl(sum(nvl(round(V.VerAuf5/1000,2), 0) ), 0) KontoFuehrungsgebuehren,
      nvl(sum(nvl(round(V.VerAuf1/1000,2), 0)  + nvl(round(V.VerAuf2/1000,2), 0) ), 0)  Verwertungskosten,
      nvl(sum(nvl(round(V.VerAuf10/1000,2), 0)  + nvl(round(V.VerAuf8/1000,2), 0) + nvl(round(V.VerAuf9/1000,2), 0) ), 0)  Barauslagen,
      nvl(sum(nvl(round(V.VerAuf13/1000,2), 0)  + nvl(round(V.VerAuf14/1000,2), 0) + nvl(round(V.VerAuf15/1000,2), 0)  + nvl(round(V.VerAuf6/1000,2), 0) ),0)  Gerichtskosten,
      nvl(sum(nvl(round(V.VerAuf11/1000,2), 0)  + nvl(round(V.VerAuf12/1000,2), 0)  + nvl(round(V.VerAuf7/1000,2), 0) ), 0) RAKosten,
      TO_CHAR(F.Created_Date,'MM.YYYY') Created_Date_MM ,
      TO_CHAR(F.Created_Date,'YYYY') Created_Date_MMRRRR
    FROM FACM F, VA V 
       WHERE  F.custnum =  DECODE(0,0,F.custnum,0) AND
      F.accnum = V.accnum 
      GROUP BY F.custnum, V.Import_date,TO_CHAR(F.Created_Date,'MM.YYYY') ,TO_CHAR(F.Created_Date,'YYYY'))

    Hello

    Here's what I suggest:

    select
    a.custnum,
    a.import_date,
    b.ErledigtMM,
    b.ErledigtGrundMM,
    a.Mandantenforderung,
    a.Inkassokosten,
    a.KontoFuehrungsgebuehren,
    a.Verwertungskosten,
    a.Barauslagen,
    a.Gerichtskosten,
    a.RAKosten,
    a.Created_Date_MM ,
    a.Created_Date_MMRRRR
    from (
    SELECT  F.custnum,
      V.Import_date,
      nvl(sum(nvl(round(V.VerAuf16/1000,2), 0)  +nvl(round(V.VerAuf17/1000,2), 0)  + nvl(round(V.VerAuf18/1000,2), 0)  + nvl(round(V.VerAuf19/1000,2), 0)  + nvl(round(V.VerAuf20/1000,2), 0)  + nvl(round(V.VerAufKAPUn/1000,2), 0)  + nvl(round(V.VerAufKAPVz/1000,2), 0) ), 0)  Mandantenforderung,
      nvl(sum(nvl(round(V.VerAuf4/1000,2), 0) ), 0) Inkassokosten,
      nvl(sum(nvl(round(V.VerAuf5/1000,2), 0) ), 0) KontoFuehrungsgebuehren,
      nvl(sum(nvl(round(V.VerAuf1/1000,2), 0)  + nvl(round(V.VerAuf2/1000,2), 0) ), 0)  Verwertungskosten,
      nvl(sum(nvl(round(V.VerAuf10/1000,2), 0)  + nvl(round(V.VerAuf8/1000,2), 0) + nvl(round(V.VerAuf9/1000,2), 0) ), 0)  Barauslagen,
      nvl(sum(nvl(round(V.VerAuf13/1000,2), 0)  + nvl(round(V.VerAuf14/1000,2), 0) + nvl(round(V.VerAuf15/1000,2), 0)  + nvl(round(V.VerAuf6/1000,2), 0) ),0)  Gerichtskosten,
      nvl(sum(nvl(round(V.VerAuf11/1000,2), 0)  + nvl(round(V.VerAuf12/1000,2), 0)  + nvl(round(V.VerAuf7/1000,2), 0) ), 0) RAKosten,
      TO_CHAR(F.Created_Date,'MM.YYYY') Created_Date_MM ,
      TO_CHAR(F.Created_Date,'YYYY') Created_Date_MMRRRR
    FROM FACM F, VA V
       WHERE  F.custnum =  DECODE(0,0,F.custnum,0) AND
      F.accnum = V.accnum
      GROUP BY F.custnum, V.Import_date,TO_CHAR(F.Created_Date,'MM.YYYY') ,TO_CHAR(F.Created_Date,'YYYY'))
    ) a,
    FACM b
    where b.custnum = a.custnum 
    

    By the way

    WHERE  F.custnum =  DECODE(0,0,F.custnum,0) AND F.accnum = V.accnum
    

    can be translated into

    WHERE F.accnum = V.accnum
    

    because

    F.custnum =  DECODE(0,0,F.custnum,0)
    

    is always true
    because

    DECODE(0,0,F.custnum,0)
    

    means

    if 0=0 then F.custnum else 0
    
  • Select the item to collection

    Hi gems... I have a question...

    I write a proc... where I use view inline...

    Select < a.something, a.something... >
    (select something, something table_name);


    in the select clause below, should I use a collection type? means I want to take the bottom of the select clause in a collection and then I want to replace the clause select lower by the name of this collection... is this possible?

    pls help...

    You cannot use the name of the collection directly to replace the sub query.

    I think that better use you TEMPORARY GLOBAL session specific tables and store data temporarily.

    Concerning
    Arun

  • Selection of column on several Pages

    I'm using Adobe Reader 9.  I need to convert a PDF to a phone bill to Excel, but nothing works to keep separate the columns in Excel.  So, try to select a single column at the same time to manually paste into Excel.  However, using the Crtl + Alt when I select a column I can't past one page.  I would select a column on several pages.  Help!  Thank you!

    Try to set your layout to enable scrolling before selecting the column.

  • Select the column by using Session variables

    I set a session variable to contain the name of a bound column that is the user. Is it possible to use a session variable to select a column in a database table? If so, how? Does need a statement where clause?

    Something like that? :

    < cfquery name = "rsSelectColumn" datasource = 'Test' >
    SELECT column 1, column 2, column 3 is Variable from Session
    OF tbl_data
    < / cfquery >

    Thank you
    Dave

    I think you want to do this, if the value in the session variable is the actual column name:


    SELECT column 1, column 2, #Session Variable # AS Col3
    OF tbl_data

    in this way, you can call any column stored in the session variable, and it will still be usable from the QUERY as COL3 regardless of which column you used.

    If that's what you want to do - it OF as simple as that.

    :-)

    Sometimes we have to think of things too.

  • Regd select the column in the table area

    Hello

    I have a search page... Have used autocustomization to create... This page will be used to query data from a table and then we must also update two fields of results table and save.

    There is a region of results. I've included the multiselect table option that made me select a column as the first column of the table. Also, including a tableaction and a button upate with whom...

    I need to write a handler for the update now... but do not understand all the slect column...

    Whenever a user clicks on the boxes to select specific records and change the fields and click Update to save, how to write code to check whether the checkbox option has been activated or not?


    Please help me as soon as possible...


    Kind regards
    Preeti

    Hello

    Take a Transient attribute tell 'SelectFlag' in view object and to set the Instance of the view and the view attribute
    for multipleselection in the table.

    Now that the update is click on the button:

    If (PageContext.GetParameter ("Update")! = null)
    {
    OAApplicationModule am = pageContext.getApplicationModule (webBean);
    OAViewObject vo = (OAViewObject) am.findViewObject ("projVO1");
    Line [] row = vo.getAllRowsInRange ();
    Loop through lines
    for (int i = 0; i)<>
    {
    Check if checbox is checked or not
    If (line.getAttribute("SelectFlag").toString().equals("Y"))//means checbox is checked for this line.
    {
    write your logic
    }
    }
    }

    Thank you
    Gerard

  • Select the column values in the collection

    Greetings,

    I want to select column values from the collection (plsql tables or table), as the following code, would it be possible
    Here tt is any collection



    Select emp_no, name, date of birth, sal tt (1), tt (2), tt (3), tt (4) emp; -single line query

    Select name, Department of justice, strength and dep_no in tt (5), tt (6), tt (7), tt (8) EMP; -single line query


    Version
    Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi
    PL/SQL Release 10.2.0.4.0 - Production

    Thanks in advance

    Not sure about your business needs. But technically you can do.

    declare
       type tbl is table of number;
       lemp tbl := tbl();
    begin
       lemp.extend;
       lemp.extend;
       lemp.extend;
    
       select empno
            , mgr
            , sal
         into lemp(1)
            , lemp(2)
            , lemp(3)
         from emp
        where empno = 7369;
    
       for i in 1..lemp.count
       loop
         dbms_output.put_line(to_char(lemp(i)));
      end loop;
    end;   
    
  • Insert in varchar2 select xmltype column: extremely slow

    I use oracle10gR2 10.2.0.4 and solaris10 64bits

    I need to select the data to an xml value in a table of column xmltype (word.testmeta)

    and insert into another table (word.testwordyy)

    desc word.testmeta;
    Name                 Null?    Type
    --------------------------------------
    FILENAME             CHAR(2000)
    XMLDATA              XMLTYPE
    
    
    desc word.testwordyy;
    Name                 Null?    Type
    ---------------------------------------
    ID                   VARCHAR2(255)
    KEYWORD              VARCHAR2(4000)
    

    and I use xmltable

    insert /*+append */ into word.testwordyy(KEYWORD)
    select /*+ gather_plan_statistics */ dbms_lob.substr(xmltype.getclobval(b.KEWOR),254)
    from word.testmeta , xmltable
    (
    '$B/mets/KEWOR'
    passing
    word.testmeta.XMLDATA as B
    columns
    KEWOR xmltype path '/KEWOR/text()'
    )
    b
    

    > select * from table(dbms_xplan.display_cursor(null,null,'iostats last')); 
    
    
    PLAN_TABLE_OUTPUT
    -----------------------------------------------------------------------------------------------------------------------------------
    SQL_ID  37ua3npnxx8su, child number 0
    -------------------------------------
    insert /*+append */ into word.testwordyy(KEYWORD) select /*+ gather_plan_statistics */
    dbms_lob.substr(xmltype.getclobval(b.KEWOR),254) from word.testmeta , xmltable ( '$B/mets/KEWOR' passing word.testmeta.XMLDATA as
    B columns KEWOR xmltype path '/KEWOR/text()' ) b
    
    
    Plan hash value: 875848213
    
    
    -----------------------------------------------------------------------------------------------------------------------------------
    
    
    PLAN_TABLE_OUTPUT
    -----------------------------------------------------------------------------------------------------------------------------------
    | Id  | Operation                           | Name                   | Starts | E-Rows | A-Rows |   A-Time   | Buffers | Reads  | Writes |
    
    
    -----------------------------------------------------------------------------------------------------------------------------------
    
    
    |   1 |  LOAD AS SELECT                     |                        |      1 |        |      1 |00:10:32.72 |   16832 |      7 |   90 |
    
    
    |   2 |   NESTED LOOPS                      |                        |      1 |     29M|  34688 |00:00:25.95 |   12639 |      5 |    0 |
    
    
    PLAN_TABLE_OUTPUT
    -----------------------------------------------------------------------------------------------------------------------------------
    |   3 |    TABLE ACCESS FULL                | TESTMETA               |      1 |   3638 |   3999 |00:00:00.08 |     909 |      0 |    0 |
    
    
    |   4 |    COLLECTION ITERATOR PICKLER FETCH| XMLSEQUENCEFROMXMLTYPE |   3999 |        |  34688 |00:00:24.50 |   11730 |      5 |    0 |
    
    
    -----------------------------------------------------------------------------------------------------------------------------------
    
    
    PLAN_TABLE_OUTPUT
    -----------------------------------------------------------------------------------------------------------------------------------
    Note
    -----
       - dynamic sampling used for this statement
    
    
    
    
    21 rows selected.
    

    and the more the number of rows in the word.testmeta table, the more time spent by rank

    I have a small simple XML but I need to process a large amount of them (5000000) as well as the treatment is very very slow when the lines of more than 8000

    Is there an optimization or the fastest?

    Why? Because you do a manipulation of LOB lob.

    Your XMLType is the kind of CLOB storage

    Your chain of subtr quantities are manipulationg LOB

    Altogether, the XML must be done in memory (XMLSEQUENCEFROMXMLTYPE), the manipulation of strings (CLOB) become bigger and bigger and bigger and will eat all your memory and CPU resources.

    How to solve it?

    Upgrade to a supported database version (11.2.0.3 and upwards)

    Store XML documents in a binary XML format of XMLType Securefile

    Use simple methods like XMLCAST to make the string conversion and manipulation

    Or...

    .. m:System.NET.HttpListener.start reading by doing the hard (and today with a version of database not supported), 10.2 through storage XMLType object / relational and convert you CLOB, XMLType storage for storing XMLType object / relational. Use the functions and operators that are created to make the manipulation of strings instead of DBMS_LOB Package (which is not free memory automatically)

Maybe you are looking for