PL/SQL <<word>> 的含义是什么?

10

PL/SQL中双尖括号括起来的单词<<word>>是什么意思?

我已经尝试过谷歌搜索,但谷歌会跳过标点符号。

它有什么用途?


2
查找“PL/SQL双尖括号”。 - Benoit
1
本文应该为您提供关于块标记及其用途的良好基础:http://www.devshed.com/c/a/Oracle/Database-Interaction-with-PLSQL-Nested-Blocks-in-Depth/1/ 希望对您有所帮助... - Ollie
1
<<>> 是标签分隔符,因此在 <<foo>> 中,foo 是一个标签。请查阅 Oracle 文档以了解更多信息:PL/SQL 语言基础PL/SQL 控制语句 - user272735
2个回答

5
作为评论者所提到的,它用于标记复合语句,并且作为GOTO的目标。您可以在END和END LOOP中使用标签,这对可读性非常有帮助,例如:<<倒计时>> for i in 1.9 loop blah; end loop 倒计时; 以下是示例:
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;
/

输出结果为:

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

0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接