Dynamic column names

Hello
I use a select * from employees to generate an XML file. I need to use this XML file in a RTF model to display data for all employees. I don't want to use the column names in the table employee instead the RTF must be able to pick up from the XML file. Is this possible?

Thank you

Hello

Take a look at this

http://winrichman.blogspot.com/search/label/cross%20tab

or send your xml and the model to my id (in profile)

Tags: Business Intelligence

Similar Questions

  • As a dynamic values column names

    I have a WEEK_TAB table

    Week_num Bkg1 Bkg2
    1 10 20
    2 40 10
    3 30 20
    2 20 60
    1-10-50
    1-20-80
    3 10 30

    When I run this package, I get the below output...

    CREATE OR REPLACE
    PACKAGE GET_TOTAL AS

    TYPE ref_cursor IS REF CURSOR;

    PROCEDURE get_week_total (p_refCursor to ref_cursor);

    PROCEDURE get_total_val;

    END GET_TOTAL;
    /

    CREATE OR REPLACE
    PACKAGE BODY GET_TOTAL AS

    PROCEDURE get_week_total (p_refCursor to ref_cursor) AS
    BEGIN
    OPEN FOR P_refcursor
    SELECT SUM (bkg1), week_num
    OF week_tab
    GROUP BY week_num
    ORDER BY week_num;
    END get_week_total;

    PROCEDURE get_total_val AS
    v_refCursor ref_cursor;
    v_sum NUMBER;
    v_week NUMBER;
    v_total NUMBER: = 0;

    BEGIN

    get_week_total (v_refcursor);

    LOOP
    EXTRACTION v_refCursor
    IN v_sum, v_week;
    EXIT WHEN v_refcursor % NOTFOUND;
    v_total: = v_total + v_sum;
    DBMS_OUTPUT. Put_line (' week ' | v_week |': ' | v_sum);
    END LOOP;
    DBMS_OUTPUT. Put_line (' total sales reservations :'|| v_total);
    END get_total_val;

    END GET_TOTAL;
    /

    O/P
    Week 01:40
    Week
    Week 03:40
    Total sales reservations: 140

    --------------------------------------------------------------------------------

    Here, I'm moving the column name as dynamic value.
    I modified the package as below...

    CREATE OR REPLACE
    PACKAGE BODY GET_TOTAL AS

    CREATE OR REPLACE
    PACKAGE GET_TOTAL AS

    TYPE ref_cursor IS REF CURSOR;

    Strarray ARRAY TYPE IS VARCHAR2 (100);

    PROCEDURE get_week_total)
    p_colName VARCHAR2,
    p_refCursor to ref_cursor);

    PROCEDURE get_total_val;

    END GET_TOTAL;
    /

    CREATE OR REPLACE
    PACKAGE BODY GET_TOTAL AS

    PROCEDURE get_week_total)
    p_colName IN VARCHAR2,
    p_refCursor OUT ref_cursor) AS

    v_query VARCHAR2 (4000);
    BEGIN
    v_query: = ' SELECT SUM (: p), week_num FROM week_tab GROUP BY week_num ORDER BY week_num';

    P_refcursor OPEN FOR v_query
    Using p_colName;

    END get_week_total;

    PROCEDURE get_total_val AS
    v_refCursor ref_cursor;
    v_sum NUMBER;
    v_week NUMBER;
    v_total NUMBER: = 0;
    STRARRAY v_colName: = STRARRAY ('BKG1', 'BKG2');

    BEGIN

    I'm IN v_colName.FIRST... v_colName.Last LOOP
    get_week_total (v_colName (i), v_refcursor);

    LOOP
    EXTRACTION v_refCursor
    IN v_sum, v_week;
    EXIT WHEN v_refcursor % NOTFOUND;
    v_total: = v_total + v_sum;
    DBMS_OUTPUT. Put_line (' week ' | v_week |': ' | v_sum);
    END LOOP;
    DBMS_OUTPUT. Put_line (' total sales reservations :'|| v_total);

    END LOOP;
    END get_total_val;

    END GET_TOTAL; GET_TOTAL;
    /


    But I get this error message
    ORA-01722: invalid number
    ORA-06512: at "SCOTT. GET_TOTAL', line 29
    ORA-06512: at line 2


    Please let me know how this can be resolved... I'm trying to get the result as below

    Week 01:40
    Week
    Week 03:40
    Total sales reservations: 140

    Week 1:150
    Week 2:70
    Week 03:50
    Total sales reservations: 270

    Variable bind bind values of the object, not the object names. You cannot use bind variable as column name. Change:

    v_query := 'SELECT SUM (:p), week_num FROM week_tab GROUP BY week_num ORDER BY week_num'; 
    

    TO

    v_query := 'SELECT SUM (' || p_colName || '), week_num FROM week_tab GROUP BY week_num ORDER BY week_num'; 
    

    and

    OPEN p_refcursor FOR v_query
    USING p_colName; 
    

    TO

    OPEN p_refcursor FOR v_query; 
    

    SY.

  • Using the name of dynamic column in datagrid selectedItems

    Hello

    I have a datagrid that is loaded with 2 columns. AllowMultiSelect is enabled.

    Based on the values selected at runtime, I get the correspondent selected the name of the column and its values and displays it on the screen of the HTML.

    GRP is datagrid

    dgrcl is a data grid column

    selflds is a table that has values 0,1,2,3

    selflds [0] = name, selflds [1] = age

    for (var l:int = 0; < grp.columnCount; l ++)

    {

    dgrcl = grp.columns [l];

    selflds [l] = dgrcl.dataField;

    }

    srhVals will have a single value selected in one point any

    get the corresponding name of the selected column and its value

    var srhVals:String;

    srhVals = String(grp.selectedItem[selflds[1]]);

    I'm trying to make the selection above instead in .selectedItems something like below. By doing that, I'll get all selected items, but not a single. If I try under syntax, I get error. Anyone have any ideas on how to make.

    srhVals = String(grp.selectedItems.selflds[1]);

    Hello

    I got my mistake, there should be no point after selectedItems operator;

    I found a solution - it goes like this:

    for (var g:int = 0; g<>

    {

    srhVals = srhVals + String(grp.selectedItems[g][selflds[1]]);

    }

    If the whole scenario is like this:

    DataGrid:

    Name age

    a               20

    b               30

    c               40

    d               50

    I select b, d in the user interface. At runtime, I get the selecteditem as 'Name' column name programmatically, loops through the selecteditems and store the value in srhVals b, d.

    b, d will finally be shown in the user interface.

  • Dynamic column in cfquery name

    I have a scenario in which database column names in a format COLUMN1, COLUMN2... COLUMNn. Column number is not known in coding. But the column names are usually hard-code while accessing the cfquery as result
    cfqueryresult. COLUMN1.

    I want to get the column names of ' cfqueryresult. ColumnList' and with this result, I want to extract column values.
    Is it possible to do this in coldfusion?



    #yourquery [ThisColumn] [currentrow] #.
    closing tags

  • Display the name of the tag as the column name and the value in the tag as a row of data from the input string.

    Hi Forum members,

    I am looking for a query display the name of the tag as the column name and the value in the tag as a row of data.

    I have to print the values within the tag to a file by choosing the value of the flags. the sequence of the tags will vary each time, as the tag name will change dynamically.

    So here is the example of input data and the expected output. The string in the text column must be separated as the column names and values.

    Input data
    Select 1 as seqno,' < > 0210A 50 4f < / 4f > < 5f20 > TEST CARD 16 < / 5f20 > < 5f2a > < / 5f2a > < 82 > 1 c 00 < / 82 > ' double text


    Output:

    Seqno 4f 5f20 5f2a 82
    0210A 50 16 1 00 TEST CARD 1

    Please help me by providing your entries on this.

    We use the version of Oracle 11.2.

    Note: This is not the XML string

    Thank you

    Shree

    with

    data in the form of

    (select 1 as seqno,'<4f>0210 A 50<5f20>TEST CARD 16<5F2a><82>00 1' text of all the double union)

    Select 2 as seqno,'XYZ<4F>0210 A 50<5f20>TEST CARD 16<5f2a><82>00 1' text of all the double union

    Select 3 as seqno,'<4f>0210 A 50<5f20>TEST CARD 16<5F2A><82>1 00XYZ ' text of all the double union

    Select option 4 as seqno,'<4F>0210 A 50<5F20>TEST CARD 16<5f2A><82>1 00XYZ' double text

    )

    Select d.seqno, x.*

    d the data,

    XMLTable ('/ root')

    by the way xmltransform (xmltype ('': replace (replace (text,'<><>'),)))

    XmlType (q'~http://www.w3.org/1999/XSL/Transform "version ="1.0"> ")

                                                     

                                                       

                                                         

                                                       

                                                     

                                                     

                                                       

                                                         

                                                       

                                                     

    ~'

    )

    )

    path of columns '4f' varchar2 (10) "tag4f."

    path of "5f20' varchar2 (30)"tag5f20. "

    path of '5f2a' varchar2 (10) "tag5f2a."

    path of varchar2 (10) "82" "tag82.

    ) x


    SEQNO 4f 5f20 5f2a 82
    1 0210A 50 16 TEST CARD - 1 00
    2 0210A 50 16 TEST CARD - 1 00
    3 0210A 50 16 TEST CARD - 1 00
    4 0210A 50 16 TEST CARD - 1 00

    with

    data in the form of

    (select 1 as seqno,'<4f>0210 A 50<5f20>TEST CARD 16<5F2a><82>00 1' text of all the double union)

    Select 2 as seqno,'XYZ<4F>0210 A 50<5f20>TEST CARD 16<5f2a><82>00 1' text of all the double union

    Select 3 as seqno,'<4f>0210 A 50<5f20>TEST CARD 16<5F2A><82>1 00XYZ ' text of all the double union

    Select option 4 as seqno,'<4F>0210 A 50<5F20>TEST CARD 16<5f2A><82>1 00XYZ' double text

    ),

    Chopper (seqno, Key, value, String) as

    (select seqno,

    regexp_substr (text,'<(.+?)>', 1, 1, null, 1),

    regexp_substr (Text,'>(.*?))

    regexp_substr (text,'<.+?>. *? ) (.*) $', 1, 1, null, 1). » <>'

    from the data

    Union of all the

    Select seqno,

    regexp_substr (String,'<(.+?)>', 1, 1, null, 1),

    regexp_substr (String,'>(.*?))

    regexp_substr (String,'<.+?>. *? ) (.*) $', 1, 1, null, 1)

    Chopper

    where regexp_substr (string,'<(.*?)>', 1, 1, null, 1) is not null

    )

    Select '4f', seqno, '5f2a', '82', '5f20.

    of (seqno, lower (key) select key, value)

    Chopper

    )

    Pivot (max (value) for key in ('4f' as '4f', '5f20' as '5f20', '5f2a' as '5f2a', "82" as "82"))

    Concerning

    Etbin

  • Question PLSQL with variable compound column names

    Hello gentlemen,


    I'm new to PLSQL and I would like to display some values of columns, which are listed in the defined variable in dbms.output. I created under code, which I think it could work, but I guess that it is far from correct.


    DECLARE
    v_TEMP_QUERY VARCHAR2
    (1000 BYTE);
    v_TEMP_VALUE VARCHAR2
    (1000 BYTE) := 'FILTER_01, FILTER_02';

    BEGIN  
    FOR v_TEMP_LOOP IN
    (v_TEMP_QUERY := 'SELECT DISTINCT ' || v_TEMP_VALUE || ' FROM CW_PAGE_COMPONENT_TEMPL WHERE COMPONENT_TEMPL_ID = 10000034642';
    EXECUTE IMMEDIATE v_TEMP_QUERY; )
    LOOP
    DBMS_OUTPUT
    .PUT_LINE (v_TEMP_LOOP.v_TEMP_VALUE);
    END LOOP;
    END;


    Thanks in advance for your help and advice on this issue and sincerely,

    Sebastian

    OK, first of all, you're confused concepts here.

    cursor loop FOR waiting for a slider must be provided, and yet you offer an assignment statement and a command immediately execute for it.  Syntax is not valid.

    Secondly, you force the way of the use of dynamic SQL, which is generally bad practice.  This use of the SQL is rarely necessary, because it often indicates that functional requirements, database design, or design/code enforcement has not examined properly... the first question is "why don't you know the names of the columns to select.  With dynamic columns in your query, you need some kind of dynamic code to manage the results of the query, you will not be able to reference the columns directly by name.

    Thirdly, the DBMS_OUTPUT package doesn't make "blank".  This may sound pedantic, but it's a common mistake that people make.  There is no fill data dbms_output buffer.  It relies on call code/interface to read the contents of the output buffer and display it in fact (for example, in SQL * more you use SQL * Plus the command "set serveroutput we ' to achieve)

    In general, in a well designed where application you know your columns you would only make...

    Start
    I'm in (select distinct filter_01, filter_02 from vw_page_component_templ where component_templ_id = 10000034642)
    loop
    dbms_output.put_line (i.filter_01 | ',' | i.filter_o2);
    end loop;
    end;

    If the columns are dynamic, then you have three options:

    (1) create a ref and pass cursor who back, extracting the content for example

    sys_refcursor getRc function returns (in numbers, in colnames templ_id varchar2) is
    RC sys_refcursor;
    Start
    Open rc for ' select distinct ' | colnames |' from vw_page_component_templ where component_teml_id =: 1' using templ_id;
    return rc;
    end;

    In SQL * more:

    var r refcursor; -It creates a variable in SQL * Plus ref cursor type
    Start
    : r: = getRc (10000034642, ' filter_01, filter_02');
    end;
    /
    print r;      -It's SQL * command to retrieve the cursor open and display the results

    (2) create an object and collection of the right structure to receive the results and use execute immediate to select IN this structure.

    (I will not show in this way, because it is absolute rubbish, and if you know the columns that you want to create the object and the collection, then you should not use dynamic SQL in the first place)

    (3) use the DBMS_SQL package to run the query and retrieve the data from the column in position rather than example:

    create or replace procedure run_query (p_sql IN VARCHAR2) is
    v_v_val varchar2 (4000);
    number of v_n_val;
    date of v_d_val;
    number of v_ret;
    c number;
    number d;
    whole col_cnt;
    Boolean f;


    rec_tab dbms_sql.desc_tab;
    number of col_num;
    v_rowcount number: = 0;
    Start
    -create a slider
    c: = dbms_sql.open_cursor;
    -analyze the SQL statement in the cursor
    DBMS_SQL. Parse (c, p_sql, dbms_sql.native);
    -run the cursor
    d: = dbms_sql.execute (c);
    --
    -Describe the columns that are returned by the SQL statement
    DBMS_SQL. DESCRIBE_COLUMNS (c, col_cnt, rec_tab);
    --
    -Local variables Bind to return to the different columns according to their types
     
    dbms_output.put_line (' number of columns in the query: ' | col_cnt);
    1.col_cnt j
    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
    12. When can dbms_sql.define_column (c, j, v_d_val);     -Date
    on the other
    DBMS_SQL.define_column (c, j, v_v_val, 2000);  -Any other type of return as varchar2
    end case;
    end loop;
    --
    -Display columns are returned...
    dbms_output.put_line ('- Columns-');
    1.col_cnt j
    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 can "DATE".
    "Otherwise, 'Other' end);
    end loop;
    dbms_output.put_line('---');
    --
    -This part generates the DATA
    loop
    -Retrieves a row of data using the cursor
    v_ret: = dbms_sql.fetch_rows (c);
    -Output when no more line
    When the output v_ret = 0;
    v_rowcount: = v_rowcount + 1;
    dbms_output.put_line (' line: ' | v_rowcount);
    dbms_output.put_line('---');
    -Extract the value of each column of the row
    1.col_cnt j
    loop
    -Fetch each column to the correct data type according to 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);
    12. When can 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'));))
    on the other
    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're done with it
    DBMS_SQL.close_cursor (c);
    END;
    /

    SQL > run_query exec ('select ename, empno, sal, deptno from emp where deptno = 10');
    Number of columns in the query: 4
    -Columns-
    EMPNO - NUMBER
    ENAME - VARCHAR2
    DEPTNO - NUMBER
    SAL - NUMBER
    -------------
    Line: 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.

    As you can see with this method, you can extract the column details, including the name and data etc. types and then extract each line and extract the data from the column position.

    Of course, this is quite complex, so it would be a last resort.

  • OBIEE dynamic column headings based repository Variables

    Hello

    How can we provide variable name of the repository (from RPD) as column headings in reports (presentation Services).

    Can you please suggest me how to do it?

    Thanks in advance...

    RAM

    Hello

    You can use the following link.

    Oracle Business Intelligence 11g: OBIEE 11 g dynamic column headings

    I used the variable presentation here, you can substitute the variable repository. The difference is that you don't need to create variable presentation, instead you use repository variable there.

    If you are not clear with this, pleas come back. I'll write a new message on your problem.

  • display the data in the column as column name

    in this column of query names are hard coded, I need to display the column name dynamically (based on sysdate). Please help me on this?

    with test_emp as

    (select 100 empno, 1st February 2014 ' hiredate, SAL union 1000 double all the)

    Select 200 empno, February 3, 2014 ", 2000 union SAL double all the"

    Select empno 300, 4 February 2014 ", 3000 union SAL double all the"

    Select 400 empno, 5 February 2014 ", 4000 SAL double

    )

    -Select * from test_emp

    SELECT EmpNo,

    Sum (decode (HireDate, trunc (sysdate), SAL, 0)) as '4 February 2014. "

    Sum (decode (HireDate, SAL, trunc(sysdate-1), 0)) as "February 3, 2014.

    Sum (decode (HireDate, trunc (sysdate)-2, SAL, 0)) as 'February 2, 2014.

    Sum (decode (HireDate, trunc (sysdate)-3, SAL, 0)) as 'February 1st, 2014. "

    Sum (decode (HireDate, trunc (sysdate)-4, SAL, 0)) as 'January 31, 2014.

    OF test_emp

    Group by empno stopped by 1

    expected results:

    EMPNO February 4, 2014 3 February 2014 2 February 2014 February 1, 2014 January 31, 2014

    100                     0                    0                       0                   1000               0

    200                     0                   2000                    0                   0                   0

    300                 3000                    0                       0                   0                   0

    400                     0                       0                       0                 0                    0

    Hello..

    We cannot manage dynamic crossover into a sql. So what I did just create a function with refcursor and get results. It will work for your case only. Try the code below and let me know in case of any problems

    FUNCTION to CREATE or REPLACE dyn_row_colum

    RETURN SYS_REFCURSOR

    AS

    v_sqlstr VARCHAR2 (32767): = ' SELECT empno, SUM (DECODE (hiredate,'|)) '''|| Trunc (sysdate) | " ((' |', sal, 0))' | ' '||'"'|| TRUNC (SYSDATE) |' » ' || «, » ;

    v_rfcur SYS_REFCURSOR;

    BEGIN

    FOR j_rec IN (SELECT col_val FROM test_emp TRUNC(SYSDATE-ROWNUM))

    LOOP

    v_sqlstr: = v_sqlstr | » '||' SUM (DECODE (hiredate,'|)) '''|| j_rec.col_val | " ((' |', sal, 0))' | ' '||'"'|| j_rec.col_val |'"' | ',';"

    END LOOP;

    v_sqlstr: = RTRIM (v_sqlstr, ','). » '||' OF test_emp GROUP BY empno';

    V_rfcur OPEN FOR v_sqlstr;

    RETURN v_rfcur;

    EXCEPTION

    WHILE OTHERS THEN

    LIFT;

    END dyn_row_colum;

    VARIABLE v_cur REFCURSOR

    EXEC: v_cur: = dyn_row_colum;

    PRINT v_cur;

    SELECT dyn_row_colum FROM dual;

    Unit tests: -.

    ----------------

    Scott@ORCL > dyn_row_colum FUNCTION to CREATE or REPLACE

    2 SYS_REFCURSOR RETURN

    3 AS

    4 v_sqlstr VARCHAR2 (32767): = ' SELECT empno, SUM (DECODE (hiredate,'|)) '''|| Trunc (sysdate) | " ((' |', sal, 0))' | ' '||'"'|| TRUNC (SYSDATE) |' » ' || «, » ;

    5 v_rfcur SYS_REFCURSOR;

    6 BEGIN

    7 FOR j_rec IN (SELECT col_val FROM test_emp TRUNC(SYSDATE-ROWNUM))

    8 LOOP

    9 v_sqlstr: = v_sqlstr | » '||' SUM (DECODE (hiredate,'|)) '''|| j_rec.col_val | " ((' |', sal, 0))' | ' '||'"'|| j_rec.col_val |'"' | ',';"

    10 END OF LOOP;

    11 v_sqlstr: = RTRIM (v_sqlstr, ','). » '||' OF test_emp GROUP BY empno';

    12 v_rfcur OPEN FOR v_sqlstr;

    13 RETURN v_rfcur;

    14 EXCEPTION

    15 SO THAT OTHERS THEN

    16 RAISE;

    17 END dyn_row_colum;

    18.

    The function is created.

    Scott@ORCL > v_cur VARIABLE REFCURSOR

    Scott@ORCL > EXEC: v_cur: = dyn_row_colum;

    PL/SQL procedure successfully completed.

    Scott@ORCL > v_cur PRINT;

    EMPNO 5 FEBRUARY 14 FEBRUARY 4, 14 3 FEBRUARY 14 FEBRUARY 2 14 1 FEBRUARY 14

    ---------- ---------- ---------- ---------- ---------- ----------

    100          0          0          0          0       1000

    400       4000          0          0          0          0

    300          0       3000          0          0          0

    200          0          0       2000          0          0

    Scott@ORCL > dyn_row_colum SELECT FROM dual;

    DYN_ROW_COLUM

    --------------------

    CURSOR STATEMENT: 1

    CURSOR STATEMENT: 1

    EMPNO 5 FEBRUARY 14 FEBRUARY 4, 14 3 FEBRUARY 14 FEBRUARY 2 14 1 FEBRUARY 14

    ---------- ---------- ---------- ---------- ---------- ----------

    100          0          0          0          0       1000

    400       4000          0          0          0          0

    300          0       3000          0          0          0

    200          0          0       2000          0          0

  • Extraction of values based on column names

    Hello

    I have three tables. Table A table contains a column with all column_names in the table b. table B is to have an emp_id and other fields that are stored as values in the column of the TABLE.  I need to get the emp_id and value from the column of table B based on data of Table A. and store it in another table.

    Example:

    Table has -col1

    Emp_name

    Emp_sal

    Emp_dept

    Table B

    Emp_id Emp_name Emp_sal Emp_dept

    1001 ABC 1000 sales

    1002 XYZ 2000 SVC

    TABLE C

    Emp_id Emp_details value

    1001 Emp_name ABC

    1001 Emp_sal 1000

    1001 Emp_dept sales

    1002 Emp_name XYZ

    1002 Emp_sal 2000

    1002 Emp_dept SVC

    Using the list of TABLE A, I have to select each Id and corresponding to the value of TABLE B and even insert in TABLE C. I know that we can use a loop for, but I have trouble choosing the name of column based on the value of the slider. Can anyone help?


    Hello

    Looks like you want to do 2 things rather difficult:

    (1) unpivot data from several columns in the column 1 value

    (2) get the column names for the another table unpivot operator

    Let's start with how you could do just part 1, unpivoting data:

    INSERT INTO table_c (emp_id, emp_details, value)

    WITH all_varchar2 AS

    (

    SELECT emp_id

    emp_name

    TO_CHAR (emp_sal) AS emp_sal

    emp_dept

    --Include all columns, you might need

    OF table_b

    )

    SELECT emp_id, emp_details, value

    Of all_varchar2

    UNPIVOT (value

    FOR emp_details IN

    (emp_name - dynamic

    emp_sal - dynamic

    emp_dept - dynamic

    )

    )

    ;

    Value is a column, everything happens in this column must have the same (or a very similar) data type.  The subquery all_varchar2 converts all columns that you can rotate in VARCHAR2s (if they are not already VARCHAR2s) so that they are ready to rotate.  You might consider doing a permanent display for this.

    Now, instead of hard-Ghoshal the 3 line marked "Dynamics", you seek to table_a.  You will know beforehand what are these columns, and you won't even know there will be the number of columns. You need instructions SQL dynamic to write this part of the INSERT statement for you at run time.

    Here's a way to do it in SQL * more and SQL:

    -The preliminary motion

    COLUMN col_list_col by col_list new_value

    SELECT LISTAGG (col1, ',') within THE GROUP (ORDER BY col1)

    AS col_list_col
    FROM table_a;

    -Main return (dynamic):

    INSERT INTO table_c (emp_id, emp_details, value)
    WITH all_varchar2 AS
    (
    SELECT emp_id
    emp_name
    TO_CHAR (emp_sal) AS emp_sal
    emp_dept
    --Include all columns, you might need
    OF table_b
    )
    SELECT emp_id, emp_details, value
    Of all_varchar2
    UNPIVOT (value
    FOR emp_details IN
    (& col_list
    )
    )
    ;

    Dynamic SQL often works like this.  First, you make a preliminary motion to write the part that is not know before execution.  Then, you run the main statement, which has the integrated preliminary query results.

    If you do this in PL/SQL, you use a string variable ordinary for col_list, instead of a substitution variable.

  • Creating a dynamic column editable

    I tried to make my dynamic columns as editable. The problem is that my dynamic columns are nested.

    Now editable column works fine when I have diff columns with a different name. For example, col1, col2, col3 (not nested)

    Or I nested columns like "pass"(parent) given two columns col1 and col2. ".

    But, when I use them in a dynamic of columns in which all of them have the same name, in the example below, each with the same name 'col', I can change all of them, but the textfield never faded away, when I click on ENTER.


    Suppose I have an editable column with col name:
    for (final CategoryTypeVO type : typeList)
                    {
                           TableColumn<ItemVO, Integer> col = new TableColumn<ItemVO, Integer>(type.getTypeName());
                          col.setMinWidth(100);
                          col.setEditable(true);
                          col.setCellFactory(cellFactory);
                         
                         
                          col.setOnEditCommit(
                                   new EventHandler<TableColumn.CellEditEvent<ItemVO, Integer>>() {
                                   public void handle(TableColumn.CellEditEvent<ItemVO, Integer> t) {
                                   ((ItemVO)t.getTableView().getItems().get(
                                   t.getTablePosition().getRow())).getListType().get(type.getTypeId()).setQuantity(t.getNewValue());
                                   }
                                   });
                           quantity.getColumns().add(col);
                         }
    and cellfactory as:
    final Callback<TableColumn<ItemVO, Integer>, TableCell<ItemVO, Integer>> cellFactory = new Callback<TableColumn<ItemVO, Integer>, TableCell<ItemVO, Integer>>() {
                        public TableCell call(TableColumn p) {
                             return new EditingCell();
                        }
                   };
    and Editing class as
    class EditingCell extends TableCell<ItemVO, Integer> {
               
               private TextField textField;
              
               public EditingCell() {}
              
               @Override
               public void startEdit() {
                   super.startEdit();
                  
                   if (textField == null) {
                       createTextField();
                   }
                  
                   
                   setGraphic(textField);
                   setContentDisplay(ContentDisplay.GRAPHIC_ONLY);
                   textField.selectAll();
                   Platform.runLater(new Runnable() {
                       @Override
                       public void run() {
                           textField.requestFocus();
                       }
                  });
               }
              
               @Override
               public void cancelEdit() {
                   super.cancelEdit();
                  
                   setText(String.valueOf(getItem()));
                   setContentDisplay(ContentDisplay.TEXT_ONLY);
               }
          
               @Override
               public void updateItem(Integer item, boolean empty) {
                   super.updateItem(item, empty);
                  
                   if (empty) {
                       setText(null);
                       setGraphic(null);
                   } else {
                       if (isEditing()) {
                           if (textField != null) {
                               textField.setText(getString());
                           }
                           setGraphic(textField);
                           setContentDisplay(ContentDisplay.GRAPHIC_ONLY);
                       } else {
                           setText(getString());
                           setContentDisplay(ContentDisplay.TEXT_ONLY);
                       }
                   }
               }
               
              
               
          
               private void createTextField() {
                   textField = new TextField();
                   //textField.setText(getString());
                   textField.setText("0");
                   textField.setMinWidth(this.getWidth() - this.getGraphicTextGap()*2);
                   
                   textField.focusedProperty().addListener(new ChangeListener<Boolean>() {
    
                          @Override
                          public void changed(ObservableValue<? extends Boolean> arg0, Boolean arg1, Boolean arg2) {
                              if (!arg2) {
                                  commitEdit(Integer.parseInt(textField.getText()));
                              }
                          }
                      });
                   
                   textField.setOnKeyReleased(new EventHandler<KeyEvent>() {
                       @Override public void handle(KeyEvent t) {
                           if (t.getCode() == KeyCode.ENTER) {
                               commitEdit(Integer.parseInt(textField.getText()));
                           } else if (t.getCode() == KeyCode.ESCAPE) {
                               cancelEdit();
                           }
                       }
                   });
               }
    
              
               private String getString() {
                   return getItem() == null ? "" : getItem().toString();
               }
    Now what happens is this thing works fine if I separate columns with distinct names. But when it comes to dynamic columns, it fails, once I have edit a cell, the text field never leaves his place. It gets stuck in the cell. Any help!

    Published by: abhinay_a on January 21, 2013 12:31 AM

    Do not know what is the problem in your code, but it is easier to use TextFieldTableCell than building your own TableCell from scratch.

    This change to the example I posted in How to create a tableview for this? works for me:

    package itemtable;
    
    import javafx.application.Application;
    import javafx.beans.value.ChangeListener;
    import javafx.beans.value.ObservableValue;
    import javafx.scene.Scene;
    import javafx.scene.control.ChoiceBox;
    import javafx.scene.control.TableColumn;
    import javafx.scene.control.TableColumn.CellDataFeatures;
    import javafx.scene.control.TableView;
    import javafx.scene.control.cell.PropertyValueFactory;
    import javafx.scene.control.cell.TextFieldTableCell;
    import javafx.scene.layout.BorderPane;
    import javafx.stage.Stage;
    import javafx.util.Callback;
    import javafx.util.converter.NumberStringConverter;
    
    public class ItemTable extends Application {
    
      @Override
      public void start(Stage primaryStage) {
        final DAO dao = new MockDAO();
        final ChoiceBox choiceBox = new ChoiceBox();
        choiceBox.getItems().setAll(dao.getCategories());
    
        final TableView table = new TableView();
    
        // Make table editable:
        table.setEditable(true);
    
        final TableColumn nameCol = new TableColumn("Name");
        nameCol.setCellValueFactory(new PropertyValueFactory("name"));
        nameCol.setCellFactory(TextFieldTableCell.forTableColumn());
        final TableColumn priceCol = new TableColumn("Price");
        table.getColumns().addAll(nameCol, priceCol);
    
        choiceBox.getSelectionModel().selectedItemProperty()
            .addListener(new ChangeListener() {
              @Override
              public void changed(ObservableValue observable, Category oldValue, Category newValue) {
                table.getItems().clear();
                priceCol.getColumns().clear();
                for (final Type type : newValue.getTypes()) {
                  final TableColumn col = new TableColumn(type.getName());
                  col.setCellValueFactory(new Callback, ObservableValue>() {
                    @Override
                    public ObservableValue call(CellDataFeatures cellData) {
                      Item item = cellData.getValue();
                      if (item == null) {
                        return null;
                      } else {
                        return item.priceProperty(type);
                      }
                    }
                  });
    
                  // Make column editable:
                  col.setEditable(true);
                  col.setCellFactory(TextFieldTableCell.forTableColumn(new NumberStringConverter()));
    
                  priceCol.getColumns().add(col);
                }
                table.getItems().setAll(dao.getItemsByCategory(newValue));
              }
            });
    
        BorderPane root = new BorderPane();
        root.setTop(choiceBox);
        root.setCenter(table);
    
        Scene scene = new Scene(root, 600, 600);
        primaryStage.setScene(scene);
        primaryStage.show();
      }
    
      public static void main(String[] args) {
        launch(args);
      }
    }
    

    Edited by: James_D January 22, 2013 07:22

  • IN parameter is the string of column names I want to SELECT delimited

    Hi guys,.

    Please bare with me. Not a pro at writing stored procedures.

    What I try to do is to pass a parameter of 'IN' to the proc. The setting is a varchar2 which is a comma-delimited string.
    I want to put this string in the SELECT statement.

    This setting is called "P_SelectFields".

    The value in the passage in the proc is like:
    P_SelectFields = ' CUSTOMERS SUM (CLI_SERVED) AS SUM (EI_INTC) + SUM (NEI_INTC) AS INTERVENTIONS,
    SUM (TOT_EMPRTN) AS EMP_RETURN, SUM (TOTAL_RTS) AS SCHOOL_RETURN
    "


    That's what I've got and I know that it works, if I put the string instead of the parameter it works. !

    PROCEDURE GET_NATIONAL_TOTAL_RESULTS (P_SelectFields IN varchar2, P_AGREEMENT_TYPE_IND AGREEMENT_TYPE.agreement_type_ind%TYPE, io_cursor in SYS_REFCURSOR)
    IS
    BEGIN
    OPEN FOR Io_cursor

    SELECT year_desc,
    P_SelectFields - that's where I want my partameter go.

    OF SPF_RESULT_VW
    WHERE r_num = 1 - FILTER for the LAST PERIOD for EACH YEAR
    and agreement_type_ind = P_AGREEMENT_TYPE_IND - desired FILTER FOR Agreement_type_ind
    GROUP BY year_desc
    ORDER BY year_desc
    ;

    END GET_NATIONAL_TOTAL_RESULTS;


    That's what I'm after you run the proc.

    YEAR_DESC = 2011-2012
    : B2 = SUM (CLI_SERVED) ACE, SUM (EI_INTC) CUSTOMERS + EMP_RETURN SUM (NEI_INTC) AS OF THE INTERVENTIONS, SUCH AS SUM (TOT_EMPRTN), SUM (TOTAL_RTS) SCHOOL_RETURN

    Where is ': B2 = "come from?".

    What can I do to make my parameter is "picked up" by the proc?

    Thank you

    Firstly: in relational databases, there is no distinction between 'fields '. Tables is not 'fields', they have columns.
    It is my experience that that call columns 'fields' basically treats the database as a flat file system. It's a very bad idea!

    If you want to pass as a parameter column names, you need dynamic SQL.
    However, PL/SQL was invented to reduce the analysis and using of the dynamic SQL, you'll at least soft-parse each statement.

    Dynamic SQL is obviously in the documentation, but most people here think that they don't need to read the documentation.

    So, for once
    glance

    OPEN io_cursor FOR
    'SELECT year_desc,'||
    P_SelectColumns||
    ' FROM SPF_RESULT_VW '||
    'WHERE r_num = 1 '|| --FILTER FOR LATEST PERIOD FOR EACH YEAR
    'and agreement_type_ind = P_AGREEMENT_TYPE_IND '||-- FILTER FOR desired Agreement_type_ind
    'GROUP BY year_desc '||
    'ORDER BY year_desc'
    ;
    

    Please note that I have renamed the parameter.

  • Dynamic column headings

    You will need to run a report on the budget for the past 3 calendar years. I can produce the report but has difficulty to print the column position properly review this report need to run each year. Is it possible to appoint the year on appropriate using bi publisher and APEX V4 column header?

    Oracle: 10G

    ex:
    If the report runs this year: column must be 2010,2009,2008.
    If the report is run next year: column name must be 2011,2010,2009
    .....

    Thank you.



    Tai

    Published by: tai84 on October 27, 2011 12:27

    Oops, Yes, the password has expired. I have reset. Try again... same settings.

    I was not aware of the position PL/SQL column type. You can specify in the 'Report of the attributes' tab in your area. At the top of this page, there is a section of Type "headings". If you click on the option button "PL/SQL", it displays a text box field to specify PL/SQL code to determine the column headers. This is what is used in my sample application. It calls the function 'GET_QUERY_COLS', you can find the SQL Workshop of my sample workspace area.

    A brief description of what is happening in my example...

    In my area "Dynamic motion", I run a dynamic SQL query because the values of the year for the columns are unknown. It runs the report of dynamic query and stores the dynamic query to the P1_REPORT_QUERY point. Then, this value of the element is passed in the function GET_QUERY_COLS that returns the name of the column, that I need. Of course, I have the user selects a range which essentially defines the columns, I need.

    Thank you
    Mark

  • Generate CSV with pl.sql column names

    Hi guys,.

    Well, I am back after a long hiatus in this form, was occupied by SAP BI project.

    Now do some oralce - sap project, well here, I needed to generate a CSV of many many queries,

    I can do via sql, but I tot it would be better to write a package or a common procedure to generate csv files

    ex, if I pass the query to the proceudre it should generate csv on the server directory file, later I send these file to the users concerned.

    The e-mail part is later, but first of all is to have a package of generic to launch and run the query n generate the csv file.

    I guess this should be possible using native dynamic sql and utl_ package, but I don't know how to get the columns name,

    If one has implemented this please explain me the way,.

    ex:
    Select emp,mgr, empno from emp;
    
    emp mgr empno
     1    1    123
      2   1    234
    
    something like that
    hope my question is clear 

    Maybe try this

    http://asktom.Oracle.com/pls/asktom/asktom.download_file?p_file=6551135514501758779

  • use a (selection list) element as the column name in the select?

    I have a popup LOV key based on a select (dynamic list of values)
    I want to display and return - select columns in the select statement to be determined by another list.

    I tried:

    Select distinct: P133_COLUMN d: P133_COLUMN r
    FROM MyTable

    but then I don't you the value of: P133_COLUMN... so if: P133_COLUMN is 'EMPNO' LOV popup displays the text "EMPNO" and referred the text 'EMPNO', not the empno column values...

    If I change

    Select distinct P133_COLUMN d & P133_COLUMN r
    FROM MyTable

    I get the standard
    "LOV query is not valid, a display and a return value is needed, the column names must be different. If your query contains a query online, the first CLAUSE in the SQL statement must not belong to the query online. »

    Anyone?

    Also, I was wondering if it is possible to set the textfield object in the item popup LOV to accept the input text directly as well as the selected value, but the first part of the question is the important part.

    Concerning

    Andreas

    Hello Andy,

    Change your LOV to something like this:
    'select' return. : P133_COLUMN |' d, ' | : P133_COLUMN | "as r from myTable";

    Greetings,
    Roel

    http://roelhartman.blogspot.com/

  • Dynamic cfgridcolumn name?

    Hello

    I have a query that will return different columns according to the entry. I'm trying to get the dynamic name of cfgridcolumn. For example, in code below column name ABC has been hard-coded.

    < bindonload cfgrid = "yes" bind = "cfc:xyz.entityList ({cfgridpage}, {cfgridpagesize}, {cfgridsortcolumn}, {cfgridsortdire ction})" >
    < name cfgridcolumn = 'ABC' header = 'ABC' / >
    < / controls cfgrid >

    Is there a way were, we can cite the columnname as a variable? Something similor to:

    < bindonload cfgrid = "yes" bind = "cfc:xyz.entityList ({cfgridpage}, {cfgridpagesize}, {cfgridsortcolumn}, {cfgridsortdire ction})" >
    < cfloop list = "" #entityList.ColumnList # "index 'index' = >"
    < name cfgridcolumn = 'ABC' header = 'ABC' / >
    < / cfloop >
    < / controls cfgrid >

    Any help would be greatly appeciated.

    Thank you very much

    Convert a table like, your columnlist

    Then you can assign it to a gridcolumn as,



    HTH

Maybe you are looking for