Firebird multiple statements - sql

is there any way to execute multiple statements (none of which will have to return anything) on Firebird? Like importing a SQL file and executing it.
I've been looking for a while and couldn't find anything for this.

Execute block is exactly for that purpose. Works in IBExpert too, a simple example :
execute block as
begin
Update stuff;
Delete stuff;
Update stuff;
end
Comprehensive guide, with temporary variables and cycles into it:
EXECUTE BLOCK

You can do it from IBExpert with Script Executive (MenĂº Tools -> Script Executive). Be sure to connect to the DB you want to run the query's and then at the Script Executive dialog check the "Use current connection" for this to work.

In IBExpert you can execute multiple commands in single script via Tools->Script Executive (Ctrl+F12)

Shouldn't the normal query-delimiter work? Like:
Update stuff; Delete stuff; Update stuff;

You can do this with IBOConsole (download from www.mengoni.it). The SQL window allows you to enter a complete script with the usual ";" delimiter.

Related

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

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:

Delete command in SQLPLUS

I am aware of only truncate command in sqlplus,
connect myuser/mypassword#myserver
truncate table mytable;
EXIT;
/
Wondering if there is a delete command, I read about DEL but not sure how to use it appropriately, please advice if there is something to use like the below in sqlplus if any,
delete from mytable where emp_id in (1,5);
Answer to your question is yes.
In fact, what you have written is a perfectly valid delete command.
See http://www.techonthenet.com/oracle/delete.php for a simple tutorial and guide. Not just Oracle, but all SQL databases support it. It is part of the SQL language itself.

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;

SQL Server - SKIP DML statements from a given SQL Script file

I have a huge sql server script which has mix of ddl, dml operations and there is a requirement to create a clean db structure (with no data). Is it possible for a transaction to skip DML scripts through some parameter or some other way.
Thanks in Advance.
Arun
Out of the box: no. But you can wrap the DML statements in your script with something like:
if ($(RUNDML) = 1)
begin
--your dml here
end
Where RUNDML is a sqlcmd variable. You'd invoke your script with differing values of RUNDML based on whether or not you wanted data in the database being built.
Alternatively, separate the DML out into another script (or scripts) so you can choose whether to run the data portion of the build or not.

How to run sql scripts from a pl sql procedure

I have a procedure like :
CREATE OR REPLACE PROCEDURE test is
BEGIN
DBMS_OUTPUT.PUT_LINE('This is a Test');
END;
I want to run some sql scripts stored in the current directory.
I could run them from sqlplus with '#scriptname.sql' but how can i do it from inside the procedure ? For ex:
CREATE OR REPLACE PROCEDURE test is
BEGIN
DBMS_OUTPUT.PUT_LINE('This is a Test');
#scriptname.sql
END;
This doesn't seem to work ! Is there a specific to run sql scripts from pl/sql procedures ?
You can't, in general, because the pl/sql is run in the database, on the server, and sqlplus is a client process. The server can't rely on even being on the same system as the client and its files, much less knowing anything about how to find the file the client is referring to. Even if the syntax were supported (and it isn't), your sql script would have to be on the server, in a location the server knew about and had access to.
Actually, you can do this in SQL*Plus - you just need to ensure the # is the first character on the line, e.g.:
CREATE OR REPLACE PROCEDURE test is
BEGIN
DBMS_OUTPUT.PUT_LINE('This is a Test');
#scriptname.sql
END;
SQL*Plus will read the entire contents of the script and insert it at that point in the procedure, then create the procedure as it is given. That means you can't have SQL*Plus commands in scriptname.sql. Also, there won't be any reference to #scriptname.sql in the actual procedure created on the database.
You could execute an OS command to start SQLPlus and have that execute the scripts. You can pass a filename into SQLplus at start up and it will execute it.
Google External Procedures and extproc or this article. Or something like call OS command with Java
You could write a Java Stored Procedure to open the file and return its contents as a String and then call Execute Immediate on the String.
Be VERY CAREFUL doing this though as any malicious sql in those files can do pretty much whatever it wants.
Even if there should be a solution, I would not recommend to to this. A PL/SQL procedure basically is a SQL script. Either
1. run your SQL scripts from outside the database, e.g. via shell script or
2. move the SQL code inside your procedure.