ORA-00922: Missing or Invalid option for SET FEEDBACK OFF in TOAD - sql

I am using TOAD application to execute my query which you can see below:
SET FEEDBACK OFF;
SELECT * FROM TABLENAME
-- and then rest of the queries
I used SET FEEDBACK OFF in Toad app (by Quest Software) as an alternative to SET NOCOUNT ON in SQL, but it shows error and says:
ORA-00922: Missing or Invalid option
Is there any alternative to SET NOCOUNT ON that we write in SQL for Oracle?

SET set of commands - in Oracle - was originally related to its command-line tool named SQL*Plus. It (the SET) works in some other tools, such as Oracle's GUI - SQL Developer.
Mathguy showed me that TOAD recognizes quite a lot SQL*Plus commands (I thought it does not); it is the way you run code in TOAD:
if you run it as a separate command, it won't work:
on the other hand, if you run it as a script, then it works, and the result is displayed in its "Script output" tab:

Related

Oracle SQL Developer - how to view listing of OLAP script instead of executing?

In Oracle SQL Developer, my database connection is to an Oracle server at uni, where my database is hosted.
The code I have to run a marking script, to assess my stored procedures for an assignment, is:
SET SERVEROUTPUT ON;
Clear screen ;
EXECUTE johnSmith.mark_ass1;
show errors;
I want to see inside johnSmith.mark_ass1 instead of just executing it.
This script is insisting that my stored procs are wrong, I'd like to know why as I'm quite sure this is not the case (at least according to the assignment specs I was given)
Thanks in advance

Flyway getting rid of my comments - SQL Server 2012

I have a very simple procedure with comments. Example:
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE test
AS
BEGIN
-- Single line comment
SET NOCOUNT ON;
SELECT GETDATE();
END
GO
The script is saved as encoded UTF-8.
When I migrate this with flyway (successfully) and later check it through the management studio, I see that the multi-line comment is stripped off. Also when viewing the flyway migrated procedure SSMS complains about 'Inconsistent Line Endings'. What am I missing here?
Glad that moving the comment down helped you - as for your 2nd problem:
why i am getting "Inconsistent ending lines" warning window while executing sql script?
Quintessence: find what corrupts it and fix it ;o)
Manually
If you have notepad++ you can clean your scripts by opening them, then Edit/EOL Conversion/ and choose what EOLs you want
kindof automatic
see Windows command to convert Unix line endings?
--> be careful with the MORE thing, it kills your file if you use it inplace (inputfile=outputfile)

Write Output of DBMS.OUTPUT.put_line To Specified Common Location Like Desktop

I have a long series of calls like:
DBMS_OUTPUT.put_line(v_1||','||v_2);
I have only read priveleges to the database and invision writing the ouptut from the statement above to a common location on all computers that I might read from later (using VBA).
I've found UTL_FILE packages that Oracle seems to support but I am having trouble understanding how to get it to do what I want.
Could someone provide me with a simple example of how I could use the put_line method and UTL_FILE packsage in tandem to write to a common location such as the desktop of a computer?
Spooling is a SQL*Plus feature one can perform on your desktop without invoking the UTL_FILE database package. Toad (utilizing the SQL*Plus feature) can do this as well.
As Justin Cave commented, UTL_FILE is an Oracle database package intended for reading and writing to the database server (e.g. 11g documentation http://docs.oracle.com/cd/B28359_01/appdev.111/b28419/u_file.htm#BABGGEDF).
Spooling is documented here for SQL*Plus (associated with the Oracle 11g database http://docs.oracle.com/cd/E11882_01/server.112/e27507/sqlplus.htm#DFSUG144 section 3.1.7).
You could select 'Run as a script' in TOAD as follows:
set serveroutput on
spool c:\temp.lst
begin
dbms_output.put_line('My text');
end;
/
spool off
Spooling is a client side feature (SQL*Plus), thus if one wanted to have invocations to dbms_output within a procedure (below, I call it my_procedure), I would just create a sql script that drives the procedure.
One could make this the contents of a sql script (e.g. test_dbms_output.sql):
SET serveroutput ON
spool c:\temp.lst
BEGIN
my_procedure(params);
END;
/
spool OFF
Then, one just can invoke this script with the SQL*Plus run command (or 'Run as a script' in Toad):
#test_dbms_output.sql;
or
run test_dbms_output.sql;

set serveroutput ON permanently?

I am new in oracle and doing practice for the PL/SQL. I have one question i.e. :
how to set serveroutput ON permanently in oracle. Is their any way that we use to set it permanently ON?
If you are refering to SQL*Plus you should set this in your glogin.sql file.
You can find this file in ORACLE_HOME\sqlplus\admin.
As far as I know there is no way of setting server output ON permanently.
But if this question is connected to fact that for every new session in SQL developer, 1 needs to execute SET SERVEROUTPUT ON statement in beginning for seeing PL/SQL code result, then solution is Go to view->DBMS_Output
Then below you will see dbms output window. There is a plus(+) button there. Click and add schema on which you are working currently. Then PL/SQL script output can be seen there.

Ignoring SQLPLUS commands in JDBC

I have a .sql file that contains below statements:
SET LINESIZE 2000
WHENEVER SQLERROR EXIT 1 ROLLBACK
WHENEVER OSERROR EXIT 1 ROLLBACK
SET PAGESIZE 0
SET HEADING ON
SET FEEDBACK OFF
SET VERIFY OFF
INSERT INTO TABLE_A
--get some value from TABLE B that will be added in Table A....
COMMIT;
EXIT;
When I run this SQL in my SQL Editor (TOAD/SQL Navigator etc.) , it works fine. I see some messages though when SQLNavigator execute this command:
SQL*Plus command ignored.
Processing ...
WHENEVER SQLERROR EXIT 1 ROLLBACK
SQL*Plus command ignored.
Processing ...
WHENEVER OSERROR EXIT 1 ROLLBACK
SQL*Plus command ignored.
Processing ...
SET PAGESIZE 0
When I run this SQL through JDBC, i get an exception:
Caused by: java.sql.SQLException: ORA-00922: missing or invalid option
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:331)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:288)
at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:743)
at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:216)
at oracle.jdbc.driver.T4CPreparedStatement.executeForRows(T4CPreparedStatement.java:955)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1168)
at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3285)
at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:3368)
I'm assuming this error is because JDBC is not able to understand SQLPlus statements and failing. Is there a way I can tell JDBC to ignore those statements and just run the main SQL? Or to resolve this I just need to modify the SQL file by removing the SQLPlus statements?
You'll need to remove the SQL*Plus commands from the file.
JDBC is intended to be a database-agnostic interface so it is designed to work the same with a variety of different database engines. SQL*Plus commands are designed to work just with SQL*Plus connecting to an Oracle database (though other tools that support Oracle databases will often support a subset of SQL*Plus commands as well). It wouldn't make sense for JDBC to know about what constitutes a SQL*Plus command so it has no way to figure out what is a SQL*Plus command or to filter them out.
Beyond that, simply removing the SQL*Plus commands will change the semantics of the script. The WHENEVER SQLERROR and WHENEVER OSEROR commands instruct SQL*Plus to issue a rollback in the event of an error (which it sounds like your script generates). You'd need to code that logic into your JDBC application if you want to match the behavior.
When you run these statements through TOAD, etc. they usually parse the text either by a delimiter (e.g. semi-column) or by line feed and run the statements separately. However, when you send the whole text to JDBC, it's probably trying to run it all at once, hence the error. You may have to parse the statements and separate them properly before sending to JDBC.