Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Executing a multi line statement in SQL Plus on Unix

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

like image 916
amphibient Avatar asked Dec 15 '22 18:12

amphibient


1 Answers

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  /
like image 63
Nick Krasnov Avatar answered Dec 28 '22 08:12

Nick Krasnov