Liquibase Update - Output SQL - Oracle Stored Procedures - sql

We have our stored procedures managed in code as Liquibase change log files (one change set/stored proc per file). These are marked to run every time we deploy. The format of the stored procedure SQL is as follows:
<createProcedure ...>
<![CDATA[
CREATE OR REPLACE MyStoredProc...
...
END;
]]>
</createProcedure>
When we run these change logs against a database everything works fine. However, when we use the updateSQL command to generate a SQL script from the change logs, Liquibase does NOT include the "/" batch separator at the end of each create or replace procedure block.
When I try adding the "/" to the stored proc code in Liquibase, it follows the create or replace statement and the "/" with another semi-colon (;). Either way, you cannot execute the batch script that Liquibase generates because these two issues generate errors.
If anyone has encountered this issue and has some guidance, please post here. This is a show-stopper for our implementation because some of our customers will not allow Liquibase to execute the change logs directly against their production instances. Thanks in advance.

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

Debugging SP on SSIS

I have a stored procedure that I execute through SSIS using an execute sql task. It appears to work on SISS, but when I look at the database the record is not created. The connection is for the correct database. The PROBLEM.
I have put a breakpoint ON and checked all the variables getting fed IN AND THEN ran it manually IN SQL SERVER management.
The SP work perfectly in SSMS with the same input parameters, but when executed through SSIS, it does not create the records required and does not give any error out.
In the SP I have a try catch to put any erorrs in the stored procedure when it erorr out to a table, but there is no entry for the SSIS run. According to the Error table for the SP and SSIS it looks like it executed successfully. When I go to see if the record it is not created. I cannot see the problem. Is there something I can put into the stored procedure to debug this problem or anything further I can do in SSIS to work this out ?
It has been 3 hours on this problem so looking for a fresh perspective to work out what is happening.
The SSIS package definitely points to the correct database and stored procedure.
From the watch window it appears to be giving all the parameters the correct values and does not error in SSIS.
Worked it out with sql profiler . In the Target database there is sequence that is incremented each time a new record needs to be created . When I deleted the record to rerun it it created it with a different ID number , I was expecting it to be created with the same ID number.
Thanks Billinkc !

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.

oracle - run stored procedure from script

I've a script that I am using to build/drop tables and basically setting up the entire schema.
After googling, I still can't figure out how to run a stored procedure.
The script is a .txt file, and I run it using Apex SQL Oracle.
If I write only this line in a script:
execute procedurename(1); --where 1 is paramter.
You have requested to run a script that does not contain any runnable
statements.
SQL>create or replace procedure procedurename(p_num number)
as
begin
null;
end;
/
Procedure created.
SQL>execute procedurename(1);
PL/SQL procedure successfully completed.
everything seems ok on SQLPLUS with oracle 11.
so it must be an apex thing.
Since execute is a sqlplus statement ,try calling the procedure using begin-end PLSQL block in Apex SQL
BEGIN
procedurename(1);
END;
/
save this in a file proc_call.sql and then call it in your script like
#C:\proc_call.sql
where C: is the sample path
For some information refer the below link
https://forums.oracle.com/forums/thread.jspa?threadID=618393

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.