2017-02-16 94 views
0

这是代码如何在oracle中打印三次特定的select语句?

declare 
a integer; 
begin 
    select to_char(to_date('1/1/2017 ','mm/dd/yyyy') + level -1) into a from dual 
    connect by level <=365; 
    for a in 1..3 loop 
    dbms_output.put_line(a); 
    end loop; 
end; 

错误发生时准确取指令要求更没有行 的请帮忙

回答

0

您正试图获得在缩放变量多值。

试试这个:

begin 
    for i in (select to_char(to_date('1/1/2017 ','mm/dd/yyyy') + level -1) col 
        from dual 
        connect by level <=365) loop 
     for j in 1..3 loop 
      dbms_output.put_line(i.col); 
     end loop; 
    end loop; 
end; 
/
+0

感谢洙非常..上帝保佑你 – Abhijith

0

所有的第一次,请注意有关您宣布“一个”变量为整数,但随后你指定一个VARCHAR2给它的事实。 2,我正在测试你的代码,看起来level <= 365有问题。 我将它改为level = 365,它似乎返回了预期的结果。

declare 
a integer; 
begin 
    select to_char(to_date('1/1/2017 ','mm/dd/yyyy') + level -1) into a from dual 
    -- connect by level <= 365; 
    connect by level = 365; 
    for a in 1..3 loop 
    dbms_output.put_line(a); 
    end loop; 
end;