2017-02-16 33 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;