Spool filename_sysdate.csv
Hi All,
I want to add sysdate with my spool file name. Could anyone please tell me how can I achieve that?
Many thanks in advance!
Ash.
Amazing what you can find if you search..
http://forums.oracle.com/forums/search.jspa?threadID=&q=spool+dynamic+filename&objID=f75&dateRange=all&userID=&numResults=30
Similar Messages
-
How to enclosed the column with in double quotes while spooling to csv fie
Dear Members,
I have to spool a sql to a CSV file. I have two columns to spool one is vendor_id and another is vendor_name. But the 2nd column vendor_name has commas in it so if i see the o/p it looks like this:
Suppose vendor_id = 12790 vendor_name = T T I, INCORPORATED
when i see the csv file it looks
12790,T T I, INCORPORATED
I want each column be enclosed in double quotes like this
"12790","T T I, INCORPORATED"
How can i do this in sql*plus while spooling to a csv file.
Thanks
sandeepthis?
SQL> select '"'||'Hi'||'"'||',"'||'how'||'"' from dual;
'"'||'HI'|
"Hi","how" -
Spool to csv file problem--comma included in the data
Friends,
i spooled the table's data to csv file.
when i open it in the excel sheet some of the records are in the different cells.
below is the record....
Colonial Street, Ruwanda
so when i view it in the excel sheet.
Colonial Street is coming in one cell
and
Ruwanda is coming in the next cell.
but "Colonial Street, Ruwanda" is the single entry in the column.
so how can i spool the record which is having comma (,) in between the words to get it in the single cell of excel?
thanksUsually putting double quotes around your column values should take care of that:
select '"'||column1
||'","'||column2
||'","'||column3||'"'
from your_table -
Spool with .csv file with appropiate line
Hi All,
I am spooling .csv file in sqlplus below are the spooling sqlplus command,
set echo off
set verify off
set termout on
set heading off
set pages 50000
set feedback off
set newpage none
set linesize 160
SET TRIMSPOOL on
spool d:\spool1.csv
select 'MENU_USAGE_ID,BAC,SRV_CNSLTNT_ID,SRV_CNSLTNT_FNAME,SRV_CNSLTNT_LNAME,PRESENTED_MENUS_COUNT,PRESENTED_SERVICES_COUNT,ACCPT_SERVICES_COUNT,TOTAL_PRSNT_MENUS_VALUE,TOTAL_ACCPT_MENUS_VALUE,MENU_USAGE_DATE,CREATEDBY,UPDATEDBY,CREATED_DATETIME,UPDATED_DATETIME,CUSTOMER_MENU_ID,TOTAL_DECLINED_MENU_PRICE,CHANNEL,MODEL_YEAR,MODEL_DESC,VIN,CURRENT_MILEAGE,RO_NUMBER,GM_SERVICES_ACCEPTED,GM_SERVICES_DECLINED,DEALER_SERVICES_ACCEPTED,DEALER_SERVICES_DECLINED' from dual;
select
MENU_USAGE_ID ||','|| BAC||','|| SRV_CNSLTNT_ID||','|| SRV_CNSLTNT_FNAME||','|| SRV_CNSLTNT_LNAME||','|| PRESENTED_MENUS_COUNT||','|| PRESENTED_SERVICES_COUNT||','|| ACCPT_SERVICES_COUNT||','|| TOTAL_PRSNT_MENUS_VALUE||','|| TOTAL_ACCPT_MENUS_VALUE||','|| MENU_USAGE_DATE||','|| CREATEDBY||','|| UPDATEDBY||','|| CREATED_DATETIME||','|| UPDATED_DATETIME||','|| CUSTOMER_MENU_ID||','|| TOTAL_DECLINED_MENU_PRICE||','|| CHANNEL||','|| MODEL_YEAR||','|| MODEL_DESC||','|| VIN||','|| CURRENT_MILEAGE||','|| RO_NUMBER||','|| GM_SERVICES_ACCEPTED||','|| GM_SERVICES_DECLINED||','|| DEALER_SERVICES_ACCEPTED||','|| DEALER_SERVICES_DECLINED from menu_usage;
spool off;
But when I am opening .csv file I seeing like
>
SQL> select 'MENU_USAGE_ID BAC SRV_CNSLTNT_ID SRV_CNSLTNT_FNAME SRV_CNSLTNT_LNAME PRESENTED_MENUS_COUNT PRESENTED_SERVICES_COUNT ACCPT_SERVICES_COUNT TOTAL_PRSNT_MENUS_VALUE TOTAL_ACCPT_MENUS_VALUE MENU_USAGE_DATE CREATEDBY UPDATEDBY CREATED_DATETIME UPDATED_DATETIME CUSTOMER_MENU_ID TOTAL_DECLINED_MENU_PRICE CHANNEL MODEL_YEAR MODEL_DESC VIN CURRENT_MILEAGE RO_NUMBER GM_SERVICES_ACCEPTED GM_SERVICES_DECLINED DEALER_SERVICES_ACCEPTED DEALER_SERVICES_DECLINED' from dual;
I have attached the both .csv files .
My requirement is
It should come like this in .csv file.
13706940 partId_001 Mark James 1 2 2 146.26 146.26 9-Apr-12 tpsdir tpsdir 9-Apr-12 9-Apr-12 9030845 0 UI 2006 CTS 1G6DP577X60140937 45 RO3 1 0 0 0
13706949 partId_001 Mark James 1 6 3 296.87 158.04 ######## tpsdir tpsdir ######## ######## 9030859 138.83 UI 2010 Avalanche - 4WD 56000 1 3 2 0
13706948 partId_001 Mark James 1 3 0 145.84 0 ######## tpsdir tpsdir ######## ######## 9030858 145.84 UI 2012 CTS 1GASDFJASLDFJLASD 50000 0 2 0 1
1. Not required >SQL prompt
2. Not required column header
3. Not required SQL> spool off;
Can anyone please help on this.
Thanks,
KrupaOther solution is to avoid using SQL*Plus spooling...
(From my standard library of examples...)
As sys user:
CREATE OR REPLACE DIRECTORY TEST_DIR AS '\tmp\myfiles'
GRANT READ, WRITE ON DIRECTORY TEST_DIR TO myuser
/As myuser:
CREATE OR REPLACE PROCEDURE run_query(p_sql IN VARCHAR2
,p_dir IN VARCHAR2
,p_header_file IN VARCHAR2
,p_data_file IN VARCHAR2 := NULL) IS
v_finaltxt VARCHAR2(4000);
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_fh UTL_FILE.FILE_TYPE;
v_samefile BOOLEAN := (NVL(p_data_file,p_header_file) = p_header_file);
BEGIN
c := DBMS_SQL.OPEN_CURSOR;
DBMS_SQL.PARSE(c, p_sql, DBMS_SQL.NATIVE);
d := DBMS_SQL.EXECUTE(c);
DBMS_SQL.DESCRIBE_COLUMNS(c, col_cnt, rec_tab);
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);
WHEN 2 THEN DBMS_SQL.DEFINE_COLUMN(c,j,v_n_val);
WHEN 12 THEN DBMS_SQL.DEFINE_COLUMN(c,j,v_d_val);
ELSE
DBMS_SQL.DEFINE_COLUMN(c,j,v_v_val,2000);
END CASE;
END LOOP;
-- This part outputs the HEADER
v_fh := UTL_FILE.FOPEN(upper(p_dir),p_header_file,'w',32767);
FOR j in 1..col_cnt
LOOP
v_finaltxt := ltrim(v_finaltxt||','||lower(rec_tab(j).col_name),',');
END LOOP;
-- DBMS_OUTPUT.PUT_LINE(v_finaltxt);
UTL_FILE.PUT_LINE(v_fh, v_finaltxt);
IF NOT v_samefile THEN
UTL_FILE.FCLOSE(v_fh);
END IF;
-- This part outputs the DATA
IF NOT v_samefile THEN
v_fh := UTL_FILE.FOPEN(upper(p_dir),p_data_file,'w',32767);
END IF;
LOOP
v_ret := DBMS_SQL.FETCH_ROWS(c);
EXIT WHEN v_ret = 0;
v_finaltxt := NULL;
FOR j in 1..col_cnt
LOOP
CASE rec_tab(j).col_type
WHEN 1 THEN DBMS_SQL.COLUMN_VALUE(c,j,v_v_val);
v_finaltxt := ltrim(v_finaltxt||',"'||v_v_val||'"',',');
WHEN 2 THEN DBMS_SQL.COLUMN_VALUE(c,j,v_n_val);
v_finaltxt := ltrim(v_finaltxt||','||v_n_val,',');
WHEN 12 THEN DBMS_SQL.COLUMN_VALUE(c,j,v_d_val);
v_finaltxt := ltrim(v_finaltxt||','||to_char(v_d_val,'DD/MM/YYYY HH24:MI:SS'),',');
ELSE
v_finaltxt := ltrim(v_finaltxt||',"'||v_v_val||'"',',');
END CASE;
END LOOP;
-- DBMS_OUTPUT.PUT_LINE(v_finaltxt);
UTL_FILE.PUT_LINE(v_fh, v_finaltxt);
END LOOP;
UTL_FILE.FCLOSE(v_fh);
DBMS_SQL.CLOSE_CURSOR(c);
END;This allows for the header row and the data to be written to seperate files if required.
e.g.
SQL> exec run_query('select * from emp','TEST_DIR','output.txt');
PL/SQL procedure successfully completed.Output.txt file contains:
empno,ename,job,mgr,hiredate,sal,comm,deptno
7369,"SMITH","CLERK",7902,17/12/1980 00:00:00,800,,20
7499,"ALLEN","SALESMAN",7698,20/02/1981 00:00:00,1600,300,30
7521,"WARD","SALESMAN",7698,22/02/1981 00:00:00,1250,500,30
7566,"JONES","MANAGER",7839,02/04/1981 00:00:00,2975,,20
7654,"MARTIN","SALESMAN",7698,28/09/1981 00:00:00,1250,1400,30
7698,"BLAKE","MANAGER",7839,01/05/1981 00:00:00,2850,,30
7782,"CLARK","MANAGER",7839,09/06/1981 00:00:00,2450,,10
7788,"SCOTT","ANALYST",7566,19/04/1987 00:00:00,3000,,20
7839,"KING","PRESIDENT",,17/11/1981 00:00:00,5000,,10
7844,"TURNER","SALESMAN",7698,08/09/1981 00:00:00,1500,0,30
7876,"ADAMS","CLERK",7788,23/05/1987 00:00:00,1100,,20
7900,"JAMES","CLERK",7698,03/12/1981 00:00:00,950,,30
7902,"FORD","ANALYST",7566,03/12/1981 00:00:00,3000,,20
7934,"MILLER","CLERK",7782,23/01/1982 00:00:00,1300,,10The procedure allows for the header and data to go to seperate files if required. Just specifying the "header" filename will put the header and data in the one file.
Adapt to output different datatypes and styles are required. -
Hello!!! When i create an after report trigger in oracle reports (Please dont schold me, for posting in this forum, Its just because everybody seems to be smarter here ;) ) <br> Nothing happenins, the code has compile with no errors...... So could some please give my code a check, and offer some suggestions.
PROCEDURE p_create_csv IS
csvfile text_IO.File_Type;
csvline varchar2(1000);
tmp_rca number;
tmp_total number;
tmp_address varchar2(100);
tmp_start_date date;
tmp_end_date date;
cursor read_lpa_lps is
SELECT
LPA_CLAIM.RCA_REF_NUMBER,
TO_CHAR(hist.total,9999990.909999) AS total,
LPA_INPUT.INPUT_FLAT||''||
LPA_INPUT.INPUT_HOUSE_NO||' '||
LPA_INPUT.INPUT_ADDRESS_LINE1 ||', '||
LPA_INPUT.INPUT_ADDRESS_LINE2 ||', '||
LPA_INPUT.INPUT_ADDRESS_LINE3 ||', '||
LPA_INPUT.INPUT_ADDRESS_LINE4 ||', '||
LPA_INPUT.INPUT_POST_CODE ||', '||
LPA_INPUT.CLAIM_NO AS address,
LPA_CLAIM.START_DATE,
LPA_CLAIM.END_DATE
FROM LPA_CLAIM,
LPA_INPUT,
LPA_HISTORY,
(SELECT lpa_history.claim_no,
SUM ((LPA_HISTORY.END_DATE - LPA_HISTORY.START_DATE +1 )
* (ROUND(LPA_HISTORY.LPA_AMT,2))/7) total
FROM LPA_HISTORY, LPA_CLAIM, LPA_INPUT
where lpa_history.claim_no = LPA_CLAIM.claim_no
and lpa_history.claim_no = LPA_INPUT.claim_no
and ((ent_seqno = (select max(ent_seqno)
from lpa_history where lpa_claim.claim_no = claim_no and start_date
= (select min(start_date) from lpa_history where lpa_claim.claim_no = claim_no)))
or
(ent_seqno > (select max(ent_seqno) from lpa_history
where lpa_claim.claim_no = claim_no and start_date
= (select min(start_date) from lpa_history where lpa_claim.claim_no = claim_no))))
group by lpa_history.claim_no
) hist
WHERE LPA_CLAIM.CLAIM_NO = LPA_INPUT.CLAIM_NO
AND LPA_CLAIM.CLAIM_NO = LPA_HISTORY.CLAIM_NO
AND LPA_CLAIM.CLAIM_NO = hist.CLAIM_NO
AND LPA_CLAIM.TENANCY_TYPE = 'PTEN'
AND LPA_CLAIM.TENURE_TYPE = 'NOT HA'
AND (LPA_INPUT.INPUT_DECISION = 'Eligible'
OR LPA_INPUT.INPUT_DECISION IS NULL)
ORDER BY LPA_INPUT.INPUT_SURNAME;
BEGIN
csvfile := Text_IO.Fopen('c:\'||'lpa_lps.csv','W');
open read_lpa_lps;
loop
fetch read_lpa_lps into tmp_rca, tmp_total, tmp_address, tmp_start_date, tmp_end_date;
if read_lpa_lps%notfound then
exit;
end if;
csvline := tmp_rca||','||to_char(tmp_total)
||','||tmp_address||','||
to_char(tmp_start_date)||','||to_char(tmp_end_date);
Text_IO.Put(csvfile,csvline);
Text_IO.New_Line(csvfile, 1);
end loop;
close read_lpa_lps;
Text_IO.Fclose(csvfile);
END;Thank UIs reports running as a local client version or via an application server?
If it's an application server then the file should have been created on the server, not on the client. -
Hi,
I want to spool a csv file from unix.. I have a shell script where im calling the .sql file in returns it select the data from the table and spool it to CSV..
THe problem i have here when i spool it , it is not comming in the right format..
for ex :
set head on;
set feed off;
set trimspool on;
set linesize 32627;
set pagesize 32627;
set echo off;
set termout on;
O/p is like
empid ename sal mgr
1234 xysss 2323232 wewew
Can anyone please help me out...Hi,
When posting formatted text (such as your output) on this site, type these 6 characters:
\(small letters only, inside curly brackets) before and after each section of formatted text, to preserve spacing.
What's wrong with the current output?
What is the correct output you want?
A lot of folks concatenate all their output into one big string column for CSV output.
That is, instead of:SELECT empid
, ename
, hiredate
, sal
they say:SELECT empid
|| ',' || ename
|| ',' || TO_CHAR (hiredate, 'DD-MON-YYYY')
|| ',' || sal
Most of the time, NUMBER columns don't require special formatting, but DATEs often do. -
Need help in writing data to a flat file in .csv format
Hi All,
could you please show with a sample example to write data in .csv format using UTL_file.
The result of the refcursor i want to write to a file in .csv format.
How can i achieve this.
ThxHi,
There are two ways to acheive this.
First and which I prefer is creating a SQL script which will generate csv file at the specified location in CSV format. And then this SQL script can be called from your cron job similar to how you call stored procedure. Following is pseudo code that can be used -
set linesize 500
set echo off
set feedback off
set prompt off
set pagesize 0
spool <name of the csv file>.csv
<Your select statement>;
spool offPut select statement delimiting columns you want to use with ','. E.g. following query should create a CSV file named as abc.csv with one record and 2 columns delimited by comma. First column is ENO and second column is ENAME.
set linesize 500
set echo off
set feedback off
set prompt off
set pagesize 0
spool abc.csv
select ENO || ',' || ENAME from employee;
spool offSecond, you can write a PLSQL procedure and then call this procedure from cron job. There is a generic procedure shared by BluShadow some time back which is a very good example for this. Please refer to following link for this solution -
REF Cursor creating CSV files
I will suggest to use first method above if possible since it will be faster and less complicated in my opinion. Second method is recommended for scenarios where select statement is created dynamically and cannot be written during development.
Hope this solves your purpose.
Cheers,
Anirudha -
Hello All,
I have a table named as 'product' having two columns prod_name and prod_status.
Table Name: product
prod_name prod_status
bag A
Pen A
Pencil B
Eraser C
Paper A
Now if I will write a query
select prod_name from product where prod_status='A';
Then it will return me output as:
prod_name
bag
Pen
Paper
But I want output as:
prod_name
bag,Pen,Paper
I have checked solution for this problem on many thread but havent found any good solution. I want it for 10G.
Thanks in advance
Edited by: Tushky on Aug 4, 2010 2:04 AMIt looks quite amazing that you did not found any solution for this porbs on forum. Anyways try the below query, it works in 10g.
To write in CSV file, spool a CSV file and copy the contents....
with c as
(select 'bag' str from dual union all
select 'pen' str from dual union all
select 'paper' str from dual )
select rtrim(xmlagg(xmlelement(e,str||',').extract('//text()')),',') op
from c
SQL> /
OP
bag,pen,paper -
How to export data to .csv and send that file to folder using sql commands?
Really hoping someone can provide some code sample or point me in the right direction (with examples using sql).
I am using oracle 11g with plsql developer. My requirement is that the data retrieval should be automatic. That means when query a data in oracle table , the data should be convert into .csv file and then it should send that to some specific folder.
Example: Assume that student_sub1 table have all students subject1 data.when i write a query like select * from student_sub1 where student=1, the student1 data should convert into .csv file and then the .csv file should go to student1 folder.
Hence I am requesting you to suggest me how write a sql code to convert the data into .csv file and to create a folder to send that file using oracle.
Your inputs helps me alot.
Thanks in advance!!!!
Waiting for your replies.... Cheers981145 wrote:
Really hoping someone can provide some code sample or point me in the right direction (with examples using sql).
I am using oracle 11g with plsql developer. My requirement is that the data retrieval should be automatic. That means when query a data in oracle table , the data should be convert into .csv file and then it should send that to some specific folder.
Example: Assume that student_sub1 table have all students subject1 data.when i write a query like select * from student_sub1 where student=1, the student1 data should convert into .csv file and then the .csv file should go to student1 folder.
Hence I am requesting you to suggest me how write a sql code to convert the data into .csv file and to create a folder to send that file using oracle.
Your inputs helps me alot.
Thanks in advance!!!!
Waiting for your replies.... CheersSET COLSEP ,
spool student1.csv
select * from student_sub1 where student=1;
spool off
How do I ask a question on the forums?
SQL and PL/SQL FAQ
Handle: 981145
Status Level: Newbie
Registered: Jan 10, 2013
Total Posts: 25
Total Questions: 10 (8 unresolved)
I extend my condolences to you since you rarely get answers to your questions here. -
How to write stored procedure to spool data into file
Hi ,
We get differnt excel sheets of differnt products.
We upload data from excel sheet to database . After uploading data , I run Preprossor (sql script) to check the data
This preprocessor script contains several select statements that query different tables in database .the output is spooled into a cvs file .
I need to change this script into a stored procedure and spool the output to cvs file.
File spooling should be done inside the stored procedure so that if I call this stored procedure from java program ,or any concurrent program,its output is .cvs file and in parameter should be productname.
But inside the stored procedure , we cannot spool the data to some .cvs file . Is any way.I do not want to spool to file when calling.It should be inside stored procedure.
Or do I need to create a table and insert all the select statements output into it .
Here is the sample preprocessor script.
spool Graco_Product.csv
set head off
set feedback off
set Pagesize 100
SELECT '1. EVERY ASSEMBLY GROUP ADDED IN sys_PRODUCT TABLE MUST HAVE AT LEAST ONE ITEM IN WOC_ASSEMBLY_ITEM'
FROM DUAL;
SELECT 'ASSEMBLY_GROUP_NAME'
FROM DUAL;
SELECT
assembly_group_name
FROM association
WHERE product_model_name = 'Graco_Product'
AND assembly_group_name NOT IN (SELECT DISTINCT assembly_group_name FROM woc_assembly_item);
SELECT '2. A RULE SHOULD HAVE AT LEAST ONE EXPRESSION FOR ITS ACTION SIDE.'
FROM DUAL;
SELECT 'RELATION_ID , RELATION_TYPE'
FROM DUAL;
SELECT wr.Relation_ID ||','||
wr.Relation_Type
FROM WOC_Relation wr
WHERE NOT EXISTS (SELECT 'X' FROM WOC_Relation_Expression wre
WHERE wre.Relation_Side = 'Action'
AND wr.Relation_ID = wre.Relation_ID)
AND wr.Relation_Type NOT IN ( 'Rule Warning','Rule Resource','Rule Default');
SELECT '3. PROPERTIES USED IN RULES SHOULD EXIST IN WOC_PROPERTY_MASTER -- EXP_LHS_VALUE'
FROM DUAL;
SELECT
'RELATION_OWNER,EXP_LHS_OPERAND,RELATION_SIDE,RELATION_ID,EXP_LHS_VALUE,RELATION_TYPE'
FROM DUAL;
SELECT
b.relation_owner ||','||
a.exp_lhs_operand ||','||
a.relation_side ||','||
a.relation_id ||','||
a.exp_lhs_value ||','||
b.relation_type
FROM woc_relation_expression a, woc_relation b
WHERE a.exp_lhs_value IS NOT NULL
AND a.exp_lhs_value_type = 'Property'
AND a.exp_lhs_value NOT IN (SELECT property_name FROM woc_property)
AND b.product_model_name = 'Graco_Product'
AND a.relation_id = b.relation_id;
SELECT '--------------------------------------------------------------------------------'
from dual;
spool off
set head on
set feedback onHigh level description
Full documentation
Note that the UTL_ and DBMS_ packages are all covered in the PL/SQL Packages and Types Reference.
You may also want to read up on the CREATE DIRECTORY statement, which lets you refer to an actual OS directory (which you create separately) via a database object. -
Problem in csv file generation
Hi ,
I am trying to spool a query in csv format using "col sep ,"
but it is giving problem for the text values like example i have a sql_text column which gives the sql text. in the csv file which was generated the select statement columns are going to next column where the comma is invoked.
is there any way to format while generating csv file that entire sql_text should come in one column
Thanks
Rakeshset echo OFF pages 50000 lin 32767 feed off heading ON verify off newpage none trimspool on
define datef=&1
define datet=&2
set colsep ','
spool querries.csv
SELECT s.parsing_schema_name,
p.instance_number instance_number,
s.sql_id sql_id,
x.sql_text sql_text,
p.snap_id snap_id,
TO_CHAR (p.begin_interval_time,'mm/dd/yyyy hh24:mi') begin_interval_time,
TO_CHAR (p.end_interval_time,'mm/dd/yyyy hh24:mi') end_interval_time,
s.elapsed_time_delta / DECODE (s.executions_delta, 0, 1, s.executions_delta) / 1000000 elapsed_time_per_exec,
s.elapsed_time_delta / 1000000 elapsed_time,
s.executions_delta executions, s.buffer_gets_delta buffer_gets,
s.buffer_gets_delta / DECODE (s.executions_delta, 0, 1, s.executions_delta) buffer_gets_per_exec,
module module
FROM dba_hist_sqlstat s, dba_hist_snapshot p, dba_hist_sqltext x
WHERE p.snap_id = s.snap_id
AND p.dbid = s.dbid
AND p.instance_number = s.instance_number
AND p.begin_interval_time >
TO_TIMESTAMP ('&datef','yyyymmddhh24miss')
AND p.begin_interval_time <
TO_TIMESTAMP ('&datet','yyyymmddhh24miss')
AND s.dbid = x.dbid
AND s.sql_id = x.sql_id
ORDER BY instance_number, elapsed_time_per_exec DESC ;
SPOOL OFF;
exit; -
Extra characters at end of line in spool file
I am trying to generate csv files from SQL Developer using queries written to spool files. I have embedded the queries and associated set commands in script files and call them, as advised elsewhere. This gives csv files that look fine, with headings and data comma separated and enclosed with double quotes. The problem is that the files seem to contain a lot of extra characters at the end of each line. They seem to be spaces, but not sure. This is causing problems for the person trying to load the data.
I'm using version SQL Developer 3.1.07.42, Java 1.6.0_11.
Any ideas on how to avoid the extra spaces appearing? Thanks for any help.
Ben.Jeff,
The SQL in the script file is below. To be honest, I have reduced it down to a simple select from dual and it still puts extra spaces at the end of the single line.
col ord noprint
spool test.csv
SELECT ' ' ord,
'ZONE_ORDER_NUMBER'||','||
'ZONE_NAME'||','||
'ZONE_TYPE'||','||
'DESCRIPTION'||','||
'START_DATE'||','||
'END_DATE'
FROM dual
UNION ALL
SELECT zone_name ord,
'"'||zone_order_number||'"'||','||
'"'||zone_name||'"'||','||
'"'||zone_type||'"'||','||
'"'||description||'"'||','||
'"'||TO_CHAR(start_date,'DD-MON-YY')||'"'||','||
'"'||TO_CHAR(end_date,'DD-MON-YY')||'"'
FROM zones
ORDER BY ord;
spool off -
Need help for Scheduling a Spool file and FTP the file
I have one requirement like below...
1. Start Scheduling a job
2. Generate a Spool file (.csv file)
3. If Spool file generation is successful then start FTP the file
Else End job
4. After successful FTP process end the job.
We need to create a log file also for this job.
Can any body give some idea how will i proceed?
Thanks in advance.Billy Verreynne wrote:
BluShadow wrote:
Chris' may be wrapped, but it includes the funky ability to query remote files directly in SQL due to it's use of pipelined functions. A feature I've also got in my own FTP package and very useful for monitoring logs on remote servers through our Apex applications. ;)Ditto - also rolled my own FTP package as doing wildcard file listing requires custom support depending on the type of FTP server you're dealing with. The text part of the responses differ (these are not RFC'ed) and makes parsing more complex than what it could have been.Yeah, the differing responses can be a pain, though fortunately they are far and few between. There was a bug in Chris' package in that it wasn't handling a two code response from a windows FTP server for one of the commands, but I emailed him and he fixed that. Not his fault, he didn't have a windows FTP server to test on at the time.
FTP is a pretty straight forward protocol and easy to wrap a PL/SQL package around (using <i>UTL_TCP</i>).Absolutely. and the RFC details almost everthing you need to handle. It was quite quick to knock up a package, similar to the code hoek has linked to.
I think there is a lot of common stuff that many of us do in this regard. Always wondered how well a proper GPL'ed open source project providing a PL/SQL development framework and libraries would do...I think there'd be a lot of arguments about what is the best way of doing things. :D -
How to Use SPOOL Command with Bind Variables
For the Following SPOOL I want the GEN_DATE to be entered by the User at the time of execution of the SQL Script. Is it possible in SPOOL Command.
set colsep , -- separate columns with a comma
set pagesize 1000 -- get rid of disturbing ---- between pages
set heading on -- Print column heading
set trimspool on -- remove trailing blanks. eliminating the spaces up to eol
set linesize 700 -- line size should be the sum of the column widths
spool spool_results.csv
SELECT *
FROM GUI_SITE_JOURNAL
WHERE GENDATE_ BETWEEN '2012-11-01 00:00:00:00000' AND '2012-11-02 00:00:00:00000'* ORDER BY GEN_DATE;
spool off;
The reason is to give the ability to user so that he can enter any range without modifying the code of the script.
Can Any one help me please.
Edited by: user10903866 on Feb 18, 2013 7:44 PMHi,
user10903866 wrote:
For the Following SPOOL I want the GEN_DATE to be entered by the User at the time of execution of the SQL Script. Is it possible in SPOOL Command.Do you want the user input in the SPOOL command, or do you want it in the query?
set colsep , -- separate columns with a comma
set pagesize 1000 -- get rid of disturbing ---- between pages
set heading on -- Print column heading
set trimspool on -- remove trailing blanks. eliminating the spaces up to eol
set linesize 700 -- line size should be the sum of the column widths
spool spool_results.csv
SELECT *
FROM GUI_SITE_JOURNAL
WHERE GENDATE_ BETWEEN '2012-11-01 00:00:00:00000' AND '2012-11-02 00:00:00:00000'* ORDER BY GEN_DATE;What is the data type oif gen_date?
If it's a string, that's a big mistake. Information about dates belongs in DATE columns.
If it's a DATE, then don't try to compare it to strings, such as '2012-11-01 00:00:00:00000' .
spool off;
The reason is to give the ability to user so that he can enter any range without modifying the code of the script.
Can Any one help me please.One way to do that is with substitution variables:
SET VERIFY OFF
ACCEPT start_gen_date PROMPT "Starting date (e.g., 2013-02-18 23:00:00.00000): "
ACCEPT end_gen_date PROMPT "Ending date (e.g., 2013-02-18 23:59:59.99999): "
SPOOL spool_results.csv
SELECT *
FROM gui_site_journal
WHERE gen_date BETWEEN '&start_gen_date'
AND '&end_gen_date'
ORDER BY gen_date;
SPOOL OFFThere are security considerations. Substitution variables give devious users the power to issue any SQL command, such as DROP TABLE. Users that have SQL*Plus access already have that power, anyway. -
Hi,
i m able to successfully spool my file.problem is i m getting unwanted lines in my result
SQL FILE
set heading off
set pages 0
set echo off
set linesize 1000
spool TISSIP_TICKETTYPES_PURCHASES.csv
PROMPT TICKET TYPES,NO OF TICKETS
PROMPT 'Executive packages - Return ABC'
SELECT BOOKINGS.TT_CODE ||','||COUNT(*) "NO OF TICKETS" FROM BOOKINGS WHERE CREATE_DATE_TIME
BETWEEN TO_DATE('&&STARTDATE','DD/MM/YYYY') AND TO_DATE('&&ENDDATE','DD/MM/YYYY') AND PURCHASE_ORDER='WEB_SERVER_USER' AND TT_CODE IN ('ABC') AND BOOKINGS.CURRENT_BS_CODE='FIRM' GROUP BY BOOKINGS.TT_CODE
OUTPUT IN FILE
'Executive packages - Return ABC'
old 2: BETWEEN TO_DATE('&&STARTDATE' 'DD/MM/YYYY') AND TO_DATE('&&ENDDATE' 'DD/MM/YYYY') AND PURCHASE_ORDER='WEB_SERVER_USER' AND TT_CODE IN ('ABC') AND BOOKINGS.CURRENT_BS_CODE='FIRM' GROUP BY BOOKINGS.TT_CODE
new 2: BETWEEN TO_DATE('07/11/2005' 'DD/MM/YYYY') AND TO_DATE('08/12/2005' 'DD/MM/YYYY') AND PURCHASE_ORDER='WEB_SERVER_USER' AND TT_CODE IN ('ABC') AND BOOKINGS.CURRENT_BS_CODE='FIRM' GROUP BY BOOKINGS.TT_CODE
no rows selected
HOW DO I REMOVE THESE 2 LINES: -
old 2 and new 2???
Thank Youthanx a lot boss.that worked
Maybe you are looking for
-
RFC destination and logigal destination.`
If I am transfering the data uisng ALE, is RFC destination and logical system name of receiveing system should be same ?????? If the names of the both are different what will be the effect plz tell me ????
-
InDesign CC crashing when exporting file to idml
I am working on a large document (600+ pages). Whenever I export to idml InDesign crashes. It always crashes when the progress bar is at about 24%. I am able to export to PDF with no issues and also save as a new indd file with no issues. I am using
-
I have a number of older AVI files that I'm trying to convert over to MP4 so that I can not only play them on my computer, but on my HD TV as well. They are older, like I said and not in HD, but having the ability to show off my videos on the big sc
-
I lost my hard drive and had to have a new hard drive.. I did a back up and I have all of my pictures... but now... light room will not reinstall... what can I do? it just keeps coming up instll failed? any suggestions? Oh.. and this is a Mac not i
-
What is meant by characteristic values
hi what is meant by characteristic values i have seen some tables like AUSP, these r for characteristic values. can any one explain me that