4

I am trying to write a simple cursor and run it inside the command line Oracle client on Unix, SQL Plus. I have mostly been using single line statements and can't find a way to execute a multi line statement once I am done writing it. Can anybody help?

Here is my code:

DECLARE 
   TYPE array_t IS varray(4) OF varchar2(10); 
   ARRAY array_t := array_t('foo', 'bar', 'stack', 'overflow');
BEGIN 
   FOR i IN 1..array.count loop
       dbms_output.put_line(array(i)); 
   END loop; 
END; 

Thanks

1 Answer 1

13

To execute a PL/SQL block in SQL*PLUS, add slash at the end of the PL/SQL block:

SQL> DECLARE
  2     TYPE array_t IS varray(4) OF varchar2(10);
  3     ARRAY array_t := array_t('foo', 'bar', 'stack', 'overflow');
  4  BEGIN
  5     FOR i IN 1..array.count loop
  6         dbms_output.put_line(array(i));
  7     END loop;
  8  END;
  9  /
Sign up to request clarification or add additional context in comments.

3 Comments

what is the difference between that and just typing . ? both seem to do the same thing
Period(.) terminates PL/SQL mode but does not run a PL/SQL block whereas run command or slash / do.
Also found that the / most definitely has to be on it's own line.

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.