Display column name in sql*plus
Hi,
How to display full column name?
there are n no of tables, i have to query the tables but i want the column name to be displayed fully. for example
SQL> desc control
Name Null? Type
CODE NOT NULL VARCHAR2(255)
LOAD_PERIOD_START_DATETIME DATE
SQL> select code,load_period_start_datetime from control;
CODE
LOAD_PERIOD
AAA
01-AUG-2007
SQL> col load_period_start_datetime format a30
SQL> /
CODE
LOAD_PERIOD_START_DATETIME
AAA
01-AUG-2007
SQL>
As it is only one column i can set with 'col <column_name> format a 30'
if there are n no of coumns from n no tables then how do i get the full column name?
Please help me.
Thanks
Hi,
you can get all the column's for a TABLE from all_tab_columns this VIEW, why dont you write as script which will generate the commands.
Could you please tell us why do you want to display the compete COLUMN NAME in SQL plus.
Thanks
Similar Messages
-
Displaying Chinese characters in SQL*Plus
DB version: 11.2
OS Version : AIX 6.1
DB characterset:AL32UTF8
To display chinese characters in SQL*Plus, I did the following:
$ export LANG=zh_CN.UTF-8
$ export LC_ALL=zh_CN.GB2312
$ export NLS_LANG="SIMPLIFIED CHINESE_CHINA.ZHS16GBK"
$
$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.2.0 Production on ÐÇÆÚÈý 5ÔÂ 2 15:52:33 2012
Copyright (c) 1982, 2010, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
With the Partitioning option
SQL> ALTER SESSION SET NLS_LANGUAGE='SIMPLIFIED CHINESE';
Session altered.
SQL> ALTER SESSION SET NLS_TERRITORY='CHINA';
Session altered.
SQL> select unistr('\8349') from dual; ---- not 100% sure if this is the way to verify if chinese characters can be displayed.
UN
²Ý ----------------------------------------> Getting a junk character instead of chinese If I was using putty, are the above steps enough to get chinese characters displayed ?
Our ssh client is Tectia (not putty).
According the below ML Note, the SSH client has to configured correctly to use globalization features.
+The correct NLS_LANG setting in Unix Environments [ID 264157.1]+
Googling "Tectia + Chinese" didn't return useful resultsI understand that you are talking about Windows SSH Client.
For Putty, you should set:
$ export LANG=zh_CN.UTF-8
$ export LC_ALL=zh_CN.UTF-8
$ export NLS_LANG="SIMPLIFIED CHINESE_CHINA.AL32UTF8"
and configure Putty in Window->Translation to use UTF-8.
There is nothing about this subject on Tectia website and in their manuals, so my best guess is that the client requires Windows code page to work correctly. In such case you need to set your Windows system default locale (locale for non-Unicode programs) to Chinese and use the following settings on the server:
$ export LANG=zh_CN.GBK
$ export LC_ALL=zh_CN.GBK
$ export NLS_LANG="SIMPLIFIED CHINESE_CHINA.ZHS16GBK"
Verify with 'locale -a' that the setting zh_CN.GBK is supported on your system.
-- Sergiusz -
Question about setting column width in SQL*Plus using info retrieved w SQL
Good morning,
Is there a way to tell SQL*Plus to set the width of a column to the greatest width of the elements found in the column ? (as opposed to the default which is the width declared in the DDL)
In other words, I'd like to do something functionally equivalent to this:
COL <columname> format a[select max(length(<columnname>)) from <thetablethatcontainscolumname>]
I'm doing the above manually in two steps
1. select max(length(columnname)) from .....
2. col columnname format a[resultofstep1]
Is there a way of doing it in one step ?
Thank you for your help,
John.Hi Munky,
>
you should consider whther you are using the correct tool for the job, SQLplus isn't exactly ideal for doing presentation layer stuff
>
I'm not really doing presentation stuff, I asked because it would be very convenient for everyday stuff. I commonly query the tables that I am going to deal withm just to have a look at the column names and a few values, something like:
select * from EMP where rownum <= 10; -- just to have a look at the table and some values
when the table contains a wide column then the display gets all messed up. It would be nice to have an option or a mechanism to tell SQL*Plus to automatically use the width of the widest value, instead of having to determine the value and then manually set the column.
thank you for your help, it's good to know that I didn't miss some trivial setting in the documentation that would do it ;)
John. -
Need to display column names in a dynamic page
Hi
I am displaying some rows returned from an sql querry in a dynamic page ...I hv written the sql querry between <ORACLE> AND </ORACLE> TAGS...The problem is ,i am not able to display the column names ...Why ? pl help....
ramYou must to use the htp package. Example:
<ORACLE>
begin
htp.tableopen('1','CENTER',null,null,'BORDER="1"');
htp.tableheader('NParte','CENTER');
htp.tableheader('Descripcisn','CENTER');
htp.tableheader('Precio/Unit','CENTER');
htp.tableheader('Servicio','CENTER');
htp.tableheader('IVA','CENTER');
htp.tableheader('Total','CENTER');
for cursor_cotiza in (select
r.Nparte as Nparte, r.Descripcion as Descripcion,
r.preciounit as preciounit,
NVL(f.servicio,0) as servicio,
round((0.145)*r.preciounit,3) as IVA,
round((0.145)*r.preciounit,3) + r.preciounit +
NVL(f.servicio,0) as PrecioTotal
from
carryin.repuestos r,
carryin.casos c, carryin.facturacion f
where r.NCaso =:NCaso
and r.Ncaso=c.NCaso
and c.Ncaso=f.Ncaso(+)
and f.servicio(+)<>0
union
select
r.Nparte as Nparte, r.Descripcion as Descripcion,
r.preciounit as preciounit,
NVL(f.servicio,0) as servicio,
round((0.145)*r.preciounit,3) as IVA,
round((0.145)*r.preciounit,3) + r.preciounit +
NVL(f.servicio,0) as PrecioTotal
from
carryin.casosneq r,
carryin.facturacion f
where r.NCaso =:NCaso
and r.Ncaso=f.Ncaso(+)
and f.servicio(+)<>0
) loop
htp.tableRowOpen('CENTER','CENTER');
htp.tableData(cursor_cotiza.Nparte,'CENTER');
htp.tableData(cursor_cotiza.Descripcion,'CENTER');
htp.tableData(cursor_cotiza.preciounit,'CENTER');
htp.tableData(cursor_cotiza.servicio,'CENTER');
htp.tableData(cursor_cotiza.IVA,'CENTER');
htp.tableData(cursor_cotiza.PrecioTotal,'CENTER');
htp.tableRowClose;
end loop;
htp.tableclose;
end;
</ORACLE>
This example show a table with header and borders. You must to see this package for more information. -
Using column number inplace of column name in SQL Select statement
Is there a way to run sql select statements with column numbers in
place of column names?
Current SQL
select AddressId,Name,City from AddressIs this possible
select 1,2,5 from AddressThanks in Advanceuser10962462 wrote:
well, ok, it's not possible with SQL, but how about PL/SQL?As mentioned, using DBMS_SQL you can only really use positional notation... and you can also use those positions to get the other information such as what the column is called, what it's datatype is etc.
CREATE OR REPLACE PROCEDURE run_query(p_sql IN VARCHAR2) IS
v_v_val VARCHAR2(4000);
v_n_val NUMBER;
v_d_val DATE;
v_ret NUMBER;
c NUMBER;
d NUMBER;
col_cnt INTEGER;
f BOOLEAN;
rec_tab DBMS_SQL.DESC_TAB;
col_num NUMBER;
v_rowcount NUMBER := 0;
BEGIN
-- create a cursor
c := DBMS_SQL.OPEN_CURSOR;
-- parse the SQL statement into the cursor
DBMS_SQL.PARSE(c, p_sql, DBMS_SQL.NATIVE);
-- execute the cursor
d := DBMS_SQL.EXECUTE(c);
-- Describe the columns returned by the SQL statement
DBMS_SQL.DESCRIBE_COLUMNS(c, col_cnt, rec_tab);
-- Bind local return variables to the various columns based on their types
FOR j in 1..col_cnt
LOOP
CASE rec_tab(j).col_type
WHEN 1 THEN DBMS_SQL.DEFINE_COLUMN(c,j,v_v_val,2000); -- Varchar2
WHEN 2 THEN DBMS_SQL.DEFINE_COLUMN(c,j,v_n_val); -- Number
WHEN 12 THEN DBMS_SQL.DEFINE_COLUMN(c,j,v_d_val); -- Date
ELSE
DBMS_SQL.DEFINE_COLUMN(c,j,v_v_val,2000); -- Any other type return as varchar2
END CASE;
END LOOP;
-- Display what columns are being returned...
DBMS_OUTPUT.PUT_LINE('-- Columns --');
FOR j in 1..col_cnt
LOOP
DBMS_OUTPUT.PUT_LINE(rec_tab(j).col_name||' - '||case rec_tab(j).col_type when 1 then 'VARCHAR2'
when 2 then 'NUMBER'
when 12 then 'DATE'
else 'Other' end);
END LOOP;
DBMS_OUTPUT.PUT_LINE('-------------');
-- This part outputs the DATA
LOOP
-- Fetch a row of data through the cursor
v_ret := DBMS_SQL.FETCH_ROWS(c);
-- Exit when no more rows
EXIT WHEN v_ret = 0;
v_rowcount := v_rowcount + 1;
DBMS_OUTPUT.PUT_LINE('Row: '||v_rowcount);
DBMS_OUTPUT.PUT_LINE('--------------');
-- Fetch the value of each column from the row
FOR j in 1..col_cnt
LOOP
-- Fetch each column into the correct data type based on the description of the column
CASE rec_tab(j).col_type
WHEN 1 THEN DBMS_SQL.COLUMN_VALUE(c,j,v_v_val);
DBMS_OUTPUT.PUT_LINE(rec_tab(j).col_name||' : '||v_v_val);
WHEN 2 THEN DBMS_SQL.COLUMN_VALUE(c,j,v_n_val);
DBMS_OUTPUT.PUT_LINE(rec_tab(j).col_name||' : '||v_n_val);
WHEN 12 THEN DBMS_SQL.COLUMN_VALUE(c,j,v_d_val);
DBMS_OUTPUT.PUT_LINE(rec_tab(j).col_name||' : '||to_char(v_d_val,'DD/MM/YYYY HH24:MI:SS'));
ELSE
DBMS_SQL.COLUMN_VALUE(c,j,v_v_val);
DBMS_OUTPUT.PUT_LINE(rec_tab(j).col_name||' : '||v_v_val);
END CASE;
END LOOP;
DBMS_OUTPUT.PUT_LINE('--------------');
END LOOP;
-- Close the cursor now we have finished with it
DBMS_SQL.CLOSE_CURSOR(c);
END;
SQL> exec run_query('select empno, ename, deptno, sal from emp where deptno = 10');
-- Columns --
EMPNO - NUMBER
ENAME - VARCHAR2
DEPTNO - NUMBER
SAL - NUMBER
Row: 1
EMPNO : 7782
ENAME : CLARK
DEPTNO : 10
SAL : 2450
Row: 2
EMPNO : 7839
ENAME : KING
DEPTNO : 10
SAL : 5000
Row: 3
EMPNO : 7934
ENAME : MILLER
DEPTNO : 10
SAL : 1300
PL/SQL procedure successfully completed.
SQL> exec run_query('select * from emp where deptno = 10');
-- Columns --
EMPNO - NUMBER
ENAME - VARCHAR2
JOB - VARCHAR2
MGR - NUMBER
HIREDATE - DATE
SAL - NUMBER
COMM - NUMBER
DEPTNO - NUMBER
Row: 1
EMPNO : 7782
ENAME : CLARK
JOB : MANAGER
MGR : 7839
HIREDATE : 09/06/1981 00:00:00
SAL : 2450
COMM :
DEPTNO : 10
Row: 2
EMPNO : 7839
ENAME : KING
JOB : PRESIDENT
MGR :
HIREDATE : 17/11/1981 00:00:00
SAL : 5000
COMM :
DEPTNO : 10
Row: 3
EMPNO : 7934
ENAME : MILLER
JOB : CLERK
MGR : 7782
HIREDATE : 23/01/1982 00:00:00
SAL : 1300
COMM :
DEPTNO : 10
PL/SQL procedure successfully completed.
SQL> exec run_query('select * from dept where deptno = 10');
-- Columns --
DEPTNO - NUMBER
DNAME - VARCHAR2
LOC - VARCHAR2
Row: 1
DEPTNO : 10
DNAME : ACCOUNTING
LOC : NEW YORK
PL/SQL procedure successfully completed.
SQL> -
ALV Report - displaying column name in two fields.
Dear All,
I am working on ALV report , report is ready but now i have to format it according to client requirment, in which have to show column name in two row like.
supppose there is field by name
"Date of receipt of processed Goods"
can i display it like
"Date of receipt of
processed Goods "
Assured points for suitable answer.
Looking foward to your response.
Best Regards,
Gulrez AlamHi Ellery,
As Philipp said, there is no need for populating the field using PL/SQL. You would just need to go to the Paper Layout in the Reports Editor, click on "Text" in the Drawing toolbar, drag it to the appropriate place in your layout to create the field, and write what you want in that field. Below that, you can create the field(s) which will display the actual totals. I'm assuming that creating the totals field is not a problem.
Navneet. -
ADF swing: JTabbedPane does not display column names.
Hi all,
I have created an ADF Panel, which allows the user to run a few simple queries against an Oracle database done using ADF view objects and ADF view links and ADF application module.
From the data control area I drag and drop a view link containing a query into a JTabbedPane. But when I run the ADF panel, JTabbedPane does not display the column headers from the SQL as opposed to JScrollPane which does.
Suppose you do a select * from departments(dep_id, manager, state_cd), you will see all column headers meaning dep_id, manager, state_cd, and under each column the corresponding data which was retuned by the SQL if you use JScrollPane. But if you use you use JTabbedPane then you would only see the data which was retuned by the SQL without seeing the column header names meaning dep_id, manager, state_cd.
What do I need to do to make JTabbedPane display columns headers?
I would appreciate your input.
Thanks.
Bobby A.Hi,
JScrollPane should be used. You can add this into a JTabbedPane if you like. Not all Swing panel show table headers
Frank -
DISPLAY UNDEFINE TABLES IN SQL PLUS
i am using Oracle 10g
for last 1 week i seen unrecognized table names in my user while i issue following command
SQL > select * from tab;
table name like ......BIN$ and many other characters after it...
i cannot drop that table also
from DBA studio above table can't view but from SQL PLUS it display as table
what i have to do to drop such tables ? please give adviceThese are recyclebin tables. A normal 'drop table' command puts a table into the recyclebin, you can get it back through 'flashback drop' command. Use 'purge user_recyclebin' to delete the tables finally.
Werner -
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 -
How to get th displaye record count through SQL*Plus without result
set lines 155
set pages 100
set autoprint on
variable cv refcursor
set serveroutput on size 1000000
set timing on
set feedback on
set echo on
exec proc_name (input1, input2, :cv);how to get the record count without resultset display in the sql*plus promt ...?
plz help me....This is my earilier code
set lines 155
set pages 100
set autoprint on
variable cv refcursor
set serveroutput on size 1000000
set timing on
set feedback on
set echo on
exec proc_name (input1, input2, :cv);
Then i have tried to execute like this
declare
disp SYS_REFCURSOR;
cv SYS_REFCURSOR;
cnt number :=0;
begin
proc_name (input1, input2, :cv);
FOR disp in cv --here cv is the set of record set
LOOP
--FETCH cv INTO disp;
EXIT WHEN cv%NOTFOUND;
cnt := cnt + 1;
END LOOP;
dbms_output.put_line(cnt);
dbms_output.put_line(cv%rowcount);
CLOSE cv;
end;
getting error...
LOOP
ERROR at line 8:
ORA-06550: line 8, column 2:
PLS-00103: Encountered the symbol "LOOP" when expecting one of the following:
. ( % ; for
The symbol "; was inserted before "LOOP" to continue.
ORA-06550: line 13, column 2:
PLS-00103: Encountered the symbol "DBMS_OUTPUT"
ORA-06550: line 13, column 27:
PLS-00103: Encountered the symbol ";" when expecting one of the following:
. ( , * % & - + / at mod rem <an identifier>
<a double-quoted delimited-identifier> <an exponent (**)> as
from into || bulk
I have set of executable procedure script for exec procedure1(input1, input2 :cv); , exec procedure1(input1, input2 :cv);,.... like that. But i want only the record count, while we execute all these scripts in the sql promt...How to do that one.. ? -
How to suppress column names in SQL-report
What I want is just the data, without any column names.
COLUMN LDATE OFF;
SELECT SYSDATE LDATE
FROM DUAL;
LDATE
07.11.11
This example doesn't work. There is still LDATE above column. Any idea?user5116754 wrote:
Great, it's so simple. Im sure there is a way to omit this result statement: "531 rows selected" at the end of report!There is, and it's also in the documentation...
SQL> set feedback off
SQL> select * from emp;
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
7369 SMITH CLERK 7902 17-DEC-1980 00:00:00 800 20
7499 ALLEN SALESMAN 7698 20-FEB-1981 00:00:00 1600 300 30
7521 WARD SALESMAN 7698 22-FEB-1981 00:00:00 1250 500 30
7566 JONES MANAGER 7839 02-APR-1981 00:00:00 2975 20
7654 MARTIN SALESMAN 7698 28-SEP-1981 00:00:00 1250 1400 30
7698 BLAKE MANAGER 7839 01-MAY-1981 00:00:00 2850 30
7782 CLARK MANAGER 7839 09-JUN-1981 00:00:00 2450 10
7788 SCOTT ANALYST 7566 19-APR-1987 00:00:00 3000 20
7839 KING PRESIDENT 17-NOV-1981 00:00:00 5000 10
7844 TURNER SALESMAN 7698 08-SEP-1981 00:00:00 1500 0 30
7876 ADAMS CLERK 7788 23-MAY-1987 00:00:00 1100 20
7900 JAMES CLERK 7698 03-DEC-1981 00:00:00 950 30
7902 FORD ANALYST 7566 03-DEC-1981 00:00:00 3000 20
7934 MILLER CLERK 7782 23-JAN-1982 00:00:00 1300 10
SQL> -
How to get the SQL file name in SQL*plus
hi all,
I have created two sql file at C drive as "c:\Createtable.sql" and "c:\Deletetable.sql"
afterwards i open
C:\>sqlplus
SQL*Plus: Release 10.2.0.1.0 - Production on Wed Jan 30 11:37:10 2008
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Enter user-name: scott/tiger
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
SQL> @C:\Createtable.sql'
Table created.
SQL> @'C:\Deletetable.sql'
Table dropped.
SQL>My problem is to get the name of the file as "c:\createtable.sql" and "C:\Deletetable.sql" in sql*plus enviornment.
Thanks & Regards
SinghDear Damorgan,
>>your version number to three decimal places
My Oracle DB Version i have already stated in my previous post is 10.2.0.1.0
Actually my problem is to get the sql files name we run in sqlplus enviornment with @ symbol. like
i have created one sql file in c drive as
"C:\Createtable.sql"
afterwords i have connected to sqlplus as
sql> conn scott/tiger
sql>@c:\createtable.sql
Now i want some query to get the name of the file which is run.
In actual my problem is as
i have suppose 10 or more SQL files in some folder ( sql1.sql, sql2.sql, sql3.sql ....).
i created one file to call all the 10 sql files (main.sql)
i have also one track_table which will keep track that which sql file is runned.
I want some automated script which will insert the record in that track_table....... for that i need the name of sql file which is runned.
Hope this will help you.
Thanks & Regards
Singh -
Not displaying column names in dynamic pages?
I'd like to use a dynamic page as a detail page. In doing this I need a bit more freedom of design than what I now know is possible. Most important - I only need to print out the values returned by the SQL, not the column names as well. And I need to define the colors and fonts of the html table tags surrounding the returned values. How?
It seems a bit strange that I am allowed to change the look and feel of the surrounding page elements through defining my own templates, and then have Oracle define how the elements placed in the templates are to appear.Hi,
It is not possible to change the format the output coming from the <oracle> tags.
Thanks,
Sharmila -
Input column name in sql?
hi All,
it is possible to create sql command where column name will be input by user.
let say: Select column1(input by user), column2(input by user)......from table1.
so, count of column depends on user's input.
thanks.hi All,
it is possible to create sql command where column
name will be input by user.
let say: Select column1(input by user), column2(input
by user)......from table1.
so, count of column depends on user's input.
thanks.ofcourse it is possible
String qText="select "+ colVariable +"from tablename" -
Using select list value as column name in SQL
Folks,
Thanks in advance for any help with this
I have a select list with two values (Instance and Username) created by
STATIC2:Username;USERNAME,Instance;INSTANCE
I am trying to pass the value of this (:P2_SELECT) and use it as a column name in a SQL query as below
select USERNAME,
INSTANCE
from table_name
where :P2_SELECT like '%'||:P2_TEXTSEARCH||'%'
When I substitue the :P2_SELECT for one of the values (either instance or username) this works fine
I suspect it is due to how Application Express interprets the value of :P2_SELECT
Any help would be much appreciated!
GarethThanks Munky that worked a treat!
The next hurdle I have now is that because I have changed the region type to "PL/SQL Function(returning SQL Query)" there is no longer the option to add sorting to the columns as I have had to change the Source option to "Use Generic Column Names (parse query at runtime only)"
I will have a scout around and see how I can get around this
Gareth
Maybe you are looking for
-
Reported a bug a year ago and sky still not sorted (planner)
When you set a reminder for a program and change the channel early, you still get the stupid pop up telling you of the reminder!!Says to record or view the channel "but i`m already on the channel" surely a year to work out that i`m on the channel is
-
Converting a pdf document with devnagari font
Is it possible to convert a devnagari pdf to devnagari word in krutidev010 font?
-
I have installed oracle database 11g enterprise edition but when I go to the "get started" section, I get stopped by a login screen. How do I find out my credentials, it doesn't appear to be the same credentials as the oracle website sign in?
-
Converting 'little endian bytes' to short
i need to convert to bytes in little endian format (low order byte first) into a short. i wrote an algorithm that i thought would solve this problem. it seems to work most of the time, however occassionally it does produce the wrong value. i was hopi
-
Cap 6.1 - Error with .flv videos in quiz
I have 5 .flv videos in a quiz and they used to work flawlessly. I had some install/uninstall/subscription issues and inadvertently updated captivate from 6.0 to 6.1 (dont know if this is the issue) and ever since I have had errors. The error is easi