0

I have set of tables and need to execute select query based on different users. Table names are stored in file and I am looking forward to write a script to execute a script to read table name from the file and execute select query as specific user. Need to validate if the query was successful or failure.

Any suggestion on the tools for Oracle database / scripting(python or java) to be used for automation.

Thanks in advance.

asked Jun 2, 2014 at 6:00
2
  • What did you try yourself? Why or what didn't (it) work? Commented Jun 2, 2014 at 8:53
  • I have written a java program to read the table names from a file and execute the select query against with specific users from another file. If select statement fails, it would log error and continue with others. Commented Jun 3, 2014 at 0:58

1 Answer 1

0

It looks like you need to write dynamic SQL. Dynamic SQL is SQL the creates SQL that can get run. Here is a simple example of dynamic SQL.

SELECT 'ALTER ' ||
 CASE object_type 
 WHEN 'PACKAGE BODY' THEN 'PACKAGE '
 WHEN 'TYPE BODY' THEN 'TYPE '
 ELSE object_type ||' '
 END || owner ||'.' || object_name ||' '||
 CASE object_type 
 WHEN 'PACKAGE BODY' THEN 'COMPILE BODY;'
 WHEN 'TYPE BODY' THEN 'COMPILE BODY;'
 ELSE 'COMPILE;'
 END text
 FROM dba_objects
 WHERE status = 'INVALID'
 ORDER BY 1;

You should also have formatting in the SQL to keep the output of the SQL as clean as possible.

SET TERM OFF
COLUMN text FORMAT A150
SET ECHO OFF
SET TRIMSPOOL ON
SET TAB OFF
SET FEEDBACK OFF
SET PAGESIZE 0
SET LINESIZE 150
SET TIMING OFF
SET TERM ON

Then you just need to write the SQL that generates SQL, if you need to connect as a different user you can include a line like:

SELECT 'CONNECT user1/cdjkfghljsdg@sidname' text from dual;

But you need to figure out how to write the SQL, since you have not given many details. You will spool to a file, then turn on feedback, set pagesize 50 or so, probably set timing on etc, then run the output of the spool file. You may want to spool to a log file during the run phase. There are alot of examples, you just need to query for an example that matches what you want to do.

answered Jun 2, 2014 at 13:35

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.