来自 Oracle apex 中 PLSQL 的警报消息

Alert message from PLSQL in Oracle apex

我想在满足特定条件时显示来自 PLSQL 的警报消息。但是它不起作用。

请检查我在单击复选框时在动态操作中编写的 PLSQL 代码。

declare
var_hire DATE ;
tenure_dt DATE;
i number;
TENURE EXCEPTION;
BEGIN
SELECT HIREDATE INTO var_hire from employee where empno=107;
-- APEX_APPLICATION.G_F01(1);
SELECT var_hire+ INTERVAL '1' YEAR INTO  tenure_dt FROM DUAL;
 IF SYSDATE < to_Date(tenure_dt,'DD-MON-YY') THEN

 /* APEX_ERROR.ADD_ERROR (
p_message  => 'The employee cannot be deleted',
p_display_location => apex_error.c_inline_in_notification );*/
apex_application.g_global_notification( 'The employee cannot be deleted');
END IF ;
END  ;

declare
var_hire DATE ;
tenure_dt DATE;
i number;
TENURE EXCEPTION;
BEGIN
SELECT HIREDATE INTO var_hire from employee where empno=107;
-- APEX_APPLICATION.G_F01(1);
SELECT var_hire+ INTERVAL '1' YEAR INTO  tenure_dt FROM DUAL;


    APEX_ERROR.ADD_ERROR (
    p_message  => 'The employee cannot be deleted',
    p_display_location => apex_error.c_inline_in_notification );
    


EXCEPTION
WHEN TENURE THEN 
RAISE_APPLICATION_ERROR(-20000,'CANNOT BE DELETED');
END  ;

您可以使用 PL/SQL 代码创建一个 Ajax callback process。例如,将 Ajax 回调过程创建为 MyQuery

declare
var_hire DATE ;
tenure_dt DATE;
i number;
TENURE EXCEPTION;
BEGIN
    SELECT HIREDATE INTO var_hire from employee where empno=107;
    SELECT var_hire+ INTERVAL '1' YEAR INTO  tenure_dt FROM DUAL;
         IF SYSDATE < to_Date(tenure_dt,'DD-MON-YY') THEN
            HTP.P('The employee cannot be deleted');    
         END IF ;
END  ;

然后在您的复选框上创建一个动态操作('执行 javascript 代码)javascript code

apex.server.process('MyQuery', { },
   {
      dataType: "text",
      success: function(pData) {
         if (pData != "") {
            apex.message.alert(pData);
         }
      }
  });