Oracle - 为变量选择一个值并在下一个select语句中使用它

时间:2014-11-26 15:07:32

标签: oracle oracle10g oracle-sqldeveloper

您好每一个我都想尝试选择一个变量中的值并在下一个选择语句中使用它但它不起作用任何人都可以帮助我PLZ ...是否可以这样做?

我正在使用带有Toad的oracle 10.5

variable  v_NextID int;
begin
begin
  SELECT NOTE_ID INTO  v_NextID FROM  (
      SELECT NOTE_ID,row_number() OVER (ORDER BY NOTE_ID ASC ) AS row_num
       FROM tableName WHERE ID ='838'
       ) t
     WHERE row_num = 2;

end;

       select v_NextID, ID from tableName  WHERE ID ='838';
end

1 个答案:

答案 0 :(得分:0)

declare
  v_NextID number;

begin
  SELECT NOTE_ID INTO  v_NextID FROM  (
      SELECT NOTE_ID,row_number() OVER (ORDER BY NOTE_ID ASC ) AS row_num
       FROM tableName WHERE ID ='838'
       ) t
     WHERE row_num = 2;

     select v_NextID, ID 
       into ... -- here you need to add INTO clause
     from tableName  WHERE ID ='838';
end;