DBMS_OUTPUT.PUT_LINE and DBMS_OUTPUT.GET_LINE using Liquibase - oracle

i am begginer in Liquibase
i need to add DBMS_OUTPUT.PUT_LINE and DBMS_OUTPUT.GET_LINE in SQL Formatted Liquibase Script not in .xml, .JSON, .YAML formats
is there any way we can use those statements
Below is the code i am using but getting invalid SQL statement
--liquibase formatted sql
--changeset pratap:2
DROP TABLE cat.testdbms;
DBMS_OUTPUT.PUT_LINE ( 'Test Line1' );
Any one can help me on this
Thanks

I think the issue is that liquibase runs SQL using a JDBC connection, and can only run basic SQL. I think that DBMS_OUTPUT is a procedure in a package. This syntax might work if run using SQL*Plus, but not when run through a JDBC statement. It might be possible to do this if you used the call statement:
--liquibase formatted sql
--changeset pratap:2
DROP TABLE cat.testdbms;
call (DBMS_OUTPUT.PUT_LINE ( 'Test Line1' ));
or something like that.

Related

Dynamically logging PLSql statements in a table

I have bunch of plsql which has dynamic queries ( ie queries are framed as string and executed with immediate execute function). I want to find the dependent tables and columns for a plsql. I am planning to achieve by GSQL parser. I tried the plsql file as it is, because of dynamic queries, I am not able to get the dependency information. The alternate way is collecting the list of SQL statements executed during the plsql run. How to get sql statement for a plsql and store it a table with unit name mapping ?
Hi you need execute the sql you have saved with execute immediate;
you will get all sql in below oracle view
select * from v$sql;
select * from dba_hist_sqltext;

Jetbrains Datagrip / PHPStorm how to execute an oracle Procedure?

I'm trying both softwares using thin client (jdbc). My database is oracle (v9 and v11g). The problem is that I can't find a way to execute a procedure. I have try:
execute schema.package.procedure('lorem', :a); -- Like TOAD
execute schema.package.procedure('lorem');
execute package.procedure('lorem');
execute package.procedure('lorem', :a); -- Also Like TOAD
Nothing works. Always the same message:
[2016-01-04 12:40:12] [42000][900] ORA-00900: invalid SQL statement
DataGrip allows to execute stored procedure without parameters in current schema like this:
call some_proc();
Here is how to call proc with params from other schema:
call schema.package.procedure('params');

Executing SQLLDR from within a PL-SQL procedure

Hello and thanks in advance. I am running Oracle 11gR2 and want to try to execute an sql loader to insert data into an existing table. I am attempting this via Java stored proc in the database that will perform commands on the OS. The problem I am having is that I cannot seem to get the call to invoke SQLLDR.EXE to work - error I have is: sqlldr not found (NOTE that lookup with PATH isnt done due to the Oracle executable being SETUID)
----------------------Sample Code------------------------------------------
declare
l_ldr varchar2(1000) := '/u01/app/oracle/product/db/11.2.0.4/bin/sqlldr.exe control=C:\ad\controlfile.ctl, log=load.log, bad=load.bad,data=C:\somefile.txt';
l_env varchar2(1000) := 'PATH=/bin:/u01/oracle/db/11.2.0.4/jdk/bin;';
l_out varchar2(5000);
l_ret varchar2(5000);
begin
dbms_output.put_line(l_ldr);
MSO_Java.dbcmd('sqlldr.exe',
l_ldr,
l_env,
'Y',
l_out,
l_ret);
dbms_output.put_line(l_ret);
dbms_output.put_line(l_out);
end;
--------------------------END CODE SAMPLE--------------------
Appreciate ANY help here. I know this can be done.....
SQLLDR doesn't have the option to be executed in a PL/SQL, but you can simulate a SQLLDR with PL/SQL.
Yeap this is posible, I created a stored procedure that works fine just with REGEXP, now the documentation is in spanish but as soon that I can I will translate this.
Here is the link
Performence? Yeah I now that simulate a SQLLDR will be affect the performance in the database but NO, is this the reason that I used REGEXP. That works fine for me loading masive data.
Another thing is that this PL/SQL gives you the opportunity to transform the data. You can use a ETL for that but sometimes that is not possible :(.
THAT IS EASY TO UNDERSTAND :D!

Weblogic JDBC Connections: multi-statement init SQL

When setting up a data source in WLS we can give it an init SQL statement, which is executed immediately after creation of every connection for this data source.
So far we are using..
SQL ALTER SESSION SET current_schema=user01
.. as we are logging in using an application user02 which has less rights than the owner user01, but we still want the data source to see the schema.
Now we'd like to add some session meta information to the DS connections, for debugging purposes on the DB side. The statements..
DBMS_APPLICATION_INFO.set_client_info('bar');
DBMS_APPLICATION_INFO.set_module('qux', 'garp');
.. allow you to set custom strings as identifiers, which will then show up in colums of V_$SESSION, thus giving the DBA some more information about a DB connection.
My problem
How is it possible to have multi-line init SQL statements? Note that the init SQL syntax expects an SQL command which is preceded by SQL and which does not end in a semicolon ;.
Edit:
What I tried so far is something along the lines of..
begin
execute immediate 'ALTER SESSION SET current_schema=uzms01';
DBMS_APPLICATION_INFO.set_client_info('bar');
DBMS_APPLICATION_INFO.set_module('qux', 'garp');
end;
.. but I keep getting errors. :(
Looks like there was a small syntax irregularity which I did not spot because SQL developer executes it without problems...
The following snippet works (note the parentheses after immediate):
SQL BEGIN
execute immediate('alter session set current_schema=user01');
DBMS_APPLICATION_INFO.set_client_info('my client');
DBMS_APPLICATION_INFO.set_module('my module', 'my action');
END;

Truncating a table in a stored procedure

When I run the following in an Oracle shell it works fine
truncate table table_name
But when I try to put it in a stored procedure
CREATE OR REPLACE PROCEDURE test IS
BEGIN
truncate table table_name;
END test;
/
it fails with
ERROR line 3, col 14, ending_line 3, ending_col 18, Found 'table', Expecting: # ROW or ( or . or ; :=
Why?
All DDL statements in Oracle PL/SQL should use Execute Immediate before the statement. Hence you should use:
execute immediate 'truncate table schema.tablename';
As well as execute immediate you can also use
DBMS_UTILITY.EXEC_DDL_STATEMENT('TRUNCATE TABLE tablename;');
The statement fails because the stored proc is executing DDL and some instances of DDL could invalidate the stored proc. By using the execute immediate or exec_ddl approaches the DDL is implemented through unparsed code.
When doing this you neeed to look out for the fact that DDL issues an implicit commit both before and after execution.
try the below code
execute immediate 'truncate table tablename' ;
You should know that it is not possible to directly run a DDL statement like you do for DML from a PL/SQL block because PL/SQL does not support late binding directly it only support compile time binding which is fine for DML. hence to overcome this type of problem oracle has provided a dynamic SQL approach which can be used to execute the DDL statements.The dynamic sql approach is about parsing and binding of sql string at the runtime.
Also you should rememder that DDL statements are by default auto commit hence you should be careful about any of the DDL statement using the dynamic SQL approach incase if you have some DML (which needs to be commited explicitly using TCL) before executing the DDL in the stored proc/function.
You can use any of the following dynamic sql approach to execute a DDL statement from a pl/sql block.
1) Execute immediate
2) DBMS_SQL package
3) DBMS_UTILITY.EXEC_DDL_STATEMENT (parse_string IN VARCHAR2);
Hope this answers your question with explanation.

Resources