PL/SQL - 在 API 调用中引用查询结果
PL/SQL - Referencing Query Results in API Calls
我有以下查询:
SELECT DISTINCT purchase_authorizer_api.get_userid('30', pagl.authorize_id)
FROM purch_authorize_group_line pagl join purchase_authorizer pa
ON pagl.authorize_id = pa.authorize_id
WHERE pagl.authorize_group_id = '30-QA-NUC'
AND pa.notify_user = 'TRUE';
这为我提供了该授权组中 PO 授权者的用户 ID。我可以有几个 PO 授权人。我需要能够给他们所有人发电子邮件。
我正在尝试在我们的 ERP 系统中创建一个事件操作,它会在发布 PO 时运行执行以下操作:
BEGIN
command_sys.mail(from_user_name_ => 'IFSAPP',
to_user_name_ => 'youremail@yourdomain.com',
subject_ => 'Test subject',
text_ => 'Test message body');
COMMIT;
END;
我可以在 to_user_name 部分输入多个用户 ID,但我很难弄清楚如何在 to_user_name 部分获得此查询的结果?
编辑:我仍在尝试这个,但我无法让它工作:
CREATE PROCEDURE a_proc
AS
cursor get_emails is
SELECT DISTINCT purchase_authorizer_api.get_userid('30', pagl.authorize_id) AS "EMAIL"
FROM purch_authorize_group_line pagl join purchase_authorizer pa
ON pagl.authorize_id = pa.authorize_id
WHERE pagl.authorize_group_id = '30-PM-COM'
AND pa.notify_user = 'TRUE';
result_ VARCHAR2(500);
BEGIN
OPEN get_emails;
FETCH get_emails BULK COLLECT INTO vi_emails;
CLOSE get_emails;
FOR indx IN 1..vi_emails.COUNT LOOP
command_sys.mail(from_user_name_ => 'IFSAPP',
to_user_name_ => result_,
subject_ => 'Test subject',
text_ => 'Test message body');
END LOOP;
END a_proc;
编辑 2:
我已经更新到:
CREATE OR REPLACE PROCEDURE a_proc
is vi_get_emails varchar2(500);
cursor get_emails is
SELECT DISTINCT purchase_authorizer_api.get_userid('30', pagl.authorize_id) AS "EMAIL"
FROM purch_authorize_group_line pagl join purchase_authorizer pa
ON pagl.authorize_id = pa.authorize_id
WHERE pagl.authorize_group_id = '30-PM-COM'
AND pa.notify_user = 'TRUE';
BEGIN
OPEN get_emails;
FETCH get_emails INTO vi_get_emails;
CLOSE get_emails;
FOR rec_ IN get_emails LOOP
command_sys.mail(from_user_name_ => 'IFSAPP',
to_user_name_ => vi_get_emails,
subject_ => 'Test subject',
text_ => 'Test message body');
END LOOP;
END a_proc;
正在编译,没有错误。但是,没有电子邮件发送给用户。
SELECT
LISTAGG(EMAIL,',') WITHIN GROUP(ORDER BY EMAIL) AS LIST
FROM
(
SELECT
'abc@abc.com' AS EMAIL
FROM
DUAL
UNION
SELECT
'xyz@abc.com' AS EMAIL
FROM
DUAL
UNION
SELECT
'def@abc.com' AS EMAIL
FROM
DUAL
UNION
SELECT
'ddd@abc.com' AS EMAIL
FROM
DUAL
UNION
SELECT
'fff@abc.com' AS EMAIL
FROM
DUAL
UNION
SELECT
'ggg@abc.com' AS EMAIL
FROM
DUAL
);
Output -
LIST
abc@abc.com,ddd@abc.com,def@abc.com,fff@abc.com,ggg@abc.com,xyz@abc.com
您可以将此查询的结果存储到一个变量中并将其作为参数传递。
希望这对你有用。
我有以下查询:
SELECT DISTINCT purchase_authorizer_api.get_userid('30', pagl.authorize_id)
FROM purch_authorize_group_line pagl join purchase_authorizer pa
ON pagl.authorize_id = pa.authorize_id
WHERE pagl.authorize_group_id = '30-QA-NUC'
AND pa.notify_user = 'TRUE';
这为我提供了该授权组中 PO 授权者的用户 ID。我可以有几个 PO 授权人。我需要能够给他们所有人发电子邮件。
我正在尝试在我们的 ERP 系统中创建一个事件操作,它会在发布 PO 时运行执行以下操作:
BEGIN
command_sys.mail(from_user_name_ => 'IFSAPP',
to_user_name_ => 'youremail@yourdomain.com',
subject_ => 'Test subject',
text_ => 'Test message body');
COMMIT;
END;
我可以在 to_user_name 部分输入多个用户 ID,但我很难弄清楚如何在 to_user_name 部分获得此查询的结果?
编辑:我仍在尝试这个,但我无法让它工作:
CREATE PROCEDURE a_proc
AS
cursor get_emails is
SELECT DISTINCT purchase_authorizer_api.get_userid('30', pagl.authorize_id) AS "EMAIL"
FROM purch_authorize_group_line pagl join purchase_authorizer pa
ON pagl.authorize_id = pa.authorize_id
WHERE pagl.authorize_group_id = '30-PM-COM'
AND pa.notify_user = 'TRUE';
result_ VARCHAR2(500);
BEGIN
OPEN get_emails;
FETCH get_emails BULK COLLECT INTO vi_emails;
CLOSE get_emails;
FOR indx IN 1..vi_emails.COUNT LOOP
command_sys.mail(from_user_name_ => 'IFSAPP',
to_user_name_ => result_,
subject_ => 'Test subject',
text_ => 'Test message body');
END LOOP;
END a_proc;
编辑 2:
我已经更新到:
CREATE OR REPLACE PROCEDURE a_proc
is vi_get_emails varchar2(500);
cursor get_emails is
SELECT DISTINCT purchase_authorizer_api.get_userid('30', pagl.authorize_id) AS "EMAIL"
FROM purch_authorize_group_line pagl join purchase_authorizer pa
ON pagl.authorize_id = pa.authorize_id
WHERE pagl.authorize_group_id = '30-PM-COM'
AND pa.notify_user = 'TRUE';
BEGIN
OPEN get_emails;
FETCH get_emails INTO vi_get_emails;
CLOSE get_emails;
FOR rec_ IN get_emails LOOP
command_sys.mail(from_user_name_ => 'IFSAPP',
to_user_name_ => vi_get_emails,
subject_ => 'Test subject',
text_ => 'Test message body');
END LOOP;
END a_proc;
正在编译,没有错误。但是,没有电子邮件发送给用户。
SELECT
LISTAGG(EMAIL,',') WITHIN GROUP(ORDER BY EMAIL) AS LIST
FROM
(
SELECT
'abc@abc.com' AS EMAIL
FROM
DUAL
UNION
SELECT
'xyz@abc.com' AS EMAIL
FROM
DUAL
UNION
SELECT
'def@abc.com' AS EMAIL
FROM
DUAL
UNION
SELECT
'ddd@abc.com' AS EMAIL
FROM
DUAL
UNION
SELECT
'fff@abc.com' AS EMAIL
FROM
DUAL
UNION
SELECT
'ggg@abc.com' AS EMAIL
FROM
DUAL
);
Output -
LIST
abc@abc.com,ddd@abc.com,def@abc.com,fff@abc.com,ggg@abc.com,xyz@abc.com
您可以将此查询的结果存储到一个变量中并将其作为参数传递。
希望这对你有用。