Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PL/SQL What's the meaning of <<word>>

Tags:

oracle

plsql

What is the meaning of a word in double angled brackets in PL/SQL, eg. <<word>>?

I've tried to do a google search but google skips the punctuation.

What is it used for?

like image 450
Revious Avatar asked Jan 30 '12 11:01

Revious


1 Answers

As mentioned by the question commenters, this is used to label compound statements and also as a target for GOTO. You can use to use the label in the END and END LOOP which can be great for readability, like <<countdown>> for i in 1.9 loop blah; end loop countdown;

Here is an example:

set echo on
set serveroutput on

<<begin_end_block>> 
declare 
  msg varchar2(1000);
begin
  dbms_output.enable;
  msg := chr(9) || 'start';
  <<loopblk>> 
  for itr8 in 1 .. 5
  loop
    msg := msg || chr(10) || chr (9) ||  'loop';
    dbms_output.put_line ('Iterator is ' || itr8);
    <<ifblck>> if itr8 > 2
    then
      msg := msg || chr(10) || chr(9) || 'greater than 2';
      goto gototarg;
    end if;
    exit loopblk when mod (itr8, 4) = 0;
    continue loopblk;
    <<gototarg>>
    dbms_output.put_line ('after goto target');
  end loop loopblk;
  dbms_output.put_line ('Ending, here are the messages' || chr(10) || msg);
end begin_end_block;
/

output is:

anonymous block completed
Iterator is 1
Iterator is 2
Iterator is 3
after goto target
Iterator is 4
after goto target
Iterator is 5
after goto target
Ending, here are the messages
    start
    loop
    loop
    loop
    greater than 2
    loop
    greater than 2
    loop
    greater than 2
like image 130
Andrew Wolfe Avatar answered Nov 16 '22 01:11

Andrew Wolfe