0

I have PL/SQL scripts and I was asked to make them run automatically using shell scripts. The problem is that I have no idea on how to do that, so please if there is any way to help me do that I will be thankful.

I tried to take the basics but it's far away from what I need:

output="$(sqlplus -S user/pw@//ip:1521/db <<ENDOFSQL
set serveroutput on;
DECLARE
    v_return PLS_INTEGER;
BEGIN

    DBMS_OUTPUT.PUT_LINE(v_return);
END;
exit;
ENDOFSQL)"

echo $output 
1
  • 1
    You need a / after the end; (on a new line). But apart from that I have no idea what you are asking Commented Feb 5, 2015 at 14:07

2 Answers 2

3

You can do it like this:

sqlplus -S user/pw@//ip:1521/db <<ENDOFSQL
set serveroutput on;
DECLARE
    v_return PLS_INTEGER;
BEGIN

    DBMS_OUTPUT.PUT_LINE('Hello World');
END;
.
/

ENDOFSQL

There is no need to capture the output in the variable if all you're going to do is echo the output afterwards.

Sign up to request clarification or add additional context in comments.

2 Comments

The question was: how to run a PL/SQL block directly from shell. He does not mention anything about scheduling - at least I don't see anything in his code.
Exactly what I want.
2

I was asked to make them run automatically using shell scripts

At first place, why do you worry about automation of the script at database level. You could simply schedule it as a cron job at the OS level.

You could also schedule it at database level using DBMS_SCHEDULER or DBMS_JOB, whichever is applicable to your database version.

4 Comments

i'm forced to do it with shell script but i didn't know how to start
@Achref, just follow my answer. Is there anything else concerning you?
@LalitKumarB is there any tutorial that i can have
Tim Hall has some good stuff here oracle-base.com/articles/linux/cron-on-linux.php

Your Answer

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.