1

I have one script script.sql which I want to execute from command line using oracle and passing it two parameters, as shown below

sqlplus user/pass @ script.sql my_parameter1_value my_parameter2_value

What should it be in script.sql in order to be able to run it with the parameter values?

2 Answers 2

1

The solution can be prepared looking at oracle blogs:

https://blogs.oracle.com/opal/sqlplus-101-substitution-variables#2_7

For the question above, the solution would be to create a script.sql like this:

DEFINE START_VALUE = &1;
DEFINE STOP_VALUE = &2;

SELECT * FROM my_table
WHERE
 value BETWEN &&START_VALUE AND &&STOP_VALUE;

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

2 Comments

"... looking at oracle blocks." What are these blocks? I'd like to look at them too.
@Littlefoot I wanted to refer to oracle blogs. I already fixed it.
0

I wanted to run a script that would return all orders raised during the last seven days. Here's how...

the script

SELECT * FROM orders_detail WHERE order_date BETWEEN '&1' AND '&2';
EXIT;

the command

sqlplus ot/Orcl1234@xepdb1 @"/opt/oracle/oradata/Custom Scripts/orders_between_dates.sql" $(date +%d-%b-%Y -d '-7 days') $(date +%d-%b-%Y)

Hope that helps someone. Luck.

Comments

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.