UiXML tables - variable number of columns?

I'm trying to define a <table> in a UIX page which will be generated from a set of parameters. This set of parameters will result in a varying number of columns so I'm looking at providing a DataObjectList which has DataObjects with keys for each of the columns attributes (header text, name of control, value of control etc.). I want to do something similar to <contents data:childData=...> on the <table> contents but this doesn't seem to work. It seems that <table> needs you to know how many columns will be present - is that so or is there some way I can do this?
Cheers
Ian

Ian,
That is correct, the uiMXL <table> element cannot currently support
a variable number of columns (using something akin to the
childData support in other contexts). But there are two approaches
to get what you want.
If you know the range of possible columns, then you can add a <column>
element for each possible column in the <table>'s contents and then
databind the rendered flag of the column element to hide/show the
column as necessary.
However, the real solution to your scenario, where the number of columns
is completely unknown when you're designing the page, is our canonical
example of a time you should write Java code for a portion of your page.
Specifically, you can use the XML <include> element to refer to a
DataProvider that will programatically create a TableBean. This
technique is discussed in the Dynamic Structure for UIX pages
portion of the UIX Developer's Guide.

Similar Messages

  • Display table with variable number of columns

    Hello Forum,
    I'm trying to build an export view of User Management Engine data. I would like to output a table with one row for every user with yes / no fields indicating membership in each of the available groups. Because the number of available groups might change in the future, I can't hardcode the column names for the groups.
    That is, I call a webservice to compute a table, and I get back a table with a variable number of columns.
    When I try to insert the webservice into my VC model, it complains:
    "Port 'Response' was omitted because it includes nested tables, which are not presently supported by Visual Composer"
    You might be interested to know that the business method of my webservice (for testing purposes) looks as follows:
    public String[][] getVariableSizeArray() {
            String[][] ret = new String[10][];
            for (int i = 1; i <= 10; i++) {
                    ret<i> = new String[10];
                    for (int j = 1; j <= 10; j++) {
                            ret<i>[j] = Integer.toString(i * j);
            return ret;
    Any help is appreciated, and points will be awarded for helpful answers,
    Sincerely,
    Florian
    Message was edited by:
            Florian Something

    Hi Florian,
    dynamic data structures are not supported. You can do this with a workaround. If you know the maximum count of your columns then you can add them to the table and hide/unhide them dynamicly via a formula in the hidden condition. Of course in your WS you als need a fix structure of your columns.
    This is not the best solution, I know so far, but it works. This is just one limit of VC.
    Best Regards,
    Marcel

  • How to generate report with dynamic variable number of columns?

    How to generate report with dynamic variable number of columns?
    I need to generate a report with varying column names (state names) as follows:
    SELECT AK, AL, AR,... FROM States ;
    I get these column names from the result of another query.
    In order to clarify my question, Please consider following table:
    CREATE TABLE TIME_PERIODS (
    PERIOD     VARCHAR2 (50) PRIMARY KEY
    CREATE TABLE STATE_INCOME (
         NAME     VARCHAR2 (2),
         PERIOD     VARCHAR2 (50)     REFERENCES TIME_PERIODS (PERIOD) ,
         INCOME     NUMBER (12, 2)
    I like to generate a report as follows:
    AK CA DE FL ...
    PERIOD1 1222.23 2423.20 232.33 345.21
    PERIOD2
    PERIOD3
    Total 433242.23 56744.34 8872.21 2324.23 ...
    The TIME_PERIODS.Period and State.Name could change dynamically.
    So I can't specify the state name in Select query like
    SELECT AK, AL, AR,... FROM
    What is the best way to generate this report?

    SQL> -- test tables and test data:
    SQL> CREATE TABLE states
      2    (state VARCHAR2 (2))
      3  /
    Table created.
    SQL> INSERT INTO states
      2  VALUES ('AK')
      3  /
    1 row created.
    SQL> INSERT INTO states
      2  VALUES ('AL')
      3  /
    1 row created.
    SQL> INSERT INTO states
      2  VALUES ('AR')
      3  /
    1 row created.
    SQL> INSERT INTO states
      2  VALUES ('CA')
      3  /
    1 row created.
    SQL> INSERT INTO states
      2  VALUES ('DE')
      3  /
    1 row created.
    SQL> INSERT INTO states
      2  VALUES ('FL')
      3  /
    1 row created.
    SQL> CREATE TABLE TIME_PERIODS
      2    (PERIOD VARCHAR2 (50) PRIMARY KEY)
      3  /
    Table created.
    SQL> INSERT INTO time_periods
      2  VALUES ('PERIOD1')
      3  /
    1 row created.
    SQL> INSERT INTO time_periods
      2  VALUES ('PERIOD2')
      3  /
    1 row created.
    SQL> INSERT INTO time_periods
      2  VALUES ('PERIOD3')
      3  /
    1 row created.
    SQL> INSERT INTO time_periods
      2  VALUES ('PERIOD4')
      3  /
    1 row created.
    SQL> CREATE TABLE STATE_INCOME
      2    (NAME   VARCHAR2 (2),
      3       PERIOD VARCHAR2 (50) REFERENCES TIME_PERIODS (PERIOD),
      4       INCOME NUMBER (12, 2))
      5  /
    Table created.
    SQL> INSERT INTO state_income
      2  VALUES ('AK', 'PERIOD1', 1222.23)
      3  /
    1 row created.
    SQL> INSERT INTO state_income
      2  VALUES ('CA', 'PERIOD1', 2423.20)
      3  /
    1 row created.
    SQL> INSERT INTO state_income
      2  VALUES ('DE', 'PERIOD1', 232.33)
      3  /
    1 row created.
    SQL> INSERT INTO state_income
      2  VALUES ('FL', 'PERIOD1', 345.21)
      3  /
    1 row created.
    SQL> -- the basic query:
    SQL> SELECT   SUBSTR (time_periods.period, 1, 10) period,
      2             SUM (DECODE (name, 'AK', income)) "AK",
      3             SUM (DECODE (name, 'CA', income)) "CA",
      4             SUM (DECODE (name, 'DE', income)) "DE",
      5             SUM (DECODE (name, 'FL', income)) "FL"
      6  FROM     state_income, time_periods
      7  WHERE    time_periods.period = state_income.period (+)
      8  AND      time_periods.period IN ('PERIOD1','PERIOD2','PERIOD3')
      9  GROUP BY ROLLUP (time_periods.period)
    10  /
    PERIOD             AK         CA         DE         FL                                             
    PERIOD1       1222.23     2423.2     232.33     345.21                                             
    PERIOD2                                                                                            
    PERIOD3                                                                                            
                  1222.23     2423.2     232.33     345.21                                             
    SQL> -- package that dynamically executes the query
    SQL> -- given variable numbers and values
    SQL> -- of states and periods:
    SQL> CREATE OR REPLACE PACKAGE package_name
      2  AS
      3    TYPE cursor_type IS REF CURSOR;
      4    PROCEDURE procedure_name
      5        (p_periods   IN     VARCHAR2,
      6         p_states    IN     VARCHAR2,
      7         cursor_name IN OUT cursor_type);
      8  END package_name;
      9  /
    Package created.
    SQL> CREATE OR REPLACE PACKAGE BODY package_name
      2  AS
      3    PROCEDURE procedure_name
      4        (p_periods   IN     VARCHAR2,
      5         p_states    IN     VARCHAR2,
      6         cursor_name IN OUT cursor_type)
      7    IS
      8        v_periods          VARCHAR2 (1000);
      9        v_sql               VARCHAR2 (4000);
    10        v_states          VARCHAR2 (1000) := p_states;
    11    BEGIN
    12        v_periods := REPLACE (p_periods, ',', ''',''');
    13        v_sql := 'SELECT SUBSTR(time_periods.period,1,10) period';
    14        WHILE LENGTH (v_states) > 1
    15        LOOP
    16          v_sql := v_sql
    17          || ',SUM(DECODE(name,'''
    18          || SUBSTR (v_states,1,2) || ''',income)) "' || SUBSTR (v_states,1,2)
    19          || '"';
    20          v_states := LTRIM (SUBSTR (v_states, 3), ',');
    21        END LOOP;
    22        v_sql := v_sql
    23        || 'FROM     state_income, time_periods
    24            WHERE    time_periods.period = state_income.period (+)
    25            AND      time_periods.period IN (''' || v_periods || ''')
    26            GROUP BY ROLLUP (time_periods.period)';
    27        OPEN cursor_name FOR v_sql;
    28    END procedure_name;
    29  END package_name;
    30  /
    Package body created.
    SQL> -- sample executions from SQL:
    SQL> VARIABLE g_ref REFCURSOR
    SQL> EXEC package_name.procedure_name ('PERIOD1,PERIOD2,PERIOD3','AK,CA,DE,FL', :g_ref)
    PL/SQL procedure successfully completed.
    SQL> PRINT g_ref
    PERIOD             AK         CA         DE         FL                                             
    PERIOD1       1222.23     2423.2     232.33     345.21                                             
    PERIOD2                                                                                            
    PERIOD3                                                                                            
                  1222.23     2423.2     232.33     345.21                                             
    SQL> EXEC package_name.procedure_name ('PERIOD1,PERIOD2','AK,AL,AR', :g_ref)
    PL/SQL procedure successfully completed.
    SQL> PRINT g_ref
    PERIOD             AK         AL         AR                                                        
    PERIOD1       1222.23                                                                              
    PERIOD2                                                                                            
                  1222.23                                                                              
    SQL> -- sample execution from PL/SQL block
    SQL> -- using parameters derived from processing
    SQL> -- cursors containing results of other queries:
    SQL> DECLARE
      2    CURSOR c_period
      3    IS
      4    SELECT period
      5    FROM   time_periods;
      6    v_periods   VARCHAR2 (1000);
      7    v_delimiter VARCHAR2 (1) := NULL;
      8    CURSOR c_states
      9    IS
    10    SELECT state
    11    FROM   states;
    12    v_states    VARCHAR2 (1000);
    13  BEGIN
    14    FOR r_period IN c_period
    15    LOOP
    16        v_periods := v_periods || v_delimiter || r_period.period;
    17        v_delimiter := ',';
    18    END LOOP;
    19    v_delimiter := NULL;
    20    FOR r_states IN c_states
    21    LOOP
    22        v_states := v_states || v_delimiter || r_states.state;
    23        v_delimiter := ',';
    24    END LOOP;
    25    package_name.procedure_name (v_periods, v_states, :g_ref);
    26  END;
    27  /
    PL/SQL procedure successfully completed.
    SQL> PRINT g_ref
    PERIOD             AK         AL         AR         CA         DE         FL                       
    PERIOD1       1222.23                           2423.2     232.33     345.21                       
    PERIOD2                                                                                            
    PERIOD3                                                                                            
    PERIOD4                                                                                            
                  1222.23                           2423.2     232.33     345.21                       

  • Procedure with variable number of columns

    Hi, I have a procedure that looks like this:
    PROCEDURE PROC(p_cursor OUT sys_refcursor)
    And in the procedure, I build up QUERY dynamically and the number of columns varies at runtime.
    At the end I do
    OPEN p_cursor for QUERY
    Then to call this, I'm doing
    call PROC(?)
    My question is, how would I go about running the query from this procedure, then adding rows or modifying the existing results, then returning the modified data?
    What I want to do is add a new row based on some condition, so I still need to return a variable number of columns, but I need to modify the results before I return them.
    Is there any way of doing this? I need to do some calculations on the columns (the variable columns), create a new row, insert into result set, and return this new result set.

    A sys_refcursor is ideally suited to pass back to a front end gui like .NET or Java which can then use that cursor to retrieve the data.
    In PL/SQL there is no point in using a sys_refcursor unless you know, at design/compile time what the returned columns are going to be.
    If the resultant columns are dynamic, then you have no choice but to use the DBMS_SQL package, where you can parse and execute any SQL statement you like and then use the DBMS_SQL package to describe what the resultant columns are and how many there are. From that you can reference the columns by position rather than by name.
    e.g.
    CREATE OR REPLACE PROCEDURE run_query(p_sql IN VARCHAR2) IS
      v_v_val     VARCHAR2(4000);
      v_n_val     NUMBER;
      v_d_val     DATE;
      v_ret       NUMBER;
      c           NUMBER;
      d           NUMBER;
      col_cnt     INTEGER;
      f           BOOLEAN;
      rec_tab     DBMS_SQL.DESC_TAB;
      col_num     NUMBER;
      v_rowcount  NUMBER := 0;
    BEGIN
      -- create a cursor
      c := DBMS_SQL.OPEN_CURSOR;
      -- parse the SQL statement into the cursor
      DBMS_SQL.PARSE(c, p_sql, DBMS_SQL.NATIVE);
      -- execute the cursor
      d := DBMS_SQL.EXECUTE(c);
      -- Describe the columns returned by the SQL statement
      DBMS_SQL.DESCRIBE_COLUMNS(c, col_cnt, rec_tab);
      -- Bind local return variables to the various columns based on their types
      FOR j in 1..col_cnt
      LOOP
        CASE rec_tab(j).col_type
          WHEN 1 THEN DBMS_SQL.DEFINE_COLUMN(c,j,v_v_val,2000); -- Varchar2
          WHEN 2 THEN DBMS_SQL.DEFINE_COLUMN(c,j,v_n_val);      -- Number
          WHEN 12 THEN DBMS_SQL.DEFINE_COLUMN(c,j,v_d_val);     -- Date
        ELSE
          DBMS_SQL.DEFINE_COLUMN(c,j,v_v_val,2000);  -- Any other type return as varchar2
        END CASE;
      END LOOP;
      -- Display what columns are being returned...
      DBMS_OUTPUT.PUT_LINE('-- Columns --');
      FOR j in 1..col_cnt
      LOOP
        DBMS_OUTPUT.PUT_LINE(rec_tab(j).col_name||' - '||case rec_tab(j).col_type when 1 then 'VARCHAR2'
                                                                                  when 2 then 'NUMBER'
                                                                                  when 12 then 'DATE'
                                                         else 'Other' end);
      END LOOP;
      DBMS_OUTPUT.PUT_LINE('-------------');
      -- This part outputs the DATA
      LOOP
        -- Fetch a row of data through the cursor
        v_ret := DBMS_SQL.FETCH_ROWS(c);
        -- Exit when no more rows
        EXIT WHEN v_ret = 0;
        v_rowcount := v_rowcount + 1;
        DBMS_OUTPUT.PUT_LINE('Row: '||v_rowcount);
        DBMS_OUTPUT.PUT_LINE('--------------');
        -- Fetch the value of each column from the row
        FOR j in 1..col_cnt
        LOOP
          -- Fetch each column into the correct data type based on the description of the column
          CASE rec_tab(j).col_type
            WHEN 1  THEN DBMS_SQL.COLUMN_VALUE(c,j,v_v_val);
                         DBMS_OUTPUT.PUT_LINE(rec_tab(j).col_name||' : '||v_v_val);
            WHEN 2  THEN DBMS_SQL.COLUMN_VALUE(c,j,v_n_val);
                         DBMS_OUTPUT.PUT_LINE(rec_tab(j).col_name||' : '||v_n_val);
            WHEN 12 THEN DBMS_SQL.COLUMN_VALUE(c,j,v_d_val);
                         DBMS_OUTPUT.PUT_LINE(rec_tab(j).col_name||' : '||to_char(v_d_val,'DD/MM/YYYY HH24:MI:SS'));
          ELSE
            DBMS_SQL.COLUMN_VALUE(c,j,v_v_val);
            DBMS_OUTPUT.PUT_LINE(rec_tab(j).col_name||' : '||v_v_val);
          END CASE;
        END LOOP;
        DBMS_OUTPUT.PUT_LINE('--------------');
      END LOOP;
      -- Close the cursor now we have finished with it
      DBMS_SQL.CLOSE_CURSOR(c);
    END;
    SQL> exec run_query('select empno, ename, deptno, sal from emp where deptno = 10');
    -- Columns --
    EMPNO - NUMBER
    ENAME - VARCHAR2
    DEPTNO - NUMBER
    SAL - NUMBER
    Row: 1
    EMPNO : 7782
    ENAME : CLARK
    DEPTNO : 10
    SAL : 2450
    Row: 2
    EMPNO : 7839
    ENAME : KING
    DEPTNO : 10
    SAL : 5000
    Row: 3
    EMPNO : 7934
    ENAME : MILLER
    DEPTNO : 10
    SAL : 1300
    PL/SQL procedure successfully completed.
    SQL> exec run_query('select * from emp where deptno = 10');
    -- Columns --
    EMPNO - NUMBER
    ENAME - VARCHAR2
    JOB - VARCHAR2
    MGR - NUMBER
    HIREDATE - DATE
    SAL - NUMBER
    COMM - NUMBER
    DEPTNO - NUMBER
    Row: 1
    EMPNO : 7782
    ENAME : CLARK
    JOB : MANAGER
    MGR : 7839
    HIREDATE : 09/06/1981 00:00:00
    SAL : 2450
    COMM :
    DEPTNO : 10
    Row: 2
    EMPNO : 7839
    ENAME : KING
    JOB : PRESIDENT
    MGR :
    HIREDATE : 17/11/1981 00:00:00
    SAL : 5000
    COMM :
    DEPTNO : 10
    Row: 3
    EMPNO : 7934
    ENAME : MILLER
    JOB : CLERK
    MGR : 7782
    HIREDATE : 23/01/1982 00:00:00
    SAL : 1300
    COMM :
    DEPTNO : 10
    PL/SQL procedure successfully completed.
    SQL> exec run_query('select * from dept where deptno = 10');
    -- Columns --
    DEPTNO - NUMBER
    DNAME - VARCHAR2
    LOC - VARCHAR2
    Row: 1
    DEPTNO : 10
    DNAME : ACCOUNTING
    LOC : NEW YORK
    PL/SQL procedure successfully completed.
    SQL>In 11g, you can create a sys_refcursor and then the DBMS_SQL package allows you to convert that refcursor into a DBMS_SQL cursor so that you can get the description of the results and do the same. This isn't available prior to 11g though.
    However_ before any of that, you should really ask yourself if there is a real need to dynamically be creating queries. There is rarely any real need to do that and if you're finding it's common in your application then this is often a sign of poor design or poorly defined business requirements (leaving the technical side to try and be "flexible" and hence leading to unmaintainable code etc.).

  • How to access variable number of columns using ref cursor !

    Hi,
    I am trying to get variable number of columns using ref cursor.
    Declare
    mySzSql varchar2(2000);
    Type dynSqlRC is Ref cursor;
    current_cur dynSqlRC;
    tbl_rec alt_42_consolidated%Rowtype;
    Begin:
    /* This works */
    mySzSql := 'select *
    from
    Table1
    Where
    rowid = ''AAEWNEABXAAAAkxAAA''';
    /* i want something like this to work, this is not working, giving missing variable name error */
    mySzSql := 'select col1, col2, col3
    from
    Table1
    Where
    rowid = ''AAEWNEABXAAAAkxAAA''';
    open current_cur for mySzSql;
    fetch current_cur into tbl_rec;
    close current_cur;
    End;
    I do have the list of desired columns which I am looking to fetch, so after taking that in the record type, how should i get their values. Is it possible to traverse tbl_rec declared above and if column name matches then I will store the value in the array and finally return this array.
    Can somebody please tell me how to do this.
    Thanks

    It appears that this is a followup to How to loop through columns selected by select clause which is itself a followup to [url="
    How to execute dynamic sql"]this earlier thread.
    Assuming these are intended to be followup questions, can we please stick to a single thread? That makes it a lot easier to understand the situation and follow the conversation. Starting multiple threads makes it harder to follow the conversation.
    Thanks,
    Justin
    Distributed Database Consulting, Inc.
    http://www.ddbcinc.com/askDDBC

  • Creating a table with a variable number of columns

    Hi,
    I am working on a form and I want to allow the user to add tables to the form. If I give them a base table (for instance, a table with two rows and columns) is there any way to allow the user to add columns to the table. I can add new instances of rows, but I need the number of columns to be variable as well.
    I am working in Livecycle Designer ES2

    Hi,
    check this article.
    http://forms.stefcameron.com/2006/10/28/scripting-table-columns/
    Hope this helps.

  • How create table with variable number of columns?

    I am creating table data in Java. Number of columns is variable. How I can write <table> in UIX.
    Here is code of one of my unsuccessful attempt:
    <provider>
    <!- get table data like DataObjectList-->
    <data name="ReportTableData">
    <method class="app.ReportTableData" method="getTableData"/>
    </data>
    <!- get names of columns like DataObjectList-->
    <data name="ColumnNames">
    <method class="app.ReportTableData" method="getColumnNames"/>
    </data>
    </provider>
    <table data:tableData="@ReportTableData">
    <contents data:childData="@ColumnNames">
    <text data:text="nameColumn"/>
    </contents>
    </table>
    I hoped that I can get cell data by key, where key is name of column. But cells of table contain only names of columns.
    Please help me, where I mistaken?
    Thank you.

    Hi Sergey,
    The UIX table implementation relies on a childData like mechanism internally to iterate over the rows. For instance, when you databind the text attribute of the UINode used to stamp out each column, you are relying on the uix:table iterating over the table data using the data object for the current row when evaluating your column stamp.
    Setting the data:childData attribute on the table's contents element conflicts with UIX's internal iteration over the tableData. For this reason, we don't support specifying a dynamic number of table columns in UIX XML.
    This doesn't mean that you can't do it, there are different strategies. If you've got a finite and known set of columns, you can specify each possible column and then databind the rendered attribute of each one to hide and show it as appropriate. Another, often cleaner approach, is to build this subtree of UINodes in Java code.

  • SSIS OLE DB Source in Data Flow Task calling SP that returns variable number of column as output

    We have one old Stored Proc that I need to reuse. But that stored proc returns different number of Columns as output depending on input Parameter. Say, if I pass 1 to 9 it will return 'ID', if i pass 10 to 33 it will return 'ID', 'Name',  if I pass
    34 to 51 it will return 'ID', 'Name', 'DefaultPosition' 
    In this way.
    Now I wanted to use this in OLE DB Source in SSIS DFT. 
    During that time immediately it is picking all possible columns in Available External Columns. Even if I manually select/delete those, package is failing at Runtime, because in Runtime the parameter this will get, it should always return one & only one
    column which is ID. [Because in this package I will only have to pass parameters like, 1 or 2 or 5 or 7 or 9.
    Which in every  case should return only ID from stored proc.
    Any Idea how I can get this please?
    Regards, Avik M.

    Has any one tried something like it? Could you please provide me a sample if you have done it.
    I tried these options but always got errors as
    [usp_return [64]] Error: SSIS Error Code DTS_E_OLEDBERROR.  An OLE DB error has occurred. Error code: 0x80040E55.An OLE DB record is available.  Source:
    "Microsoft SQL Server Native Client 10.0"  Hresult: 0x80040E55  Description: "Column does not exist.".
    [SSIS.Pipeline] Error: SSIS Error Code DTS_E_PRIMEOUTPUTFAILED.  The PrimeOutput method on component "usp_return" (64) returned error code 0xC0202009.  The component returned a failure code when the pipeline engine called PrimeOutput(). The meaning
    of the failure code is defined by the component, but the error is fatal and the pipeline stopped executing.  There may be error messages posted before this with more information about the failure.
    ~ Thank you so much
    Regards, Avik M.

  • PLSQL-generated SQL report with variable number of columns

    I created an app to track college football bowl picks:
    http://apex.oracle.com/pls/otn/f?p=21723
    The main report region includes columns for the various games as well as a column for each participant. In order not to hard code the number of participants, I used PLSQL to generate the SQL so that new columns could be added on the fly.
    However, whenever I add a new user I get this result -
    report error:
    ORA-01403: no data found
    If I copy and paste the PLSQL into a new report region and then delete the old one, however, all is well.
    Is there something I can do to overcome this?
    Thanks.
    Bill

    Roberto
    <br><br>
    Here are the tables:
    <br><br>
    BOWL_GAMES<br>
    ID     NUMBER<br>
    NAME     VARCHAR2(30)<br>
    FAV     VARCHAR2(20)<br>
    DOG     VARCHAR2(20)<br>
    BDATE     DATE<br>
    LINE     NUMBER(3,1)<br>
    FAV_SCORE     NUMBER(4,0)<br>
    DOG_SCORE     NUMBER(4,0)<br>
    <br>
    BOWL_USERS<br>
    ID     NUMBER<br>
    USERNAME     VARCHAR2(20)<br>
    PW     VARCHAR2(20)<br>
    NAME     VARCHAR2(20)<br>
    EMAIL     VARCHAR2(50)<br>
    <br>
    BOWL_PICKS<br>
    ID     NUMBER(5,0)<br>
    USERID     NUMBER(10,0)<br>
    GAMEID     NUMBER(10,0)<br>
    PICK     NUMBER(1,0)<br>
    <br>
    <br>
    Below is my PLSQL. Feel free to try out the app. Thanks.
    <br><br>
    Bill<br><br>
    declare<br>
    p_sql varchar2(32767);<br>
    cursor c1 is select * from bowl_users order by id;<br>
    begin<br>
    p_sql := q'! select to_char(b.bdate, 'Mon FMdd') "Date", b.name, '< a href="javascript$pickEm(''' || b.fav || ''')">' || b.fav || '</ a> -' || b.line || ' < a href="javascript$pickEm(''' || b.dog || ''')">' || b.dog || '</ a>' "Line" !';<br>
    for a1 in c1 loop<br>
    p_sql := p_sql || q'! , bowl_strike(b.id, !' || a1.id || q'! , 0) || (select decode(p.pick, 0, substr(b.dog,1,4), 1, substr(b.fav,1,4), 'No pick') from bowl_picks p where p.userid = !' || a1.id || q'! and p.gameid = b.id) || bowl_strike(b.id, !' || a1.id || q'! , 1) "!' || upper(a1.name) || q'!" !';<br>
    end loop;<br>
    p_sql := p_sql || q'! , bowl_score(b.id) "SCORE" from bowl_games b order by b.bdate !';<br>
    return replace(p_sql,'$',':');<br>
    end;
    <br><br>
    Message was edited by:
    [email protected]

  • Bex query that returns variable number of columns based upon variable value

    I have a request to create a query that, at excution time, has a variable for 'nbr of months', and based on the value entered by the user, returns data for only the specified number of months. Value that can be entered can vary from 1 to 12. A simple example is, if the user enters 1, then they would only want to see one column, and if they entered 6, then they'd like to see 6 columns in the workbook.  All suggestions on how to implement this dynamic columns on a workbook will be appreciated.
    Thanks.
    BN

    Hi,
    Do this->
    1) first create a New Structure in Rows-> Place your New Selection and drag your KF.
    2) Nw Create a New Formual under this structure. Now Create a Formula variable ( "ZFVXXX")with user-entry and ready for input and dimension as NUmber. and place in formula area. And hide this formula.
    3)Now Create a New Customer-Exit variable on 0CALMONTH name as "ZCECMON" with following atrribute->Mandatory, Range(Interval) and remove check for Ready for entry.
    4)Drag your 0CALMONTH in Rows above That Structure and restrict it to "ZCECMON".
    5) Now go to CMOD and write this code.
    INCLUDE ZXRSRU01 *
    DATA: L_S_RANGE TYPE RSR_S_RANGESID. 'In global area
    DATA: LOC_VAR_RANGE LIKE RRRANGEEXIT. 'In global area
    DATA: zmonth like /bi0/0calmonth.
    CASE I_VNAM.
    WHEN 'ZCECMON'.
    IF i_step = 2.
    LOOP AT I_T_VAR_RANGE INTO LOC_VAR_RANGE
    WHERE VNAM = 'ZFVXXX'.
    zyear = sy-datum(4).
    zmonth = sy-datum+4(2).
    l_s_range-low = zmonth.
    zmonth = zmonth + loc_var_range-low.
    l_s_range-HIgh = zmonth.
    l_s_range-sign = 'I'.
    l_s_range-opt = 'BT'.
    APPEND l_s_range TO e_t_range.
    ENDIF.
    ENDCASE.
    6) activate the porject and go to rsrt and run there first.
    Regards,
    San!
    Message was edited by: San!

  • DB view with flexible number of columns?

    In my Oracle 10 I have these tables
    Customer table:
    id      customer
    1       John
    2       Bob
    Item table
    id      item_name
    1       itemA
    2       itemB
    3       itemC
    4       itemD
    Purchase table:
    id      item_id date    customer_id
    1       3       070202  2
    2       6       070203  5
    ...I'd like to create a view like this:
            itemA   itemB   itemC   itemD   ...
    John    3       4       0       0       ...
    Bob     0       3       0       0       ...
    ...The view showed John purchased itemA 3 times, item B 4 times. Bob purchased itemB 3 times. This assume each customer only by one item at a time, which is a reasonable simplification of my situation.
    Such a view (with variable number of columns) is needed not in our web application but also provide an understandable data source for non IT professional to use report software. If my approach of solving this problem is completely wrong, I'd also like to know what's the common practice. Thank you very much in advance!
    Message was edited by:
    user609663

    I have tried to ask the question in a way that greatly simplify current problem to make it easy for others to understand without having to explain a lot of background information and 'the situation'; it seems I over-simplified the issue to make it even not worth solving or a wrong question being asked. So here I explain the complete problem and look for advice again (be prepared, pretty long description following:). I am a purchased customer of Oracle 10 DB and I reasonably expect being considered as Oracle user looking for help rather than students trying to play smart with assigned data normalization course exercises.
    We are working on a system that collects data from interview results. The questionnaires for the interviews are formatted with a coded question, followed by user's answer to the question, like the following:
         Question Code   Question content   Answer
         H001            ...                123
         H002            ...                45
         H003            ...                33
         H004            ...                66
         H005            ...                4,66
         ...             ...                ...The users answer question with a digit, for some special questions, e.g. H005, they are allowed to answer with a set of digits. There are thousands of interviews each year, the simplest solution to collect the interview answers is to use such a db table:
    simple_db_table:
    id   H001  H002  H003  H004  H005  H006  H007
    1    123   45    33    66    4     82    9
    ...This solution have two problems:
    1. It doesn't properly store answers to questions that requre a set of digits, like H005.
    2. The number of questions and their codes change from one survey to another, but the table have fixed number of columns and column names.
    And two benefit:
    1. With such simple table, people who use report software that directly access oracle db can creat their reports on easy-to-understand data presentation;
    2. calculation based on questionnaire data is simple, e.g. get the average of H007/H009 for questionnaires that have H002 > H003 * 600 would be:
    SELECT SUM(H007) / SUM(H009) FROM simple_db_table WHERE H002 > H003 * 600;Next solution we have normalized tables:
    questionnaire_entry_table:
    id                 NUMBER
    questionnaire_name CHARquestionnaire_definition_table:
    id                 NUMBER
    questionnaire_id   NUMBER
    question_code      CHAR
    question_content   VARHCARinterview_table:
    id                 NUMBER
    questionnaire_id   NUMBER
    date               DATEquestionnaire data table: itv_data
    id                 NUMBER
    interview_id       NUMBER
    question_code      CHAR
    answer             NUMBERWith the new structure, it just turn the problems of simple_db_table to its benefit and simple_db_table's benefit become the problem:
    1. Personnel who use report creation software feel too confused to make report based on such tables, because they do not understand the normalized modeling. In our case, effective training is difficult because there will be many geographically distributed people make reports based on this structure and they have lower IT knowledge than database administrators. These personnel can make reports based on simple_db_table.
    2. calculation based on questionnaire data is very difficult.
    To explain 2, let's take the same example, we still wish to get the average of H007/H009 for questionnaires that have H002 > H003 * 600, my method is:
    setp 1: create a view with by using:
           CREATE VIEW v (id, H002, H003) AS
           SELECT a.itv_id, a.H002, b.H003
             FROM itv_data a, itv_data b
           WHERE a.interviewee_id=b.interviewee_id
             AND a.question_code='H002' AND b.question_code='H003';step 2: create a stored procedure to get the calculation result:
           CREATE OR REPLACE PROCEDURE get_result (result OUT NUMBER) IS
             sh007 NUMBER := 0;
             sh009 NUMBER := 0;
           BEGIN
             SELECT SUM(H007) INTO sh007 FROM itv_data
               WHERE itv_id in (SELECT id FROM v WHERE H002 > H003 * 683);
             SELECT SUM(H009) INTO sh009 FROM itv_data
               WHERE itv_id in (SELECT id FROM v WHERE H002 > H003 * 683);
             idc := sh007/sh009;
           END get_idc;As you can see the calculation become much more complex and might involve overhead.
    There might be better way to calculate the result that I don't know yet. We have some 100 different formulas to calculate different results, so it's important to get them right and efficiently.
    The best solution seems to me is that to create such a view from itv_data and other tables so that to reflect the same structure of simple_db_table. So here comes the question I originally asked how is it possible to create a view with flexible number of columns. I made the very simple example in my original posted message wishing to get an idea of this is possible or the way to go.
    I may be taking a completely wrong approach to attack the problem, e.g. perhaps there is a simpler way to get_result from itv_table and for report creation users I should use a metadata layer on top of the normalized table structure (e.g. by using Metadata Query Language from Pentaho BI). But anyway I'd like to get some insightful ideas from the forum. Again thanks for help in advance.

  • How to transpose rows to multiple dynamic number of columns

    Hi All,
    I have a requirement to transpose the rows in single column to multiple columns. The columns are not fixed.
    A table called XX_PRODUCT_SIZE.
    The data in the table are,
    PRODUCT_NO SIZE PRESSURE
    P1 1 100
    P1 1 200
    P1 2 100
    P1 2 300
    P1 3 300
    The data in the table are not fixed with respect to size and pressure. In future the product P1 may have size 4 with new pressure 900.
    Now I want to convert these rows into multiple columns.
    So it should be,
    PRODUCT_NO SIZE_1 SIZE_2 SIZE_3 PRESSURE_100 PRESSURE_200 PRESSURE_300
    P1 TRUE TRUE TRUE
    P1 TRUE TRUE TRUE
    P1 TRUE TRUE
    I tried many ways of writing using CASE, MAX with rownumber over partition by etc. but which will not work for me as the rows are not fixed to compare.
    Can you please help me writing a query which transpose rows to columns dynamically. My intention is to create a materialized view for this XX_PRODUCT_SIZE table with transposing columns.
    I am using 10g DB
    Thank You
    Manju
    Edited by: ManjuNaik88 on May 28, 2013 2:29 AM

    Hi,
    If the number of columns in a query has to be figured out at run-time, then you need dynamic SQL. See the froum FAQ {message:id=9360005} for links to examples.
    You might find it easier to create one big column that looks like a variable number of columns. SELECT ... PIVOT can do this with XML output. String aggregation is another way; see {message:id=3527823} .
    ManjuNaik88 wrote:
    ... I saw Oracle 11g Pivot can be used. "PIVOT" is still not working
    SELECT ... PIVOT works. If it's not doing what you the way you're uisng it, then just change how you're using it.
    (You don't expect a mor precise answer with just that information, do you?)

  • Validating the number of columns

    Hi Guyz,
    how can i validate the number of columns in the custom table with number of columns in flat file.. at the moment ive uploaded all the data in flat file to internal table.
    plz advise..
    Thanks

    Try looking in table DD03L to list the field names within your specific table

  • Sys_refcursor from a table variable with columns per row not fixed

    i am creating a crosstab aggregation report where the number of columns in a table is determined at runtime from the dataset.
    so, i have:
    type strArray is table of varchar2(32767);
    type strArray2 is table of strArray index by pls_integer;
    i want to return a sys_refcursor (created from a strArray2 type variable) so a BIRT .rptdesign file can use it.
    sqldeveloper complains table not found when i do open for on the sys_refcursor.
    i cannot do a table of user defined record type because the number of columns depends on the dataset and therefore not fixed.
    how to get the sys_refcursor which upstream api can use ?

    Not exactly sure what you want to do and why... Keep in mind that pulling data from the SQL engine into the PL/SQL engine (or into external code lke Java) and processing it there, can never be as fast or scale as well as crunching that data in the SQL engine instead. So where processing can be done in the SQL engine, do it there.
    As for a 2D array definition and SQL projection, you can have a look at something like the following. Not sure if this is the approach you have in mind though. (note: the implicit cursor used could very easily be exposed to an external client via a ref cursor interface):
    SQL> --// 1 dimensional array definition
    SQL> create or replace type T1D is table of varchar2(4000);
      2  /
    Type created.
    SQL> --// 2 dimensional array definition
    SQL> create or replace type T2D is table of T1D;
      2  /
    Type created.
    SQL>
    SQL> declare
      2          arr2D   T2D;
      3  begin
      4          select
      5                  T1D( object_id, object_type, object_name )
      6                          bulk collect into
      7                  arr2D
      8          from    user_objects;
      9 
    10          for x in 1..2   --// just showing the 1st 2 elements and not arr2D.Count
    11          loop
    12                  for y in 1..arr2D(x).Count
    13                  loop
    14                          DBMS_OUTPUT.put_line( 'x='||x||' y='||y||' value='||arr2D(x)(y) );
    15                  end loop;
    16          end loop;
    17  end;
    18  /
    x=1 y=1 value=296403
    x=1 y=2 value=PACKAGE
    x=1 y=3 value=SYSLIB
    x=2 y=1 value=296404
    x=2 y=2 value=PACKAGE BODY
    x=2 y=3 value=SYSLIB
    PL/SQL procedure successfully completed.
    SQL>

  • How to find the number of columns in an internal table DYNAMICALLY ?

    Hi,
    How to find the number of columns in an internal table DYNAMICALLY ?
    Thanks and Regards,
    saleem.

    Hi,
    you can find the number of columns and their order using
    the <b>'REUSE_ALV_FIELDCATALOG_MERGE'</b>
    call function 'REUSE_ALV_FIELDCATALOG_MERGE'
    EXPORTING
       I_PROGRAM_NAME               = sy-repid
       I_INTERNAL_TABNAME           = 'ITAB'
       I_INCLNAME                   = sy-repid
      changing
        ct_fieldcat                  = IT_FIELDCAT
    EXCEPTIONS
       INCONSISTENT_INTERFACE       = 1
       PROGRAM_ERROR                = 2
       OTHERS                       = 3
    if sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
             WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    endif
    now describe your fieldcat . and find no of columns.
    and their order also..
    regards
    vijay

Maybe you are looking for

  • I phone 4s

    the problem is i created new acccount and filed all details when i enter my card no sucrity no after then there is one option of i thunes gift card and down side there is showing code so i m asking avout this code what i have to file in if i do not f

  • Files on mac server invisible for windows user

    Hi, Our school have a mac file server for sharing all the teachers' source. The problem is that when I login with my account in windows, some folders are invisible but when I login in Mac folders are visible. All the protocols are running well, AFP,

  • Hyperlink display text

    I'm adding hyperlinks to a pages document but want to change the display text for the links. Is this possible & if so how?? Thanks!!

  • Attachment in a case - CRM 5.0

    Hello all, I work with the version CRM 5.0. I would like to attach a document to a case without using knowledge search document. Please advice. Thanks in advance. Best Regards, Elsa.

  • NSU Error!!!

    Just tried to update my N96 through NSU since the OTA is not giving me any updates for FW V12!! The thing is that when I try to start the NSU it gives me an error (see attachment). I have McAfee antivirus and has never ever given me this problem befo