[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 477
  • Last Modified:

Unix Script Problem

This script retrun values into a txt file. I need to insert a delimter "^", Currently the delimiter is only added to the headings. How can I add it to the end of the actual data.

e.g

Val1  val2  val3
ss^  dd^   mm^

select substring(Task_Type,1,10)"Type^",
       substring(Job_Name,1,10)"Jobname^",
       substring(MemName,1,30)"Member^",
       substring(W_Day_Str,1,15)"Week Days^" ,
       substring(Days_Cal,1,10)"Calendar^",
       substring(Group_Name,1,30)"Group^",
       substring(Description,1,60)"Description^",
       substring(Node_Id,1,12)"Data Center^" from def_job

Thanks
0
xy15973
Asked:
xy15973
  • 2
1 Solution
 
pmathinosCommented:
Change this line to reflect your table/columns and try it:

e.g:
SELECT SUBSTR(NUMDATA,4,4)||'^ '||UPLINK||'^ '||DOWNLINK||'^ '||TOTAL
FROM TEMP_TABLE

will give you:

9480^ 0^ 0^ 0
9478^ 1170^ 58^ 1228
9470^ 0^ 0^ 0
9422^ 0^ 0^ 0
9473^ 0^ 0^ 0
9445^ 1281^ 366^ 1647
9472^ 0^ 0^ 0
9480^ 0^ 0^ 0
9479^ 0^ 0^ 0

pmathinos.
0
 
xy15973Author Commented:

Will this work?

select substring(Task_Type,1,10)||"^"||Type ,
       substring(Job_Name,1,10)||"^"||Jobname ,
       substring(MemName,1,30)||"^"||Member ,
       substring(W_Day_Str,1,15)||"^"||"Week Days" ,
       substring(Days_Cal,1,10)||"^"||"Calendar",
       substring(Group_Name,1,30)||"^"||"Group",
       substring(Description,1,60)||"^"||"Description",
       substring(Node_Id,1,12)||"^"||"Data Center" from def_job
go
0
 
pmathinosCommented:
double quotes will not work. Use single quotes to append Strings to columns...

To get the column headers as well use a separate SQL query.

Save the following to an temp.sql file, start your SQL session and type
SQL> @temp.sql
to execute the file...
"output.dat" will contain your '^' - delimited report

-- start of sql file

set heading off
set linesize 100
set feed off
set echo off
set show off
set pagesize 0
set space 0
set trimspool on

SPOOL output.dat

select 'Type'||'^'||'Jobname'||'^'||'Member'||'^'||'Week Days'||'^'||'Calendar'||'^'||'Group'||'^'||'Description'||'^'||'Data Center' from dual;

select      substring(Task_Type,1,10)||'^'||
      substring(Job_Name,1,10)||'^'||
      substring(MemName,1,30)||'^'||
      substring(W_Day_Str,1,15)||'^'||
      substring(Days_Cal,1,10)||'^'||
      substring(Group_Name,1,30)||'^'||
      substring(Description,1,60)||'^'||
      substring(Node_Id,1,12)
from def_job;

SPOOL OFF

-- end of sql file


0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now