02-15-2006
There are many ways to do this.. First format the cloumns you want to select to make them as characters. then select all the columns from table and create a spool file. this will solve your purpose.
A sample file is mentioned below.. Try to get help from this..
cat <<EOD > $TmpFileName
spool $SpoolFileName
set heading off
set termout off
set feedback off
set pagesize 0
set linesize 240
set colsep ' '
-- set the column format.
col CUST_ID format a10
col HDR_ID format a10
col ITEM_NO format a10
col SAP_MTL_NBR format a18
col MTL_DSCR format a80
col MTL_GRP format a10
col PLNG_QTY format a30
col UOM format a4
col SLS_ORG format a10
col PLANT format a10
col OMAD_DTE format a10
col CREATE_DTE format a10
--**********************************************************************
-- selects the Heading
--**********************************************************************
SELECT distinct
'CUST_ID' CUST_ID,
'HDR_ID' HDR_ID,
'ITEM_NO' ITEM_NO,
'SAP_MTL_NBR' SAP_MTL_NBR,
'MTL_DSCR' MTL_DSCR,
'MTL_GRP' MTL_GRP,
'PLNG_QTY' PLNG_QTY,
'UOM' UOM,
'SLS_ORG' SLS_ORG,
'PLANT' PLANT,
'OMAD_DTE' OMAD_DTE,
'CREATE_DTE' CREATE_DTE
FROM dual;
--**********************************************************************
-- selects the records
--**********************************************************************
SELECT H.Trade_Cust_ID CUST_ID,
H.Ord_Hdr_ID HDR_ID,
I.Ord_Ln_Item_ID ITEM_NO,
I.SAP_Mtl_nbr SAP_MTL_NBR,
M.Mtl_Dscr MTL_DSCR,
M.Mtl_Grp_ID MTL_GRP ,
TO_CHAR(NVL(I.Ord_Plng_Unt_Qty,0),'099999999999.999') PLNG_QTY,
'PU' UOM,
H.SAP_SLS_ORG_ID SLS_ORG,
I.Plant_ID PLANT,
TO_CHAR(I.Orig_OMAD_Dte,'MM/DD/YYYY') OMAD_DTE,
TO_CHAR(I.Create_Dte,'MM/DD/YYYY') CREATE_DTE
FROM
tab1 H,
Tab2 I,
tab3 M
WHERE
-----;
spool off;
/
quit
EOD
${ORACLE_HOME}/bin/sqlplus user_id password $TmpFileName 1>> \
$LogFileName 2>&1
Hope it will help you to come out of your problem.
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Hi,
I have a file that has contents like this:
SQL> select * from details;
NAME REG
-------------------- ----------
Mani 1
Santosh 2
Manju 3
Mukesh 4
SQL> spool off;
... (5 Replies)
Discussion started by: sendhilmani123
5 Replies
2. Shell Programming and Scripting
hi
iam new of scipiting.give me the some Material of regarding sql in scripting.
and i have no backup's in 3 severs.how to write script in dirctory.
please give me some usefull information
cheers
Naveen.g (2 Replies)
Discussion started by: naveeng.81
2 Replies
3. Shell Programming and Scripting
Hi,
I am looking for some books that have examples of both Oracle SQL and Shell script being used together. For example, to insert 500 rows into a table using a script. I already have books that cover Shell scripting or SQL, but as separate subjects. I am looking for books that have both of... (3 Replies)
Discussion started by: handle123
3 Replies
4. Shell Programming and Scripting
Hi,
I need to write a shell script file that does
1)Connects to DB using SQL plus
2)Do some SQL query like select * from....
3)Based on the output that I got from the sql query I will have to write a if else loop.
Plz let me know how to write the shell scripting for this.
Thanks for... (1 Reply)
Discussion started by: villain41
1 Replies
5. Shell Programming and Scripting
I am trying to assgn the output of the select statement to a variable, like this
"VARIABLE_NAME=$ db2 "select COLUMN_NAME_1 from TABLE_NAME where COLUMN_NAME_2='VALUE_TO_CHECK'"; "
but the value that is getting into VARIABLE_NAME is
"COLUMN_NAME_1
-----------------
VALUE
1... (3 Replies)
Discussion started by: sgmini
3 Replies
6. Shell Programming and Scripting
HI friends , i am also facing an issue in mysql
i ma trying to insert detail in a variable but not got success
#!/bin/sh
mysql -u<username> -p<password> <dbname> << EOF
DEV=`mysql --skip-column-names <dbname> -e "SELECT timestamp from process_record where id = 1"`
EOF
echo $DEV
ERROR... (3 Replies)
Discussion started by: sanjay833i
3 Replies
7. Shell Programming and Scripting
hey i have to connect to sql through shell script , then store the value of the query in a variable and then compare it after some time after running a process.
i have used this code but it is not working.
#!/bin/sh
Val = (sqlplus -s rte/rted2@rel76d2 <<!
SELECT MAX(STAT_ID) FROM CVT_STATS;... (3 Replies)
Discussion started by: ramsavi
3 Replies
8. UNIX for Dummies Questions & Answers
hey i am using this code to connect to sql , store the value in variable and then
compare it with another variable after some time by executing the same query
but the desired result is not coming
#!/bin/bash
val=$(sqlplus -s rte/rted2@rel76d2 <<ENDOFSQL
set heading off
set feedback off... (11 Replies)
Discussion started by: ramsavi
11 Replies
9. Shell Programming and Scripting
I have a situation where I have a list of airplanes that make a series of flights.
Therefore I am looking up the different flights that each airplane makes based on a postgres sql query:
select flightid from plane where airplane='DELTAx'
As a result I get a series of flight numbers... (0 Replies)
Discussion started by: JSNY
0 Replies
10. Shell Programming and Scripting
Can anyone please assist me?
I have attached 2 input files and one output file. I need to generate the sql update statements using the above 2 input files. if inputfile2 has 5 rows, then we should generate 5 update statements because column1 is unique. inputfile1 and inputfile2 may contain more... (10 Replies)
Discussion started by: vinus
10 Replies
LEARN ABOUT OPENSOLARIS
select.h
select.h(3HEAD) Headers select.h(3HEAD)
NAME
select.h, select - select types
SYNOPSIS
#include <sys/select.h>
DESCRIPTION
The <sys/select.h> header defines the timeval structure, which includes the following members:
time_t tv_sec /* seconds */
suseconds_t tv_usec /* microseconds */
The time_t and suseconds_t types are defined as described in <sys/types.h>. See types.h(3HEAD).
The sigset_t type is defined as described in signal.h(3HEAD).
The timespec structure is defined as described in <time.h>. See time.h(3HEAD).
The <sys/select.h> header defines the fd_set type as a structure.
The following is defined as a macro:
FD_SETSIZE Maximum number of file descriptors in an fd_set structure.
Inclusion of the <sys/select.h> header can make visible all symbols from the headers <signal.h>, <sys/time.h>, and <time.h>.
ATTRIBUTES
See attributes(5) for descriptions of the following attributes:
+-----------------------------+-----------------------------+
| ATTRIBUTE TYPE | ATTRIBUTE VALUE |
+-----------------------------+-----------------------------+
|Interface Stability |Standard |
+-----------------------------+-----------------------------+
SEE ALSO
select(3C), signal.h(3HEAD), time.h(3HEAD), types.h(3HEAD), attributes(5), standards(5)
SunOS 5.11 10 Sep 2004 select.h(3HEAD)