Retrieving Column Names from a Query

I need to be able to generate XML that looks like this:
<Categories>
<Category Name='Arrivals'/>
<Category Name='Departures'/>
<Category Name='Unused'/>
<Category Name='Out of Commission'/>
</Categories>
Where the name attribute value is the name of columns in a query. For example, a standard SQL query might look something like this:
select
year, arrivals, departures, unused, out_of_commission
from
some_table
I am able to generate the XML that represents the data just fine. However, my vended application is requiring this column header information. I've browsed and searched the XMLDB documentation but could not see a way to retrive the column names returned by the query. I think I Just need to be pointed in the right direction.
Thanks,
Steve

What technique are you itending using to generate the XML ?.
Does something like this work
select xmlelement("Categories",
xmlelement("Category", xmlattributes('Arrivals' as "Name"), Arrivals),
xmlelement("Category", xmlattributes('Departures' as "Name"), Departures),
xmlelement("Category", xmlattributes('Unused' as "Name"), Unsused),
xmlelement("Category", xmlattributes('Out Of Commission' as "Name"), Out_of_Commission)
from some_table

Similar Messages

  • How to retrieve column names in a query in a case sensitive way

    Given a query, I want to extract all the column names/aliases in the query in a case-sensitive way.
    When I use dbms_sql.describe_columns() or java.sql.ResultSetMetaData classes getColumnName() or getColumnLabel()
    it returns the columns name ONLY in Upper case.
    My application needs to extract the column names in the same case as it appears in the query string.
    Is there any API to get this without parsing the SQL query string?
    Thanks
    PS: The dbms_sql.describe_columns() returns the column name in upper case.
    declare
    IS
    l_column_recs DBMS_SQL.DESC_TAB;
    l_cur NUMBER;
    l_column_count NUMBER;
    BEGIN
    l_cur := dbms_sql.open_cursor;
    dbms_sql.parse(l_cur, 'select target_type from targets', dbms_sql.NATIVE);
    dbms_sql.describe_columns(l_cur, l_column_count, l_column_recs);
    FOR i IN l_column_recs.FIRST..l_column_recs.LAST
    LOOP
    dbms_output.put_line(l_column_recs(i).col_name);
    end loop;
    end;
    /

    As far as the result set is concerned, though, the column name is in all upper case. If you query the data dictionary, you would see that the TARGET_TYPE column in the TARGETS table is stored in upper case.
    The way Oracle works is that column names that are not enclosed in double-quotes are converted to upper case in the data dictionary and elsewhere and then Oracle looks for the column name in the table definition. That is what allows Oracle to have case-insensitive identifiers unless a user specifies case-sensitive identifiers by enclosing the identifier in double quotes.
    If you changed the query to be
    SELECT target_type as "target_type"
      FROM targetsOracle should report the alias in a case sensitive fashion because you've now indicated that the alias should be treated as case sensitive.
    Justin

  • How to retrieve column name from Excel using POI HSSF eventusermodel?

    Hi ,
    I am simply reading the excel sheet and writing in a txt file. I have done the following in the switch construct. It works fine but I want to retrieve only the column header. But this code gives me all available strings in the excel sheet. Any pointer would be greatly appreciated.
    case SSTRecord sid : 
             SSTRecord sstrecord = (SSTRecord) record;
             for (int i=0; i<sstrecord.getNumUniqueStrings(); i++){      
                  System.out.println(" Column name" +  sstrecord.getString(i));
    break;bye for now
    Sat

    try labels:
            case LabelSSTRecord.sid:
                LabelSSTRecord lrec = (LabelSSTRecord) record;
                if (lrec.getRow() == 0) {
                    System.out.println(" Column name "
                            + sstrec.getString(lrec.getSSTIndex()));
                break;

  • Query the column names from Public database links

    Greetings,
    I would like to retrieve the list of all the column names from a public database link. A regular ALL_TAB_COLUMNS doesn't seem to be working.
    Thanks
    John9569

    Hi,
    I think your DBA needed to create a synonym for you to have access of that remote database view.
    CREATE SYNONYM synonym_name
    FOR view_name@db_link;Then you can find the column names by
    DESC   synonym_nameGuru's , please correct me If I am wrong.
    Thanks
    Edited by: user10679113 on Mar 12, 2009 12:28 PM
    Edited by: user10679113 on Mar 12, 2009 12:33 PM

  • How to pull only column names from a SELECT query without running it

    How to pull only column names from a SELECT statement without executing it? It seems there is getMetaData() in Java to pull the column names while sql is being prepared and before it gets executed. I need to get the columns whether we run the sql or not.

    Maybe something like this is what you are looking for or at least will give you some ideas.
            public static DataSet MaterializeDataSet(string _connectionString, string _sqlSelect, bool _returnProviderSpecificTypes, bool _includeSchema, bool _fillTable)
                DataSet ds = null;
                using (OracleConnection _oraconn = new OracleConnection(_connectionString))
                    try
                        _oraconn.Open();
                        using (OracleCommand cmd = new OracleCommand(_sqlSelect, _oraconn))
                            cmd.CommandType = CommandType.Text;
                            using (OracleDataAdapter da = new OracleDataAdapter(cmd))
                                da.ReturnProviderSpecificTypes = _returnProviderSpecificTypes;
                                //da.MissingSchemaAction = MissingSchemaAction.AddWithKey;
                                if (_includeSchema == true)
                                    ds = new DataSet("SCHEMASUPPLIED");
                                    da.FillSchema(ds, SchemaType.Source);
                                    if (_fillTable == true)
                                        da.Fill(ds.Tables[0]);
                                else
                                    ds = new DataSet("SCHEMANOTSUPPLIED");
                                    if (_fillTable == true)
                                        da.Fill(ds);
                                ds.Tables[0].TableName = "Table";
                            }//using da
                        } //using cmd
                    catch (OracleException _oraEx)
                        throw (_oraEx); // Actually rethrow
                    catch (System.Exception _sysEx)
                        throw (_sysEx); // Actually rethrow
                    finally
                        if (_oraconn.State == ConnectionState.Broken || _oraconn.State == ConnectionState.Open)
                            _oraconn.Close();
                }//using oraconn
                if (ds != null)
                    if (ds.Tables != null && ds.Tables[0] != null)
                        return ds;
                    else
                        return null;
                else
                    return null;
            }r,
    dennis

  • Getting table name from a query

    Hi, I'm trying to get the table name from my sql query
    My code is as follows;
    ResultSetMetaData metadata = rs.getMetaData();
    for (int i = 1; i < metadata.getColumnCount(); i++)
    System.out.println(metadata.getTableName(i));
    I just get a blank output. Yet my sql query executes and I can pull down the records, and grab the column names from the result sets.
    Any ideas on how I can get the table name for the columns. The reason being is on one of my querys I'm using join statements and i need to retrieve the table name for the column i'm displaying, as some tables have similar column names.
    Thanks in advance.

    Hi,
    What db are you using?
    I also get a blank output with ResultSetMetaData.getTableName because Oracle doesn't implement this method.
    Why do you not know the table name anyway?
    regards
    Nick

  • XMII Converting Column Name from "14_name_g/L" to "_14_name_g_L"?

    Hi,
    Is there a way to stop XMII from automatically converting the oracle column name "14_name_g/L" to "_14_name_g_L"?  Or is there anything I can do to change it so that the right column name is displayed to the user?
    I looked in the XML output of the query template in the BLS and the Column description is correct, but the column name gets automatically converted by XMII.
    Additionally, I tried entering the column name "14_name_g/L" directly into an XML variable in a BLS transaction (as part of a valid xml document) and received the error:  "Invalid XML String: The content of elements must consist of well-formed character data or markup.
    I also tried converting the XMLOutput of the Query with an XSLT, but it didn't seem to work and if XMII won't accept the correct format in an XML variable I wasn't very optimistic about the XSLT working without XMII converting the XML document back to the format it prefers.
    Any thoughts or ideas of what I can do about this? 
    Thanks alot for the help!
    Kerby

    Thanks everyone for the response.  I think I need to provide a few more details about our implementation to clarify things. 
    This situation comes up when we are doing a 'CrossTab' or 'Pivot' of data in the database and returning it to the user as a CSV file.  The pivoted columns we are creating are the distinct <materialNo>_<ParameterName>_<ParameterUOM> from the original data.  The result of the query template is directly returned to the user as a CSV file, and so the columns are never shown in an applet or grid.  We are also running into the Oracle 30 character limit for column names, so would prefer to keep the current convention of "14_name_g/L" instead of adding the g_per_L idea.  Because we are pivoting on the data present in the original columns, the column name is not known ahead of time. 
    Is there any way to do change this after retrieving the data from the query template so it can be displayed correctly?  Or do I need to look for alternatives?
    From the OutputXML of the calling Query Template, an example problem column looks like:
    <Column Description="14_Conductivity_g/L" MaxRange="1" MinRange="0" Name="_14_Conductivity_g_L" SQLDataType="12" SourceColumn="14_Conductivity_g/L" />
    and then the actual xml rows have the column name as the identifier. 
    <row>
    <_14_Conductivity_g_L>17</_14_Conductivity_g_L>
    </row>
    What I have tried is to create an xslt which overwrites the column name with column description.  That did not work as it still showed the leading '_' and replaced the '/' with '_'.  I am not sure if it didn't work because of the inaccurate column name in the row definition or if XMII replaced the column name again with its preferred column definition.  I considered trying to change the xslt to also overwrite the columnName in the rows with the correct columnName, but I wasn't sure if that would work either or XMII would overwrite the values anyway?
    Thoughts or ideas for workarounds?  Or is this pretty much the limitation and need to accept the leading _ and find another separator for  g/L?
    Thanks alot for the help!
    Kerby

  • Lookup column names with Power Query

    Hi,
    before I go ahead and change source files, I was wondering if I can use Power Query to get a model with the following data. To simplify the example, I have the following dataset in an Excel sheet:
    In another Excel sheet, the column names are defined, for example:
    What would like to have in Power Query is one table with the column names from the second screenshot in column B. Is there a way to link these two tables together in Power Query in order to use these names as column headers in the dataset?
    Thanks!
    - If a post answers your question, please click "Mark As Answer" on that post!

    You can filter the list of renames against the list of actual column names with something like
        FilteredColumns = Table.SelectRows(Columns, each List.Contains(Table.ColumnNames(Source), [Name])),
    Again, the working end-to-end:
    let
    Source = Table.FromRows({{"New York", 23, 51, 732}, {"Chicago", 25, 421, 23}, {"Los Angeles", 632, 22, 423}}, {"City", "Col 1", "Col 2", "Col 3"}),
    Columns = Table.FromRows({{"Col 1", "Column 1"}, {"Col 2", "Column 2"}, {"Col 3", "Column 3"}, {"Col 4", "Column 4"}}, {"Name", "Value"}),
    FilteredColumns = Table.SelectRows(Columns, each List.Contains(Table.ColumnNames(Source), [Name])),
    ColumnsAsRenames = Table.TransformRows(FilteredColumns, Record.FieldValues),
    RenamedColumns = Table.RenameColumns(Source, ColumnsAsRenames)
    in
    RenamedColumns

  • Retrieve column names of a table!!

    Hi all,
    I want to retrieve column names of a table 'test' whose values are null
    For ex:
    select * from test
    will give the results as
    column_1 column_2 column_3 column_4
    111
    lets consider the case that the table has only one record.
    accordingly we have to get column_2 ,column_3 and column_4 as the result.
    i tried dynamic 'execute immediate' statement and tried to extract in one single execute immediate statement but i was not able to accomplish because of the multiple columns.
    is it possible without using a pl/sql function or procedure??

    Check this:
    SQL> INSERT INTO my_Test values('ABCD',NULL,NULL);
    1 row created.
    SQL> COMMIT;
    Commit complete.
    SQL> select * from my_Test;
    COL1       C COL3
    ABCD
    SQL> declare
      2  CURSOR C1 IS SELECT column_name FROM all_tab_cols WHERE table_name = 'MY_TEST';
      3  v_sql VARCHAR2(10000) := NULL;
      4  my_null_col_list VARCHAR2(32767) := NULL;
      5  my_cnt NUMBER := 0;
      6  BEGIN
      7  FOR I in C1 LOOP
      8  v_sql := 'SELECT COUNT(*) FROM my_test WHERE '||I.column_name ||' IS NULL';
      9  execute immediate v_sql INTO my_cnt;
    10  IF (my_cnt > 0) THEN
    11  my_null_col_list := my_null_Col_list||','||I.column_name;
    12  END IF;
    13  END LOOP;
    14  my_null_col_list := SUBSTR(my_null_col_list,2);
    15  dbms_output.put_line('Columns that have null values for table my_Test are:'||my_null_col_list);
    16  END;
    17  /
    Columns that have null values for table my_Test are:COL2,COL3
    PL/SQL procedure successfully completed.
    SQL> desc my_test;
    Name                                      Null?    Type
    COL1                                               VARCHAR2(10)
    COL2                                               VARCHAR2(1)
    COL3                                               VARCHAR2(10)
    SQL>

  • Getting column names from cursor

    Hi all
    I have procedure which produces list of applied for jobs web page(using htp. package)
    I got result in cursor, but have to provide dinamic sort, based on colimn pressed
    procedure my_application_list
    (pi_resume_num     in varchar2 default null
    ,pi_sort_col     in varchar2 default null
    ,pi_page_no     in varchar2 default null
    ,pi_action     in varchar2 default null
    ,pi_msg          in varchar2 default null
    is
    CURSOR cur_job IS
         SELECT      jtl.JOB_TITLE
              ,jtl.COMPANY_NAME
              ,a.APPLY_DATE
              ,a.lang
              ,a.job_id
         FROM job_tl jtl, applied_for_job a, gateway gt
         WHERE a.job_seeker_id=app.job_Seeker
         AND a.job_id=jtl.job_id
         AND a.lang=jtl.lang
         AND a.gateway=gt.gateway
         AND jtl.lang=(SELECT substr(MIN(lt.order_list||jtl0.lang),2) lang
                   FROM      job_tl jtl0
                        ,language_tl lt
                   WHERE jtl0.job_id = a.job_id
                   AND jtl0.lang=lt.lang
                   AND lt.gui_lang=app.language)
         ORDER BY pi_sort_col
    rest of code
    The columns displayed in web page are Job_title, Company_name and Applied_date
    This page is displyed well, bu without column nmes at the top. I am trying to get column names from cursor in order to have ORDER BY <pi_sort_col>
    can someone help how i can get those column names:Job_title, Company_name and Applied_date
    User will be able to click on column and sort
    Thank in advance .I appreciate any help

    Hi Francisco
    Here is my code
    CREATE OR REPLACE PACKAGE BODY cc_web_application_list
    IS
    TYPE COL_NAME_LIST IS TABLE OF VARCHAR2(100)
         INDEX BY BINARY_INTEGER;
    TYPE COL_ORDER_LIST IS TABLE OF VARCHAR2(30)
         INDEX BY BINARY_INTEGER;
    col_name_t col_name_list;
    col_order_t col_order_list;
    procedure my_application_list
         (pi_resume_num     in varchar2 default null
         ,pi_sort_col     in varchar2 default null
         ,pi_page_no     in varchar2 default null
         ,pi_action     in varchar2 default null
         ,pi_msg          in varchar2 default null
    is
    l_my_page_no      PLS_INTEGER :=     TO_NUMBER(nvl(pi_page_no,1));
    l_js_name          gam_user.username%TYPE;
    l_js_first_name          gam_user.first_name%TYPE;
    l_cnt                PLS_INTEGER := 0;
    l_scr_lines      PLS_INTEGER := 0;
    l_curline           PLS_INTEGER;
    l_jobs_applied           PLS_INTEGER;
    l_total_rec      PLS_INTEGER;
    l_total_pages      PLS_INTEGER;
    l_pos               PLS_INTEGER;
    l_first               PLS_INTEGER :=0;
    last                PLS_INTEGER :=0;
    l_lines           PLS_INTEGER := 10;
    col_name      VARCHAR2(100) := col_name_t(3) ;
    col_order           VARCHAR2(30) := 'DESC';
    str                VARCHAR2(2000);
    TYPE display_rec IS TABLE OF VARCHAR2(500) INDEX BY BINARY_INTEGER;
    display           display_rec;
    TYPE page_table_type IS TABLE OF PLS_INTEGER INDEX BY BINARY_INTEGER;
    page_number          page_table_type;
    CURSOR cur_job IS
         SELECT      jtl.JOB_TITLE job_title
              ,jtl.COMPANY_NAME company_name
              ,a.APPLY_DATE apply_date
              ,a.lang
              ,a.job_id
         FROM job_tl jtl, applied_for_job a, gateway gt
         WHERE a.job_seeker_id=app.job_Seeker
         AND a.job_id=jtl.job_id
         AND a.lang=jtl.lang
         AND a.gateway=gt.gateway
         ORDER BY a.apply_date;
    This decode is a problem
              decode(col_order,'ASC'
                   ,decode(col_name
                   ,col_name_t(1), jtl.job_title
                   ,col_name_t(2), jtl.company_name
                   ,col_name_t(3), TO_CHAR(a.apply_date, 'YYYYMMDDhh24miss')
                   ,a.apply_date)
                   ) ASC
              ,decode(col_order,'DESC'
                   ,decode(col_name
                   ,col_name_t(1), jtl.job_title
                   ,col_name_t(2), jtl.company_name
                   ,col_name_t(3), TO_CHAR(a.apply_date, 'YYYYMMDDhh24miss')
                   ,a.apply_date)
                   ) DESC
              ,a.apply_date
    TYPE rec_one IS TABLE OF cur_job%ROWTYPE INDEX BY BINARY_INTEGER;
    r               rec_one;
    BEGIN
    BEGIN
    SELECT username,first_name
    INTO l_js_name,l_js_first_name
    FROM gam_user
    WHERE user_id = App.job_seeker;
    EXCEPTION
    WHEN OTHERS THEN NULL;
    END;
    Cc_Pkg_Elements.p_page_top_job_seeker(
    'Personal Job List'
    ,REPLACE(Txt_Proc_My_Joblist.title_job_list
         ,'##first_name##',l_js_first_name),'N' ,TRUE ,'Pxx');
    ----- get numer of records returned by query
    SELECT COUNT(1)
    INTO l_total_rec
    FROM     job_tl jtl,applied_for_job a
         ,gateway gt
    WHERE a.job_id = jtl.job_id
    AND     a.job_seeker_id     = App.job_seeker
    AND     a.gateway     = gt.gateway ;
    ------get number of pages
    l_total_pages:=CEIL (l_total_rec/l_lines);
    l_jobs_applied := 0;
    col_name := pi_sort_col;
    col_order := pi_sort_col;
    --get first positions
    l_first := (nvl(l_my_page_no,1) - 1) * l_lines + 1;
    FOR rec IN cur_job LOOP
         l_cnt := l_cnt + 1;
         EXIT WHEN l_cnt > l_first + l_lines - 1;
         IF l_cnt >= l_first THEN
              l_scr_lines := l_scr_lines + 1;      
              r(l_scr_lines) := rec;          --assign counter from loop to r index
              IF rec.apply_date IS NOT NULL THEN
              l_jobs_applied := l_jobs_applied + 1;
              END IF;
         END IF;
    END LOOP;
    htp.p('<FORM ACTION="'||App.gateway||'8.my_application_list" METHOD="post">');
    htp.p('<table align="center">');
    htp.p('<tr><td>');
    IF r.COUNT = 0 THEN
         Web_Pkg_Elements.doc_msg(Txt_Proc_My_Joblist.no_jobs);
    END IF;
    htp.p('</td></tr>');
    htp.p('</table>');
    --table_heading(col_name ,col_order );
    htp.p('<table align=center>');
    htp.p('<tr align="center"><td>');
    FOR i IN 1..l_total_pages LOOP
         page_number(i) := i;
         IF page_number(i) = l_total_pages THEN
              htp.p('');
    ||'');
              Web_Pkg_Elements.doc_val_small(page_number(i)||'</A>');          
         ELSE
         htp.p('');
    |'||'');
         Web_Pkg_Elements.doc_val_small(page_number(i)||' |'||'</A>');     
         END IF;
    END LOOP;
    htp.p('</td></tr>');
    htp.p('</table>');
    htp.p('<table align=center>');
    FOR l_curline IN 1..l_scr_lines LOOP
         display(1) := NVL(r(l_curline).job_title, '<br>');
         display(2) := NVL(r(l_curline).company_name, '<br>');
         display(3) := NVL(Cc_Pkg_Nls.date2char(r(l_curline).apply_date, App.date_format), '<br>');
         IF MOD(l_curline, 2) = 0 THEN     
              Cc_Pkg_Elements.tr_even;
         ELSE
              Cc_Pkg_Elements.tr_odd;
         END IF;
         htp.p('<td>');
         htp.p('');
         Web_Pkg_Elements.doc_val(display(1)||'');
         htp.p('</td>');
         htp.p('<td>');
         Web_Pkg_Elements.doc_val(display(2));
         htp.p('</td>');
         htp.p('     <td>');
         Web_Pkg_Elements.doc_val(display(3));
         htp.p('     </td>');
    htp.p('</tr>');
    END LOOP;
    htp.p('</TABLE>');
    htp.p('<TABLE width="88%" BORDER="0" CELLPADDING="0" CELLSPACING="0"
                   align="center">');
    htp.p('<tr valign=bottom>');
    htp.p('<TD colspan=2 align=right>');
    IF l_my_page_no > 1 THEN
         htp.p('<P>'||'<IMG SRC="'||App.image||'prev.gif" ALT="'
         ||Txt_Proc_My_Joblist.prev
         ||'"'     ||' HEIGHT=20 BORDER=0 ALIGN=bottom '
         ||'hspace=2>');
    END IF;
    IF l_my_page_no < CEIL (l_total_rec/l_lines) THEN
         htp.p(' <a href="'||
         web_pkg_elements.link$$(App.gateway||'8.my_application_list?'
         ||'pi_sort_col='||Web_Pkg_Elements.replace_in_url(pi_sort_col)
         ||'&pi_msg=&pi_page_no='||TO_CHAR(l_my_page_no + 1)
         ||">'||'<IMG SRC="'||App.image||'next.gif" ALT="'
         ||Txt_Proc_My_Joblist.NEXT
         ||'"' ||' HEIGHT=20 BORDER=0 ALIGN=bottom '
         ||'hspace=2></a>');
    END IF;
    htp.p('</TD>');
    htp.p('</TR>');
    htp.p('     </TABLE>');
    htp.formHidden('pi_sort_col', pi_sort_col);
    htp.formHidden('pi_page_no', pi_page_no);
    htp.p('</FORM>');
    END my_application_list;
    END ; --cc_pkg_application_list

  • Using PL/SQL to retrieve column names and column values

    If I have a table as follows
    Table A(
    meal varchar2(32),
    beverage varchar2(32),
    desert varchar2(32));
    and the table contains a row
    meal beverage desert
    pork chops iced tea apple crisp
    Is there a way in pl/sql to retrieve the column names along with the values. I have an object type
    DATA_DEFINITION_T AS OBJECT (
              "FIELD_NAME"          VARCHAR2(32),
              "FIELD_VALUE" VARCHAR2(32)
    I need to store the column name in field_name and the column value in field_value.
    So the result would be:
    FIELD_NAME = meal
    FIELD_VALUE = pork_chops
    FIELD_NAME = beverage
    FIELD_VALUE = iced tea
    FIELD_NAME = desert
    FIELD_VALUE = apple crisp
    Thanks in advance.

    Hi,
    try this procedure ....just create it and give the table name..the object M_DATA_TAB has the required data
    procedure l_fill_data_dict(p_table_name varchar2) is
    connection_id EXEC_SQL.CONNTYPE;
    bIsConnected BOOLEAN;
    cursorID EXEC_SQL.CURSTYPE;
    nIgn PLS_INTEGER;
    m_val VARCHAR2(40);
    m_col_name varchar2(40);
    m_col_val varchar2(240);
    m_cnt number;
    m_id number := 0;
    m_incr number := 0;
    p_sqlstr varchar2(4000);
    p_sql_cnt varchar2(4000) ;
    p_org_sql varchar2(4000);
    TYPE DATA_DEFINITION_TABS IS RECORD (
    FIELD_NAME VARCHAR2(32),
    FIELD_VALUE VARCHAR2(240));
    TYPE DATA_DEFINITION_TAB IS TABLE OF DATA_DEFINITION_TABS;
    M_DATA_TAB DATA_DEFINITION_TAB := DATA_DEFINITION_TAB();
    --m_file text_io.file_type;
    Begin
    --     m_file := text_io.fopen('c:\eg.txt','w');
         --Set default connection
    connection_id := EXEC_SQL.DEFAULT_CONNECTION;
    bIsConnected := EXEC_SQL.IS_CONNECTED;
    IF bIsConnected = FALSE THEN
         message('Connection Failed');
    RETURN;
    END IF;
    --Find the total no.of columns in the given table
    p_sql_cnt := 'Select COUNT(column_name) from user_tab_columns where table_name='''||p_table_name||''' order by column_id';
    cursorID := EXEC_SQL.OPEN_CURSOR;
    EXEC_SQL.PARSE(cursorID, p_sql_cnt, exec_sql.V7);
    EXEC_SQL.DEFINE_COLUMN(cursorID, 1, m_val,40);
    nIgn := EXEC_SQL.EXECUTE(cursorID);
    IF (EXEC_SQL.FETCH_ROWS(cursorID) > 0) THEN
         EXEC_SQL.COLUMN_VALUE(cursorID, 1, m_val);
    end if;
    EXEC_SQL.CLOSE_CURSOR(cursorID);
    --EXEC_SQL.CLOSE_CONNECTION;
    m_cnt := m_val;---column count
    ---get the column names from the user_Tab_columns and fetch the values from the given table for that column...
    For i in 1..m_cnt loop
         m_id := m_id+1;
    p_sqlstr := 'Select column_name from user_tab_columns where table_name='''||p_table_name||''' and column_id ='||m_id||' order by column_id';
    cursorID := EXEC_SQL.OPEN_CURSOR;
    EXEC_SQL.PARSE(cursorID, p_sqlstr, exec_sql.V7);
    EXEC_SQL.DEFINE_COLUMN(cursorID, 1, m_col_name,40);
    nIgn := EXEC_SQL.EXECUTE(cursorID);
    IF (EXEC_SQL.FETCH_ROWS(cursorID) > 0) THEN
         EXEC_SQL.COLUMN_VALUE(cursorID, 1, m_col_name);
    end if;
    EXEC_SQL.CLOSE_CURSOR(cursorID);
    --fetch the column value from the given table
         p_org_sql := 'select DISTINCT '||m_col_name||' from '||p_table_name;
         cursorID := EXEC_SQL.OPEN_CURSOR;
    EXEC_SQL.PARSE(cursorID, p_org_sql, exec_sql.V7);
    EXEC_SQL.DEFINE_COLUMN(cursorID, 1, m_col_val,240);
         nIgn := EXEC_SQL.EXECUTE(cursorID);
         Loop      
         nIgn := EXEC_SQL.FETCH_ROWS(cursorID);
              IF (nIgn > 0) THEN
                   EXEC_SQL.COLUMN_VALUE(connection_id, cursorID, 1, m_col_val);
    M_DATA_TAB.extend();
                   M_DATA_TAB(M_DATA_TAB.last).field_name := m_col_name;
                   M_DATA_TAB(M_DATA_TAB.last).FIELD_VALUE := m_col_val;
                   m_incr := m_incr+1;
                   -- text_io.put_line(m_file,m_col_name||'##'||m_col_val);
              else
                   exit;
              End if;
         End loop;--loop of records in the table for the given column
    EXEC_SQL.CLOSE_CURSOR(cursorID);
    End loop; ---loop of columns in the table
    --text_io.fclose(m_file);
    message('Total no. of items in the object='||m_incr);
    EXEC_SQL.CLOSE_CONNECTION;
    EXCEPTION
    When EXEC_SQL.Invalid_Connection then
         message('invalid connection');
         when EXEC_SQL.Package_Error     then
         message('pkg err');
         when EXEC_SQL.Invalid_Column_Number          then
         message('invalid col num defined');
         when others then
              MESSAGE(SQLERRM);
    End;
    Regards
    Dora
    Edited by: Dora on Sep 27, 2009 3:13 PM

  • How to get only column names from different tables as single table columns

    Hi All,
       I have one requirement in which we want only column names from different tables.
    for example :
     I have three tables T1 ,T2, T3 having
      col1 clo2 clo3 -->  T1 , 
      col3 col5 ,clo6 --> T2 ,
      Clo6 col8 col9 --> T3
    columns i want to get only all  Column names from all table as single Resultset not any data from that how can i get that empty resultset 
    because this empty result i want to bind in datagridview(front end) as Empty resultset 
    Please tell me anyways to do this
    Niraj Sevalkar

    If I understand you want an empty result set, just with metadata. SET FMTONLY do the trick:
    SET FMTONLY ON
    SELECT Col1, Col2, Col3, ....., Coln
    FROM
    T1 CROSS JOIN T2 CROSS JOIN T3
    SET FMTONLY OFF
    Another alternative is to include an imposible contition
    SELECT Col1, Col2, Col3, ....., Coln
    FROM
    T1 CROSS JOIN T2 CROSS JOIN T3
    WHERE 1 = 0
    If you are using a SqlDataAdapter in your client application. You can use the FillSchema method. the select command may be any select statement that returns the columns you want. Under the covers FillSchema will call SET FMTONLY ON.
    If you are using SqlCommand.ExecuteReader you can pass SchemaOnly to CommandBehavior argument. SET FMTONLY ON is called under the covers. Again the select command may be any select statement that returns the columns you want.
    "No darás tropezón ni desatino que no te haga adelantar camino" Bernardo Balbuena

  • Column name in a query contains special characters

    Hi folks,
    The column name in a query contains special characters. For example ~ or ^. The creator of the table put these column names under double quotation while creating the table. When I get the column names form the result set meta data object it returns without quotation. Is there any way to tell the jdbc driver so that it return those column names as it was created, I mean in double quotation.
    The help is urgent. I will appreciate any suggestions. Thanks �.
    [using oracle driver for 10g]
    Thanks
    Angelina

    Just because the column names were in quotations when the database was created doesn't mean that the quotes are actually part of the names. What's inside the quotes is what makes the column name in the database. If I created a column as "abcd" and put it in quotes just like that ("abcd"), it would go in the database as abcd since SQL would strip off the quotes.
    And there's your answer. Just put all column names in quotes whenever you need to talk to SQL. It will strip off the quotes and understand.
    I think SQL will also accept square brackets ([ and ]).

  • How to retrieve user name from a given Subject?

    I am in a situation where I need to retrieve user name from the Subject that is populated when user logs in. I have the active Subject and I do following to get the principals in the subject and iterate through them:
    Set principals = subject.getPrincipals();
    Iterator ite = principals.iterator();
    while (ite.hasNext()) {
    Principal prin = (Principal)ite.next();
    String name = prin.getName();
    But this contains all the principals, including user name, roles, password, etc. How do I programmatically determine which one is user name?

    Don't you have different principal types? I am making a jaas module and I have different principals for roles, groups etc. I think of principals as attributes, the type in the attribute name and the principal name is the attribute value.
    To get all the principals of the type SomePrincipal, you can use:
    Set principals = subject.getPrincipals(SomePrincipal.class)
    You can also take som principal an test wether it is an instance of som type:
    if (Principal p instanceof SomePrincipal){..}
    An other solution which might be better if you have many different attributes is to store both attribute name and value in the name of the principal.
    If "mark" is a username the principal name will be "username:mark" el.
    Then it will be easy to find the username.

  • Find column name from constraint name

    How to fetch the column name from a constraint name to which the constraint is applied?.
    I only know the name of the constraint and can get the table name from "dba_constraints". How can I know to which column in the table this constraint is applied.
    Thanks

    What about this?
    satyaki>
    satyaki>
    satyaki>desc user_cons_columns;
    Name                                      Null?    Type
    OWNER                                     NOT NULL VARCHAR2(30)
    CONSTRAINT_NAME                           NOT NULL VARCHAR2(30)
    TABLE_NAME                                NOT NULL VARCHAR2(30)
    COLUMN_NAME                                        VARCHAR2(4000)
    POSITION                                           NUMBER
    satyaki>
    satyaki>Regards.
    Satyaki De.

Maybe you are looking for

  • Error while assigning a character value to a numeric variable.

    I fire a sql statement and check the number of rows returned by the sql. I check this result with the application logs. The application logs keeps the sqls fired by the application and the no of rows returned, in the example below the sql returned 84

  • [Satellite Pro A200] - slowness during data transfer and heat problems.

    Hi folks. I have a 1.5 y.o Toshiba Satellite Pro A200 with standard 200GB HDD. Since some time its behaviour is just... weird. Sometimes system slows. It just behaves sluggish, it frequently freezes for a second during simple tasks such as entering t

  • Request help for iphone screen flickering

    I'm using iphone 4. Few days ago (before the software update 6.0.1) i noticed my iphone screen is flickering and blurred.this bug was not fixed after IOS update 6.0.1. Thus showing horizontal lines in the screen.           please help me

  • BAPI_DOCUMENT_CREATE2 error

    Hi!! I'm trying to create a document through BAPI_DOCUMENT_CREAT2, we fill everything and run, not an error but the document is not created, follows the fields that I filled DocumentType - DBE DocumentNumber - 22224 DOCUMENTVERSION - 00 DOCUMENTPART

  • Configure diameters interface

    Hi I have a problem... When I configure a new channel of type "diameter/diameters" I receive this error: The WebLogic Server did not start up properly. java.lang.NumberFormatException: 0.0.0.0      at java.lang.Integer.parseInt(Ljava/lang/String;I)I(