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.
Related
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:
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
I have a really strange problem on my SQL Server.
Every night 2 tables, that I have recently created, are being automatically truncated...
I am quite sure, that it is truncate, as my ON DELETE Trigger does not log any delete transactions.
Additionally, using some logging procedures, I found out, that this happens between 01:50 and 01:52 at night. So I checked the scheduled Jobs on the server and did not find anything.
I have this problem only on our production server. That is why it is very critical. On the cloned test server everything works fine.
I have checked transaction log entries (fn_dblog), but didnt find any truncate logs there.
I would appreciate any help or hints that will help me to find out process/job/user who truncates the table.
Thanks
From personal experience of this, as a first step I would look to determine whether this is occurring due to a DROP statement or a TRUNCATE statement.
To provide a possible answer, using SSMS, right click the DB name in Object Explorer, mouse over Reports >> Standard Reports and click Schema Changes History.
This will open up a simple report with the object name and type columns. Find the name of the table(s), click the + sign to expand, and it will provide you history of what has happened at the object level for that table.
If you find the DROP statement in there, then at least you know what you are hunting for, likewise if there is no DROP statement, you are likely looking for a TRUNCATE.
Check with below query,
declare #var as varchar(max)='tblname'
EXEC sp_depends #objname =#var;
it will return number of stored procedure name which are using your table and try search for any truncate query if you have wrote by mistake.
Thanks a lot to everyone who has helped!
I've found out the reason of truncating. It was an external application.
So if you experience the same problem, my hint is to check your applications that could access the data.
I don't know if can help you to resolve the question.
I often encounter the following situations.
Look at this example:
declare #t varchar(5)
set #t='123456'
select #t as output
output:12345
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;
I need to access variables in whole script that is divided to few sections by GO command. How to do that?
Below is source example (that doesn't work):
--script info (begining of script file)
DECLARE #ScriptCode NVARCHAR (20) = '20120330-01'
--some queries
GO
--and there I cannot use #ScriptCode variable
INSERT INTO DBScriptsHistory(ScriptCode) VALUES(#ScriptCode)
That's correct, because variables exist only within the current batch. Assuming that you need to use the GO statement (e.g. CREATE VIEW must be the first statement in a batch), the simplest solution is probably to use sqlcmd scripting variables.
The GO statement is a batch separator for the different SQL client tools - it is not part of SQL.
Each batch is separate from the other - just remove the GO statement.
See GO (Tranasct-SQL):
The scope of local (user-defined) variables is limited to a batch, and cannot be referenced after a GO command.
Remove the GO keyword, it will work. Once you have called GO, the variable is no longer in scope.