Print column names along with values from SQL


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Print column names along with values from SQL
# 1  
Old 07-23-2008
Print column names along with values from SQL

Hi,
Can anyone tell me how to print the column name anong with the value from the table in shell script e.g

Code:
 #!/bin/ksh
 var=`sqlplus scott/tiger << -e
        set heading off feedback off
        select * from emp;
        quit;
        e`
 echo $var

My output should be;

Code:
name:XXXX id:1111 dept:PPP

# 2  
Old 07-23-2008
Remove the colons in the tags and have the ending tag start inside the brackets with a slash to make them work, btw.

Can you also post a snippet of the ouput of that SQL query please (I have no oracle at hand)?
# 3  
Old 07-23-2008
I have done something like this

Code:
select 'COL_1='||col_1,'COL_2='||col_2 from dual;

Hope this helps for others...
# 4  
Old 07-23-2008
You misunderstood me - I would like to see the output of your SQL query to be able to parse it with some tool - not the query itself.

Just the 1st 5 rows including that header. I can't parse what I can't see.
# 5  
Old 07-23-2008
Code:
SELECT 'D_PROC='||TO_CHAR(D_PROC,'YYYYMMDD'),'I_REPROC='||I_REPROC,'C_TYPE_FILE='|| UPPER(TAML000.C_TYPE_FILE),
               'NM_SYS_TRGT='||TAML000.NM_SYS_TRGT,'NM_SRVR_TRGT='||TAML000.NM_SRVR_TRGT,'NM_DIRY_TRGT='||TAML000.NM_DIRY_TRGT,
               'NM_FILE_TRGT='||TAML000.NM_FILE_TRGT,'NM_SYS_SRCE='|| TAML000.NM_SYS_SRCE
        FROM
               $ETLSCHEMA.LOAD_RERUN_REF, $ETLSCHEMA.TAML000
        WHERE
              TAML000.NM_OWNR=UPPER('AMLAPP')
        AND   TAML000.NM_TAB=UPPER('TAML024')
        AND   TAML000.NM_TAB=LOAD_RERUN_REF.NM_TAB
        AND   TAML000.NM_OWNR=LOAD_RERUN_REF.NM_OWNR
        AND   I_PROC='Y';

OUTPUT:

Code:
D_PROC=20080723 I_REPROC=N C_TYPE_FILE=INBOUND NM_SYS_TRGT=A NM_SRVR_TRGT=B NM_DIRY_TRGT=C NM_FILE_TRGT=D NM_SYS_SRCE=CACHE

I want to store this into any array where
Code:
arr[D_PROC]=20080723 ..

How can we achieve this??
# 6  
Old 07-24-2008
hi,

can u try like this:
Code:
set -AF D_AROC"`sqlplus -s<<e
scott/tiger
SELECT 'D_PROC='||TO_CHAR(D_PROC,'YYYYMMDD'),'I_REPROC='||I_REPROC,'C_TYPE_FILE='|| UPPER(TAML000.C_TYPE_FILE),
'NM_SYS_TRGT='||TAML000.NM_SYS_TRGT,'NM_SRVR_TRGT='||TAML000.NM_SRVR_TRGT,'NM_DIRY_TRGT='||TAML000.N M_DIRY_TRGT,
'NM_FILE_TRGT='||TAML000.NM_FILE_TRGT,'NM_SYS_SRCE='|| TAML000.NM_SYS_SRCE
FROM
$ETLSCHEMA.LOAD_RERUN_REF, $ETLSCHEMA.TAML000
WHERE
TAML000.NM_OWNR=UPPER('AMLAPP')
AND TAML000.NM_TAB=UPPER('TAML024')
AND TAML000.NM_TAB=LOAD_RERUN_REF.NM_TAB
AND TAML000.NM_OWNR=LOAD_RERUN_REF.NM_OWNR
AND I_PROC='Y';
e`"

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Linux

Print the 1st column and the value in 2nd or 3rd column if that is different from the values in 1st

I have file that looks like this, DIP-17571N|refseq:NP_651151 DIP-17460N|refseq:NP_511165|uniprotkb:P45890 DIP-17571N|refseq:NP_651151 DIP-19241N|refseq:NP_524261 DIP-19241N|refseq:NP_524261 DIP-17151N|refseq:NP_524316|uniprotkb:O16797 DIP-19588N|refseq:NP_731165 ... (2 Replies)
Discussion started by: Syeda Sumayya
2 Replies

2. Shell Programming and Scripting

awk Print New Column For Every Two Lines and Match On Multiple Column Values to print another column

Hi, My input files is like this axis1 0 1 10 axis2 0 1 5 axis1 1 2 -4 axis2 2 3 -3 axis1 3 4 5 axis2 3 4 -1 axis1 4 5 -6 axis2 4 5 1 Now, these are my following tasks 1. Print a first column for every two rows that has the same value followed by a string. 2. Match on the... (3 Replies)
Discussion started by: jacobs.smith
3 Replies

3. Shell Programming and Scripting

Print unique names in a specific column using awk

Is it possible to modify file like this. 1. Remove all the duplicate names in a define column i.e 4th col 2. Count the no.of unique names separated by ";" and print as a 5th col thanx in advance!! Q input c1 30 3 Eh2 c10 96 3 Frp c41 396 3 Ua5;Lop;Kol;Kol c62 2 30 Fmp;Fmp;Fmp ... (5 Replies)
Discussion started by: quincyjones
5 Replies

4. Shell Programming and Scripting

Print every 5 4th column values as separate row with different first column

Hi, I have the following file, chr1 100 200 20 chr1 201 300 22 chr1 220 345 23 chr1 230 456 33.5 chr1 243 567 90 chr1 345 600 20 chr1 430 619 21.78 chr1 870 910 112.3 chr1 914 920 12 chr1 930 999 13 My output would be peak1 20 22 23 33.5 90 peak2 20 21.78 112.3 12 13 Here the... (3 Replies)
Discussion started by: jacobs.smith
3 Replies

5. Shell Programming and Scripting

Print unique names in each row of a specific column using awk

Is it possible to remove redundant names in the 4th column? input cqWE 100 200 singapore;singapore AZO 300 400 brazil;america;germany;ireland;germany .... .... output cqWE 100 200 singapore AZO 300 400 brazil;america;germany;ireland (4 Replies)
Discussion started by: quincyjones
4 Replies

6. Shell Programming and Scripting

Transpose field names from column headers to values in one column

Hi All, I'm looking for a script which can transpose field names from column headers to values in one column. for example, the input is: IDa;IDb;IDc;PARAM1;PARAM2;PARAM3; a;b;c;p1val;p2val;p3val; d;e;f;p4val;p5val;p6val; g;h;i;p7val;p8val;p9val; into the output like this: ... (6 Replies)
Discussion started by: popesk
6 Replies

7. Shell Programming and Scripting

Print rows in reverse order if values decrease along the column

Hi, Guys. Please help me to find solution to this problem using shell scripting. I have an INPUT file with 4 columns separated by tab. Each block of records is separated by ----- ----- Sample1 5402 6680 Pattern01 Sample2 2216 2368 Pattern02... (6 Replies)
Discussion started by: sam_2921
6 Replies

8. Shell Programming and Scripting

print unique values of a column and sum up the corresponding values in next column

Hi All, I have a file which is having 3 columns as (string string integer) a b 1 x y 2 p k 5 y y 4 ..... ..... Question: I want get the unique value of column 2 in a sorted way(on column 2) and the sum of the 3rd column of the corresponding rows. e.g the above file should return the... (6 Replies)
Discussion started by: amigarus
6 Replies

9. UNIX for Dummies Questions & Answers

Extracting column names from a table.. SQL with UNIX

:rolleyes: hi there everybody, i need help,... thanks anyway! i am working on a very huge table with the name table1. the problem is that i know only one field name in this table..., working with a ksh environment i don't know how to view the table to check out the field names :confused:. ... (4 Replies)
Discussion started by: fmina
4 Replies

10. Shell Programming and Scripting

how to read the column and print the values under that column

hi all:b:, how to read the column and print the values under that column ...?? file1 have something like this cat file1 ======= column1, column2,date,column3,column4..... 1, 23 , 12/02/2008,...... 2, 45, 14/05/2008,..... 3, 56, 16/03/2008,..... cat file2 =======... (6 Replies)
Discussion started by: gemini106
6 Replies
Login or Register to Ask a Question