TOAD Set Pagesize > Run as Script - sql

If I run SQL in TOAD 11.0.0.116, and run it as a Script, it displays the output in the "Script Output" tab as raw text.
However, the display wraps after about 62 characters as you can see here:
I have messed about with setting the pagesize variable, to 0, and 200 and 2000 etc. but nothing makes any difference. Does anyone know if it is possible to prevent the text wrapping like this?
Thanks

Try using the set linesize command. I have here the Toad version 9.5 and it works:
set linesize 500;
instead of set pagesize

Related

How to execute Sql query from batch file

I'm new to batch files scripting.
All I want is creating a batch file that is calling SQL file and store results in CSV file .
Can anyone help me, your help is highly appreciated.
I am using Oracle database (version : oracle 11g)
Update:
Set cn = CreateObject("ADODB.Connection")
cn.ConnectionString = "Driver={Microsoft ODBC for Oracle};
CONNECTSTRING=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=<host>)(PORT=<port>))(CONNECT_DATA=(SERVICE_NAME=whipripa)));
uid=<uid>;pwd=<pswd>;"
While executing above query, it's not giving any errors, but still it's not connecting to Database either. Can someone tell me how to go ahead.
Here is a template of SQL Plus Script:
set colsep ,
set headsep off
set pagesize 0
set trimspool on
set linesize 2
set numwidth 5
spool books.csv
SELECT
title,
primary_author
FROM
books;
spool off
you’ll simply issue the sqlplus command from your shell:
sqlplus user/pwd#mydb #query.sql

How to have spool file display result of query? (Having trouble)

I am trying to export a .csv file (spool file) that has the result set of a very simple query that I am running in Oracle SQL Developer. The spool file generates; however, only the query is displayed (select * FROM TABLE) with no result set. What am i doing wrong? The command I am using is as follows:
spool "C:\Temp\test.csv"
select * from table;
spool off;
Thanks in advance
Use below commands to get the output of the query in spool file
SET SERVEROUTPUT ON
SET ECHO ON
After executing the select query don't forget to spool off.
So i did some more research / experimenting and i found that the following works:
I first created a sql file with the appropriate sql script /command and placed it in a directory (C:\TEMP). Then i ran the following command:
SET NEWPAGE 0
SET SPACE 0
SET PAGESIZE 0
SET FEEDBACK OFF
SET HEADING OFF
set verify off
SET ECHO OFF
spool "c:\Temp\test.csv"
#c:\Temp\test.sql as script(F5);
spool off
However now i run into a road block where oracle throws me an error saying that only 5,000 rows are currently supposed in script results...
Edit: I created the above code as a .sql file (test2.sql) and ran the below script. But am still encountering the 5000 row error:
SET NEWPAGE 0
SET SPACE 0
SET PAGESIZE 0
SET FEEDBACK OFF
SET HEADING OFF
set verify off
SET ECHO OFF
spool "c:\Temp\test2.csv"
#c:\Temp\test2.sql as script(F5);
spool off
The following worked when I tried to increase the limit: I went up to my sql developer tool bar ( tools > prefs > database > worksheet) and was able to change the maximum output limit.

Oracle Spool unable to display special characters

I am generateing a txt file using the below code. The code works fine, but there are issues with some characters. I am using Oracle.
Characters such as é, á etc. are unable to be displayed.
set echo off
set verify off
set termout on
set heading off
set pages 50000
set feedback off
set newpage none
set linesize 1000
set serveroutput off
set pagesize 0
set trimout on
set trimspool on
spool Weekly_Members_Vendors.txt
select ''||Unique_ID||''||Name||''||Alt_Name||''|| Entity_Type||''||Party_Type||''||Reference_#||''||Addr1||''||Addr2||''||
Addr3||''||Town||''||County||''||Postcode||''||Country||''||ALT_ADDRESS1||''||ALT_ADDRESS2||''||
ALT_ADDRESS3||''||ALT_TOWN||''||ALT_COUNTY||''||ALT_POST_CODE||''||ALT_COUNTRY||''||NATIONALITY||''||
DOB||''||INDIVIDUAL_ID||''||INDIVIDUAL_ID_TYPE||''||COUNTRY_OF_REGISTRATION||''||COMPANY_ID||''||COMPANY_ID_TYPE||''||
SOURCE_COUNTRY||''||SOURCE_SYSTEM||''||TRANSACTION_TYPE
from dbo.Temp_Weekly_Export_File;
spool off;
exit
I assume you run this in SQL*Plus on Windows.
In this case, check code page of command line windows by chcp
Usually it should be CP437 or CP850 (depending if you are in Europe or US).
Then before you start SQL*Plus set your NLS_LANG value accordingly, either as Environment Variable (e.g. set NLS_LANG=WE8PC850)
or
in Registry (HKLM\SOFTWARE\Wow6432Node\ORACLE\KEY_%ORACLE_HOME_NAME%\NLS_LANG for 32-bit, resp. HKLM\SOFTWARE\ORACLE\KEY_%ORACLE_HOME_NAME%\NLS_LANG for 64-bit)
You can also change the code page of command line window, e.g. chcp 1252
See also these answers:
Unicode characters in Windows command line - how?
OdbcConnection returning Chinese Characters as "?"

which set command to display entire line in sql output to txt file

I am trying to output a query result to a txt file in Windows. The query is being executed in Oracle. I want to export the entire record one by one but gets cut off at the end, the query however displays the full line.
I thought the command:
SET linesize 2000 will do the trick but no luck:
Getting:
2702M11F13-XL 38550116-06 Test 3 325 http://www.test.com/clot
Should get (what shows in query output):
2702M11F13-XL 38550116-06 Text 3 325 http://www.test.com/clothing/outerwear/coats/test/hybridge-lite-vest/p/38550116 CAD
Please help.
Thanks in advance
It should be possible using set colsep
Refer to the Oracle Sql*Plus documentation for set colsep
Note that there's also set tab {on/off} which is used to convert tabs to spaces

Clear Screen in SQL*Plus

I'm running the following report but getting an error
/* Simple table formatting */
clear screen;
accept Report_File char prompt 'Enter a file name for summary report ';
/*Set up column headers*/
col StoreCode format A8 heading 'Store Code';
col DESCRIPTION format A8 heading 'Item Description';
col PRICE format $999999.99 heading 'Price';
col QUANTITY format 999 heading 'Quantity';
col (Price*Quantity) format $999999.99 heading 'Value';
/*Format and title pages */
set Pause off;
set Feedback off;
set Space 6;
set newpage 2;
set pagesize 54;
set linesize 200;
set underline =;
title center 'Current Stock Value by Store' skip 2 left -
'prepared by Jason Kemeys' &Report_Officer right -
&Todays_Date skip4;
btitle center format 999 SQL.PNO;
/* Set breaks and computes */
break on StoreCode skip 2 on SuppCode skip 1 on Report;
compute sum of (Price*Quantity) on StoreCode;
compute sum of (Price*Quantity) on Report;
/*Select data & send to file*/
spool &Report_File;
select StoreCode, Description, Quantity, Price, (Price*Quantity)
from Stocks
order by StoreCode;
spool off;
/* Clear all settings */
clear breaks;
clear columns;
clear computes;
set Pause on;
Just need to know why its showing the error and how to get it running; first time doing a report in SQL.
This is the error I'm getting
clear screen;
* ERROR at line 2: ORA-00900: invalid SQL statement
cl scr is the command used to clear screen in SQL.
I suspect this is dependent on the version of Oracle you are using.
This should work in version 11.2 but to quote from the 10g documentation:
CLEAR SCREEN is not available in SQL*Plus.
The same note isn't there in the 11.1 documentation, which would imply that you're using Oracle 10g or earlier. If this supposition is true then there's little that you can do.
It's possible that you can utilise the host command in SQL*Plus to run cls, if you're using Windows, or clear, if you're using Linux, but I'm not certain that it would have exactly the same effect. If it were possible it would simply be:
host cls
host runs an operating system command from SQL*Plus, and so will appear to clear the screen.
simply use cl scr command to clear the SQL plus.
Very few occurances of ";" in your code is actually needed. For example, the "clear screen" command to start with, doesn't need a semicolon. It will work, when you add one, but I wouldn't be sure about all the subsequent commands in that same file. Commands that need them, are limited to INSERT, UPDATE, DELETE, COMMIT, ROLLBACK, and such.
Secondly, if you get weird feedback from SQL-files, and if you have written them outside of Linux/Unix, this often ends up in SQLPLUS complaining about invisible characters. Look at that file via both VI and CAT commands, and note anything weird.