Saturday, June 19, 2010

Debugging PLSQL code from java - Is that possible?

Yes it is possible.
There are some packages are available for read/write package in oracle. UTL_ FILE package is used for this purpose. Using this package we can read and write OS text files via PL/SQL.
To make use of this functionality, Please do the following

1. Login as sys to DB
2. Need to create DIRECTORY in Oracle i.e. under which folder your log file will be created.
e.g.: CREATE OR REPLACE DIRECTORY DBDIR AS 'c:\plsqllog\';
3. Grant read access to the user (from where you are going to execute the procedure)
e.g: Grant read on directory dbdir to mtx5;
4. Plug in the below code in the PL/SQL Code and add debug statement wherever it is needed .
- - Declare Section in PLSQL: Declare file handler
fileHandler UTL_FILE.FILE_TYPE;
- - Body Section in PLSQL
- - Open a file for input or output with the default line size.
fileHandler := utl_file.fopen('DBDIR','NEWFILE.TXT','W');
- - DBDIR is the directory, NEWFILE.TXT is the file name, W - write mode
- - below line is debugging statement. You can put the below debug statement wherever is required.
utl_file.put_line(f1,'1. This is a test of UTL_FILE packages');
- - finally close the handler
utl_file.fclose(f1);
If you execute the PLSQL through java, debug statements will be logged. Please find attached sample PLSQL for your reference.
Hope this will be useful to everybody!!!!!!!!!

No comments: