Re: How do you get a verticle list of table columns plus sample value?

From: Thomas Kyte <tkyte_at_us.oracle.com>
Date: Sun, 22 Jul 2001 06:54:48 GMT
Message-ID: <9hlt5t046f_at_drn.newsguy.com>


In article <84qsjtkehbiirvrcvab26s55i17e327jvt_at_4ax.com>, John says...
>
>Can anyone offer a method of obtaining a sample record from a table
>which lists each column vertically plus a sample value? VAX Datatrieve has
>a very useful command called LIST which does this but I haven't found an
>Oracle or Steven Feuerstein package that does a similar job. I have used a
>complex PL/SQL loop using ALL_TAB_COLUMNS but am having a job getting this
>to generate dynamic SQL in the spooled output. For example,
>the output from SCOTT.EMP would look like this:
>
>EMPNO 7521
>ENAME WARD
>JOB SALESMAN
>MGR 7698
>HIREDATE 22-Feb-81
>SAL 1250
>COMM 500
>DEPTNO 30
>
>Any suggestions welcomed!
>TIA,
>John
>

see
http://asktom.oracle.com/pls/ask/f?p=4950:8:::::F4950_P8_DISPLAYID:1035431863958 [Quoted] for a copy of print_table I have -- it prints down the screen in sqlplus. Easy enough to take it and write a procedure list:

scott_at_ORA8I.WORLD> create or replace procedure list( p_tname in varchar2 )   2 as
  3 begin
  4 print_table( 'select * from ' || p_tname || ' where rownum=1' );   5 end;
  6 /

Procedure created.

scott_at_ORA8I.WORLD> exec list('emp')

EMPNO                         : 7369
ENAME                         : SMITH
JOB                           : CLERK
MGR                           : 7902
HIREDATE                      : 17-dec-1980 00:00:00
SAL                           : 800
COMM                          :
DEPTNO                        : 20
-----------------

PL/SQL procedure successfully completed.

scott_at_ORA8I.WORLD>

--
Thomas Kyte (tkyte_at_us.oracle.com)             http://asktom.oracle.com/ 
Expert one on one Oracle, programming techniques and solutions for Oracle.
http://www.amazon.com/exec/obidos/ASIN/1861004826/  
Opinions are mine and do not necessarily reflect those of Oracle Corp 
Received on Sun Jul 22 2001 - 08:54:48 CEST

Original text of this message