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

Similar Messages

  • Getting column names from SYS_REFCURSOR

    Hi everybody, i have a SYS_REFCURSOR in a procedure. And i open it and fetch cursor to a record as follows:
    OPEN curgroup FOR vexpr2;
    LOOP
    FETCH curgroup INTO recType;
    END LOOP;
    recType is a Record, has two variables. Anyway, the question is can i get the column names from refcursor?
    like recType.COLUMN1 (Column1 is not a record variable ) ????
    or is there anything else to perform this operation?

    Hi,
    Despite what Billy states it is very possible to get the column names from a weak ref cursor, or describe a ref cursor with PL/SQL. It has been possible since 8i, it just relies on the little known fact that a ref cursor in PL/SQL translates directly to a ResultSet in Java so we can use a tiny JSP in the DB.
    Here is the link to the completely free, Open Source code which allows you to do this: [XUTL_REFCURSOR|http://www.chrispoole.co.uk/apps/xutlrefcursor.htm]
    And a little example:
    SQL> variable scott_cursor refcursor
    SYS@ORA10GR2
    SQL> begin
      2  open :scott_cursor for select * from scott.emp;
      3  end;
      4  /
    PL/SQL procedure successfully completed.
    SYS@ORA10GR2
    SQL> begin
      2  xutl_refcursor.describe_columns(:scott_cursor);
      3  end;
      4  /
    PL/SQL procedure successfully completed.
    SYS@ORA10GR2
    SQL> select col_name from xutl_described_columns;
    COL_NAME
    EMPNO
    ENAME
    JOB
    MGR
    HIREDATE
    SAL
    COMM
    DEPTNO
    SYS@ORA10GR2
    SQL> print :scott_cursor
         EMPNO ENAME      JOB              MGR HIREDATE                   SAL       COMM     DEPTNO
          7369 SMITH      CLERK           7902 17/12/1980 00:00:00        800                    20
          7499 ALLEN      SALESMAN        7698 20/02/1981 00:00:00       1600        300         30
          7521 WARD       SALESMAN        7698 22/02/1981 00:00:00       1250        500         30
          7566 JONES      MANAGER         7839 02/04/1981 00:00:00       2975                    20
          7654 MARTIN     SALESMAN        7698 28/09/1981 00:00:00       1250       1400         30
          7698 BLAKE      MANAGER         7839 01/05/1981 00:00:00       2850                    30
          7782 CLARK      MANAGER         7839 09/06/1981 00:00:00       2450                    10
          7788 SCOTT      ANALYST         7566 19/04/1987 00:00:00       3000                    20
          7839 KING       PRESIDENT            17/11/1981 00:00:00       5000                    10
          7844 TURNER     SALESMAN        7698 08/09/1981 00:00:00       1500          0         30
          7876 ADAMS      CLERK           7788 23/05/1987 00:00:00       1100                    20
          7900 JAMES      CLERK           7698 03/12/1981 00:00:00        950                    30
          7902 FORD       ANALYST         7566 03/12/1981 00:00:00       3000                    20
          7934 MILLER     CLERK           7782 23/01/1982 00:00:00       1300                    10
    14 rows selected.
    SYS@ORA10GR2
    SQL>As the demo shows describing the ref cursor does not affect the cursor in any way, it is not selected from. It is not converted into a DBMS_SQL cursor and can be passed to a front end.
    [XUTL_REFCURSOR|http://www.chrispoole.co.uk/apps/xutlrefcursor.htm] is designed to have exactly the same output and uses the same return type as DBMS_SQL DESCRIBE COLUMNS, to enable pre-existing code that uses that API to be quickly re-used.
    HTH
    Chris

  • Getting Column names from SQL report

    I have a SQL report as follows:
    select ename, dept, manager
    from emp;
    I need to be able to dynamically access the column names being displayed inside APEX so I can use in a List of Values. I can't use all_tab_columns. Is there an internal APEX table/view that I can accxess that will give me all of the columns that are eing displayed in a SQL report?

    Hi Bob,
    Try this -
    1) Give your report region a static id
    2) Use the following query -
    select
      heading d,
      column_alias r
    from
      apex_application_page_rpt_cols
    where region_id = 'FOO';Obviously change 'FOO' to match your region id, and look at the different columns available in the apex_application_page_rpt_cols view to see what best suits you.
    The APEX dictionary rocks ;)
    Hope this helps,
    John.
    http://jes.blogs.shellprompt.net
    http://apex-evangelists.com

  • Getting column names for a particular Table from Connection object.

    Hi,
    Can any one suggests me a way to get column names from a particular table of a database from the java.sql.Connection object. ?
    Thanks in advance.

    Connection connection;
    DatabaseMetaData metadata = connection.getMetaData();
      String[] names = {"TABLE"};
      ResultSet tables = metadata.getTables(null,"%", "%", names);
      while (tables.next()) {
      String tableName = tables.getString("TABLE_NAME");
       ResultSet columns = metadata.getColumns(null, "%", tableName, "%");
    while (columns.next()) {
      String columnName = columns.getString("COLUMN_NAME");
        }

  • Getting column names using EJB3.0

    Hi,
    Could someone help me how to get column names in EJB3.0.
    I am having reference to folloiwng ejb.
    @Entity
    @Table(name = "users")
    @org.hibernate.annotations.Entity(dynamicInsert = true, dynamicUpdate = true)
    @SequenceGenerator(name = "users", sequenceName = "users")
    public class User {
    private Long userId;
    private String username;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO, generator = "users_seq")
    @Column(name = "user_id")
    public Long getUserId() {
    return userId;
    public void setUserId(Long userId) {
    this.userId = userId;
    @NotNull
    @Column(name = "username")
    public String getUsername() {
    return username;
    public void setUsername(String username) {
    this.username = username;
    Thanks in advance

    You shouldn't be getting column names from EJBs.
    You need to know the object, the schema, and how to map one to the other.
    So you should look at the SQL table "users" and map this object to it.
    %

  • 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

  • C# : Get Column name for an Insert Query from The Selected GridView Row.

    Hi Guys, I am trying to insert data in an SQL table by executing an Insert Query. 
    The problem is that I need to get the column name from a cell in the selected gridview Row.
    Here's the snippet:
    SqlCommand cmd30 = new SqlCommand("insert into mytable ( '"+GridView7.SelectedRow.Cells[0].Text+"' , r_id) values ('"+ GridView7.SelectedRow.Cells[1].Text +"', '"+TextBox1.Text+"')",con30);
            cmd30.ExecuteNonQuery();
    **r_id is not a Primary Key.
    The Error is get is:
    Incorrect syntax near 'r_id'.
    Any Help will be appreciated.
    Thanks,
    Shaleen
    TheHexLord

    Hi TheShaleen,
    Like your title mentioned.GridView control is a web class.This forum is to discuss problems of C# development.  Your question is not related to the topic of this forum.
    You'll need to post it in the dedicated ASP.Net Forum  for more efficient responses, where you can contact ASP.NET experts. Thanks for understanding.
    Best regards,
    Kristin
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Why do I get a class conflict between the Prepare SQL.vi and the Get Column Name.vi with the SQL Toolkit compatibility vis from the Database Connectivity Toolkit?

    I have done extensive programming with the SQL Toolkit with LabVIEW versions through 6.1. My customer now wants to upgrade to Windows 7, so I am trying to upgrade to LabVIEW 2009 (my latest purchased version) using the Database Connectivity Toolkit, and the SQL Toolkit Compatibility vis. Everything seemed to be going okay with the higher level SQL operations, but I ran into trouble with the Get Column Name.vi. 
    The pictures below show the problem. The original SQL Toolkit connected the Prepare SQL.vi with the Get Column Name.vi with a cluster of two references, one for connection, and one for sql. The new compatibility vis have a class conflict in the wire because the Prepare SQL.vi contains a cluster with connection, and command references, but the Get Column Name.vi expects a cluster with connection and recordset references. 
    How do I resolve this conflict?
    Thank You.
    Dan

    I've never worked with the old version of the toolkit, so I don't know how it did things, but looking inside the SQL prep VI, it only generates a command, and the the column name VI wants a recordset. I'm not super familiar with all the internals of ADO, but my understanding is that is standard - you only have the columns after you execute the command and get the recordset back. What you can apparently do here is insert the Execute Prepared SQL VI in the middle and that will return what you need.
    I'm not sure why it worked before. Maybe the execute was hidden inside the prep VI or maybe you can get the column names out of the command object before execution. In general, I would recommend considering switching to the newer VIs.
    Try to take over the world!

  • Getting column names empty from MS Access database

    Hi,
    I have MS Access intalled in my desktop.I am using aveConnect jdbc driver to connect to MS Access database.
    I am trying to retrieve all the table name and column names of respective tables .
    But when i get column name as empty string when i try to retrieve the column name of a table.
    here is the sample code i use.
    I am getting the column count of a particular table and type of the column.
    It would be nice if some could help me .
    ResultSet ColumnData = meta.getColumns(null, null, "TBLACCOUNT", null);
                   System.out.println( "ColumnData:" +ColumnData);
                   if (ColumnData!= null) {
                        System.out.println("ColumnData not null");
                        ResultSetMetaData rsmd = ColumnData.getMetaData();
                        int columnCount = rsmd.getColumnCount();
                        String columnName = rsmd.getColumnName(1);
                        String columnType = rsmd.getColumnTypeName(1);
                        System.out.println("columnCount is " +columnCount);
                        System.out.println("The name of the first column is: " +columnName);
                        System.out.println("The data type of the first column is: " +columnType);
    thanks
    sheeba

    You're here in a JDBC forum, not a SQL forum. I suggest you to start learning SQL and come back once you have JDBC issues.
    Here is a list of links to all SQL tutorials available on the Internet.
    http://www.google.com/search?q=sql+tutorial

  • 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

  • How to get column names for a specific view in the scheme?

    how to get column names for a specific view in the scheme?
    TIA
    Don't have DD on the wall anymore....

    or this?
    SQL> select text from ALL_VIEWS
      2  where VIEW_NAME
      3  ='EMP_VIEW';
    TEXT
    SELECT empno,ename FROM EMP
    WHERE empno=10

  • 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.

  • 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

  • How to Select data using same column name from 3 remote database

    Hi,
    Can anyone help me on how to get data with same column names from 3 remote database and a single alias.
    Ex.
    SELECT *
    a.name, b.status, SUM(b.qty) qantity, MAX(b.date) date_as_of
    FROM
    *((table1@remotedatabase1, table1@remotedatabase2, table1@remotedatabase3)a,*
    *(table1@remotedatabase1, table1@remotedatabase2, table1@remotedatabase3)b)*
    WHERE b.dept = 'finance'
    AND a.position = 'admin'
    AND a.latest = 'Y' AND (b.status <> 'TRM') AND b.qty > 0;
    GROUP BY a.name, b.status ;
    NOTE: the bold statements is just an example of what I want to do but I always gets an error beacause of ambiguous columns.
    Thanks in advnce. :)
    Edited by: user12994685 on Jan 4, 2011 9:42 PM

    user12994685 wrote:
    Can anyone help me on how to get data with same column names from 3 remote database and a single alias.Invalid. This does not make sense and breaks all scope resolution rules. And whether this is in a single database, or uses tables across databases, is irrelevant.
    Each object must be uniquely identified. So you cannot do this:
    select * from (table1@remotedatabase1, table1@remotedatabase2, table1@remotedatabase3) a3 objects cannot share the same alias. Example:
    SQL> select * from (dual, dual) d;
    select * from (dual, dual) d
    ERROR at line 1:
    ORA-00907: missing right parenthesisYou need to combine the objects - using a join or union or similar. So it will need to be done as follows:
    SQL> select * from (select * from dual d1, dual d2) d;
    select * from (select * from dual d1, dual d2) d
    ERROR at line 1:
    ORA-00918: column ambiguously definedHowever, we need to have unique column names in a SQL projection - so the join of the tables need to project a unique set of columns. Thus:
    SQL> select * from (select d1.dummy as dummy1, d2.dummy as dummy2 from dual d1, dual d2) d;
    DUM DUM
    X   X
    SQL> I suggest that you look closely at what scope is and how it applies in the SQL language - and ignore whether the objects referenced are local or remote as it has no impact to fundamentals of scope resolution.

  • Simplest way to get column names

    i need to retrieve column names in a rowset, let me explain a bit;
    i can simply retrieve a column name by using IColumnsInfo::GetColumsInfo, but the problem is when i use "AS" keyword in the select statement such like;
    SELECT identification AS  id FROM test_table_a
    i see alias name of that column instead the internal column name.
    as you can guess the qestion is; how can i get both alias and internal name at the same time and of course what is the *usual* way to get it.
    thanks in advance

    Getting 'real' column names from a table:
    Code Snippet
    SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = N'Products'

Maybe you are looking for