Executing a multi line statement in SQL Plus on Unix

10,731

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  /
Share:
10,731

Related videos on Youtube

amphibient
Author by

amphibient

Software Engineer with table manners

Updated on July 11, 2022

Comments

  • amphibient
    amphibient almost 2 years

    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

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