1

I am using this script:

#!/bin/sh
for i in $(seq 1 20);
do
 echo "CREATE TABLE eugene_$i (id NUMBER NOT NULL);
 ! sleep 10
 DECLARE j NUMBER;
 BEGIN
  FOR j IN 1..20 LOOP
   select * from eugene_$i;
   ! sleep 10
  END LOOP;
 END;
 DROP TABLE eugene_$i;" | sqlplus system/password &
done
wait

My intent is to keep the connection alive, and run repetitive queries for testing.

The goal is wait 10 seconds after each select and call the next one.

I am not getting selects at all. I assume the inner for loop has some syntax problem.

1 Answer 1

2

When you issue a select statement (either as an implicit or explicit cursor) in PL/SQL, you need to fetch the values into a variable. You can return one row or bulk collect many rows into one or more variables (e.g. one scalar variable per column returned, or a record per row).

The PL/SQL inside your script should therefore look something like:

DECLARE
  -- no need to declare the j variable; that's implicit to the `FOR ... loop`
  id number; 
BEGIN
 FOR j IN 1..20 LOOP
  select *
  into   id
  from   eugene_$i;
  ! sleep 10 -- I'm not sure this will work in your script; it's not Oracle syntax, but may get translated by your script?
 END LOOP;
END;
/
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you, but it does not fully answer my requirements. Though it helped me realize how I need to approach it.

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.