trimspool ON is removing space from last column while spooling - oracle

I am spooling content of a table onto a flat file as pipe delimited with TRIMSPOOL ON Option. The default value of the last column is BLANK SPACE (' '). The trimspool is trimming this value and hence the value becomes NULL and hence validation is not succesful since this column is NOT NULL. Is there any way to solve this without altering the order of the columns.

Try SET TRIMOUT ON instead of SET TRIMSPOOL ON because it does not affect spooled output.The definition below
SET TRIMOUT ON
Determines whether SQL*Plus allows trailing blanks at the end of each
displayed line. ON removes blanks at the end of each line, which may
improve performance especially when you access SQL*Plus from a slow
communications device. TRIMOUT ON does not affect spooled output.
OR you can use NVL(col_last,' ') while loading the data

Related

whitespace trimming in the right side of my report issue

i am using sqlplus to generate report,i will spool the output of query in sqlplus screen and making report
now i want a report which having spaces
SELECT '123'||lapd(count(1),12,'0')||rpad(' ',10',' ') from dual;
i expect the report should spool as (im showing space as dot(.) to explain you)
123000000000009..........
but i got
123000000000009
i have lot of query like this...
i am using
set trimspool on
set termout off
set linespace 300
any idea?
SET TRIMSPOOL ON removes trailing blanks at the end of each displayed or spooled line.
If that's so, and you want to keep those blanks at the end of the result, why on Earth did you use that setting? Remove it!

Rows returned in blocks on SQLPlus (oracle client)

the following query works perfectly fine when used in Oracle SQL Developer:
SET ECHO OFF
SET FEEDBACK OFF
SET LINES 1000
SET LINESIZE 150
COLUMN URL FORMAT a54
SELECT DISTINCT RPAD (ROUTE.URL, 54) URL
FROM ROUTE
ORDER BY URL ASC;
But when issued in my SQLPlus, for some reason, the result rows are divided into 11-lines blocks:
URL
-------
url-1
url-2
url-3
...
url-11
URL
-------
url-12
url-13
url-14
...
url-22
etc..
Why does it happening? and how can I get the results in one block?
I use SQLPlus 11.2.0.3.0
You're already using set linesize - twice in fact, you set that to 1000, then immediately reduce to 150:
SET LINES 1000
SET LINESIZE 150
I suspect you might have expected the first setting to be the number of lines, rather than the length of each line, but they are the same setting - one is just a shortened version.
To set the number of lines in each block, or page, use the slightly-related set pagesize instead, e.g.:
SET PAGESIZE 1000
SET LINESIZE 150
The default value is 14, which means you get 11 lines of data, plus the header row, the row under that with dashes, and a blank line between pages.
If you set pagesize to zero then all results will be in a single 'page', however many lines of output you have; but that also suppresses the column headings.
Read more about setting page dimensions.

Why is SPOOL writing my output with LINESIZE set to 32767?

I am trying to spool certain data, but for some reason it gets wrapped to the next line.
This is the script I am using to SPOOL (I am adding the full script with comments in case it has any significance)
SET SERVEROUTPUT ON FORMAT WRAPPED SIZE UNLIMITED
SET LONG 2000000000
SET LINESIZE 32767
SET VERIFY OFF
SET FEEDBACK OFF
SET TERMOUT OFF
SET HEADING OFF
SET ECHO OFF
SET PAGESIZE 0
SET NEWPAGE NONE
SET TRIMSPOOL ON
/* -------------------------------------------------- COMMENT --------------------------------------------------
COMMENT1
COMMENT2
COMMENT3
COMMENT4
COMMENT5
*/
SPOOL "File_Name_MySYNONYM_SCRIPT-11111111.sql"
select SCRIPT FROM MY_TABLE_2_UPDATE where OBJECT_ID =11111;
SPOOL OFF
SCRIPT is a CLOB column and for the given ID contains:
CREATE OR REPLACE PUBLIC SYNONYM "MY_SYNONYM_12345" FOR "MS1"."MY_OBJECT1_SETUP";
This is the Output I get in the spooled file:
CREATE OR REPLACE PUBLIC SYNONYM "MY_SYNONYM_12345" FOR "MS1"."MY_OBJECT1_SETU
P";
You can see the P"; gets wrapped to the second line. The line is actually wrapped, it is not my editor (Notepad++) that is showing it wrong, I have "Word Wrap" deactivated.
I don't know what other SQL PLUS parameter I need to set to fix this issue.
Adding my comment as an answer as it seemed to help.
Try adding this after the SET command and before the SPOOL: "COLUMN SCRIPT FORM A3000". If sqlplus defaults the column SCRIPT to say 80 it will wrap.
However, reading further it seems you have other formatting issues, and also it seems the data is from DBMS_METADATA.GET_DLL.
I have written many tools (going back to v7) to extract DDL to scripts so that schemas can be rebuilt, and although DBMS_METADATA.GET_DDL is a huge help I still find it doesn't quite do the whole thing as neatly as you would like. So be warned. My scripts combine GET_DDL and some custom extract queries to get the nice clean usable scripts.
To remove extraneous line feeds, try this is your session:
exec DBMS_METADATA.SET_TRANSFORM_PARAM(DBMS_METADATA.SESSION_TRANSFORM,'PRETTY',false);
Documentation for this is here

how can I avoid white spaces in oracle query result?

I am spooling data from oracle to write it in csv file.. Its fetching blank spaces with result. Is there any way to avoid those blank spaces??
Use TRIMSPOOL
set trimspool on
SELECT RTRIM(columnname) AS columnname...

SQLPlus export to CSV (output format problem)

I'm facing an issue with an interface script, supposed to export the content of some table of an ORACLE database into CSV file, which is then followed by an import of those CSV into a MYSQL database.
STEP1: SQLPlus export to CSV
set headsep off
set heading off
set term off
set echo off
SET RECSEPCHAR \n
set pagesize 0
set linesize 0
trimspool on
SET FEEDBACK OFF
spool as_ex_feature.csv
select '"AS'||'"|"'||feature_group||'"|"'||feature_desc||'"|"
||feature_order||'"|"'||prod_code||'"'
from MYVIEW WHERE MYCONDITIONS;
spool off;
-> this step is generating the CSV file, but the format seems incorrect, as I can find some carriage return in the output.
Also you'll see in STEP2 that we define an "ENCLOSED BY" value how could I get that one included in the export format (doesn't seem to be the case right now).
STEP 2: MYSQL load
LOAD DATA INFILE 'mycsvfile' REPLACE INTO TABLE `mt_feature`
FIELDS TERMINATED BY '|'
ENCLOSED BY '"'
ESCAPED BY '\\'
LINES TERMINATED BY '\n';
This script had to be rebuilt for some technical reasons and the Mysql part had not been changed and is working fine with a proper CSV file to import.
The issue seem to be coming from that SQLPlus export, where I need to admit I don't have much knowledge on. Maybe I should use another method to get those files generated?
Please let me know if you need additional details, I feel blind...
Script running on oracle 10g, Linux, Mysql 4.x
Thanks!
SET LINESIZE 0 isn't valid, the value has to be between 1 and 32767. So I imagine it's wrapping the content at the default line length, which is 80 unless you've already got it set in a glogin script.
If you prefix any lines of code with (at least) four spaces in SO then it'll be formatted correctly, e.g.
select "AS'||'"|"'||
feature_group||'"|"'||
feature_desc||'"|"'||
feature_order||'"|"'||
prod_code||'"'
from MYVIEW
WHERE MYCONDITIONS;
Sounds like you may need to replace any embedded newline chars in the stored data....
SELECT "AS'||'"|"'||
TRANSLATE(feature_group, CHR(10), '\\n') ||'"|"'||
(etc).
And I'm not sure about setting the linesize to 0.

Resources