Oracle Apex:PL/SQL 块中的 Javascript 代码
Oracle Apex: Javascript code in PL/SQL Block
是否可以在 PL/SQL 块中包含 JavaScript 代码。
我想在 oracle Apex 页面进程中提交时执行包含 JavaScript 代码的 pl/sql 块。
DECLARE
v_count NUMBER;
BEGIN
select count(*) into v_count
from summary
where prd_items = 'Total';
HTP.p ('<script type="text/javascript">');
HTP.p ( 'alert(''The value of Total for BU is ' ||v_count|| '.\n'
|| 'You have to enter correct values to proceed further \n'');');
HTP.p ('</script>');
END;
我的页面区域中有 Submit
按钮,这个 pl/sql 块是页面处理项并在页面提交时执行 (Conditional:Submit
)。
但是我无法弹出警告框。请指教
谢谢。
要从 pl/sql 程序嵌入 javascript 代码,您必须将程序放在 "Before Header" 点。但我认为这不是您要实现的目标的最佳解决方案。
你想做的是添加验证吗?如果是这样,为什么不使用顶点验证。使用如下选项创建验证:
- 识别验证level:Page项
- 确定要验证的页面项目:Select 您想要的项目。
- Select 验证类型:PL/SQL
- 选择您希望的验证类型create:Function返回错误文本
- 验证码:
DECLARE v_count NUMBER;
V_validation_msg VARCHAR2(500);
BEGIN
SELECT prd_items INTO v_count FROM summary WHERE prd_items = 'Total';
V_validation_msg:='The value of Total for BU is ' ||v_count|| '.\n' || 'You have to enter correct values to proceed further';
IF 1= 1 THEN --add some condition here if you want
RETURN V_validation_msg;
ELSE
RETURN NULL;
END IF;
END;
- 按下按钮时:您的提交按钮。
Is it possible to have JavaScript code in the PL/SQL block?
- 是
但是,如果您将执行点更改为 AFTER HEADER,您正在尝试执行的操作将无法正常工作,即传递 javascript 函数 AFTER SUBMIT.It 只会起作用。
或者,如果您只想验证输入的值而不想使用顶点验证,您可以使用 APEX_ERROR package.Try 这个。
DECLARE
v_count NUMBER;
BEGIN
select prd_items into v_count
from summary
where prd_items = 'Total';
-- I dont really know what you want to
--accomplish with this query but Im pretty sure
--It will not return a number
-- if you want to count the number of prd_items it should be like this
--select COUNT(*)
--into v_count
--from summary
--where prd_items = 'Total';
APEX_ERROR.ADD_ERROR(
p_message => 'The value of Total for BU is '||v_count||'.<br>'||
'You have to enter correct values to proceed further',
p_display_location => apex_error.c_inline_in_notification
);
END;
编辑:如果你想在计数不等于 100 时显示错误,请执行以下操作:
DECLARE
v_count NUMBER;
BEGIN
Select COUNT(*)
into v_count
from summary
where prd_items = 'Total';
IF v_count != 100 THEN
APEX_ERROR.ADD_ERROR(
p_message => 'The value of Total for BU is '||v_count||'.<br>'||
'You have to enter correct values to proceed further',
p_display_location => apex_error.c_inline_in_notification
);
END IF;
END;
是否可以在 PL/SQL 块中包含 JavaScript 代码。 我想在 oracle Apex 页面进程中提交时执行包含 JavaScript 代码的 pl/sql 块。
DECLARE
v_count NUMBER;
BEGIN
select count(*) into v_count
from summary
where prd_items = 'Total';
HTP.p ('<script type="text/javascript">');
HTP.p ( 'alert(''The value of Total for BU is ' ||v_count|| '.\n'
|| 'You have to enter correct values to proceed further \n'');');
HTP.p ('</script>');
END;
我的页面区域中有 Submit
按钮,这个 pl/sql 块是页面处理项并在页面提交时执行 (Conditional:Submit
)。
但是我无法弹出警告框。请指教
谢谢。
要从 pl/sql 程序嵌入 javascript 代码,您必须将程序放在 "Before Header" 点。但我认为这不是您要实现的目标的最佳解决方案。
你想做的是添加验证吗?如果是这样,为什么不使用顶点验证。使用如下选项创建验证:
- 识别验证level:Page项
- 确定要验证的页面项目:Select 您想要的项目。
- Select 验证类型:PL/SQL
- 选择您希望的验证类型create:Function返回错误文本
- 验证码:
DECLARE v_count NUMBER; V_validation_msg VARCHAR2(500); BEGIN SELECT prd_items INTO v_count FROM summary WHERE prd_items = 'Total'; V_validation_msg:='The value of Total for BU is ' ||v_count|| '.\n' || 'You have to enter correct values to proceed further'; IF 1= 1 THEN --add some condition here if you want RETURN V_validation_msg; ELSE RETURN NULL; END IF; END;
- 按下按钮时:您的提交按钮。
Is it possible to have JavaScript code in the PL/SQL block?
- 是
但是,如果您将执行点更改为 AFTER HEADER,您正在尝试执行的操作将无法正常工作,即传递 javascript 函数 AFTER SUBMIT.It 只会起作用。
或者,如果您只想验证输入的值而不想使用顶点验证,您可以使用 APEX_ERROR package.Try 这个。
DECLARE
v_count NUMBER;
BEGIN
select prd_items into v_count
from summary
where prd_items = 'Total';
-- I dont really know what you want to
--accomplish with this query but Im pretty sure
--It will not return a number
-- if you want to count the number of prd_items it should be like this
--select COUNT(*)
--into v_count
--from summary
--where prd_items = 'Total';
APEX_ERROR.ADD_ERROR(
p_message => 'The value of Total for BU is '||v_count||'.<br>'||
'You have to enter correct values to proceed further',
p_display_location => apex_error.c_inline_in_notification
);
END;
编辑:如果你想在计数不等于 100 时显示错误,请执行以下操作:
DECLARE
v_count NUMBER;
BEGIN
Select COUNT(*)
into v_count
from summary
where prd_items = 'Total';
IF v_count != 100 THEN
APEX_ERROR.ADD_ERROR(
p_message => 'The value of Total for BU is '||v_count||'.<br>'||
'You have to enter correct values to proceed further',
p_display_location => apex_error.c_inline_in_notification
);
END IF;
END;