如何将游标结果作为过程中的参数传递

时间:2018-03-26 09:18:07

标签: plsql cursor

我有一个返回2行的游标:

$(document).ready(function(){
  $(document).on("click","#team",function(){
    $("input[name='lead_check[]'").val($(this).val());
  });
  $("#team").trigger("click"); //For setting first time value on page load.
});

现在我想将这些值传递给一个过程(**标记下面的参数)。

Attach name         Attach MIME type
----------          ---------------
abc.pdf             application/pdf
xyz.pdf             application/pdf

我该怎么做?

2 个答案:

答案 0 :(得分:1)

如果有游标,那么应该有一个循环,你可以使用该游标返回的值。像这样:

begin
  for cur in (select attach_name, attach_type from some_table)
  loop
    send_smtp_mail
     (p_to          => 'xyx@xyz.com',
      p_from        => 'xyx@xyz.com',
      p_subject     => 'TEst',
      p_text_msg    => NULL,
      p_attach_name => cur.attach_name,         --> this
      p_attach_mime => cur.attach_mime_type     --> and this
    );
  end loop;
end;

答案 1 :(得分:0)

如果您可以更改send_smtp_mail功能,则可以将光标作为参数传递(将参数p_attach_namep_attach_mime替换为p_attachment_cursor):

CREATE OR REPLACE PROCEDURE send_smtp_mail(..., p_attachment_cursor IN SYS_REFCURSOR)
AS
  attach_name ...
  attach_mime ...
BEGIN
LOOP
FETCH p_attachment_cursor INTO attach_name, attach_mime ...
EXIT WHEN p_attachment_cursor%NOTFOUND;

-- process data as needed
END LOOP;

CLOSE p_cursor;
END;
/