oracle 创建一个共享页面,用于在填充注解文本后将记录(基于记录的表)更新为已删除

brvekthn  于 2023-06-05  发布在  Oracle
关注(0)|答案(1)|浏览(128)

我正在使用Oracle APEX 22.1,我有一些表,如TBLCASETBLCASE_CLASSES,...。.它们都具有列ISDELETEDDELETE_TIMEDELETE_USERDELETE_NOTE。我想要的是:
当用户在任何报告页面中单击删除时,会显示一个对话框页面,在此对话框中,我希望为每个表显示不同的文本,并在确认之前显示用户必须输入的注解文本字段(:P32_NOTE)。
除了id项(:P32_ID)之外,我还添加了一个保存表名的项(:P32_TABLE)和一个保存文本的项(:P32_DISPLAY)。他们都来自链接,所以没有问题。
我使用了if else based on:P32_TABLE项。

BEGIN
    IF :P32_TABLE = 'TBLCASE' THEN
        UPDATE TBLCASE SET ISDELETED = 1, DELETE_TIME = LOCALTIMESTAMP, DELETE_USER = :APP_USER, DELETE_NOTE = :P32_NOTE:
        WHERE ID = :P32_ID;
    ELSIF :P32_TABLE = 'TBLCASECALSS' THEN
        UPDATE TBLCASECLASS SET ISDELETED = 1, DELETE_TIME = LOCALTIMESTAMP, DELETE_USER = :APP_USER, DELETE_NOTE = :P32_NOTE:
        WHERE ID = :P32_ID;
    ELSIF :P32_TABLE = 'TBLCASEDOCUMENT' THEN
        UPDATE TBLCASEDOCUMENT SET ISDELETED = 1, DELETE_TIME = LOCALTIMESTAMP, DELETE_USER = :APP_USER, DELETE_NOTE = :P32_NOTE:
        WHERE ID = :P32_ID;
    ELSIF :P32_TABLE = 'TBLCASEEND' THEN
        UPDATE TBLCASEEND SET ISDELETED = 1, DELETE_TIME = LOCALTIMESTAMP, DELETE_USER = :APP_USER, DELETE_NOTE = :P32_NOTE:
        WHERE ID = :P32_ID;
    END IF;
END;

但只有在:P32_TABLE = TBLCASE工作的情况下。有什么问题吗

vmpqdwk3

vmpqdwk31#

我认为问题是因为你在比较中拼错了表的名称。如果你使用像execute immediate这样的动态方法会更好。我将向您展示如何:
首先,创建一个数据库PROCEDURE以执行update命令。

create or replace PROCEDURE DELETE_OPERATION
  ( 
    P_ID      number , 
    P_TABLE  VARCHAR2, 
    P_USER    VARCHAR2 , 
    P_NOTES VARCHAR2 )
AS
v_cmd VARCHAR2;
BEGIN
    v_cmd := 'UPDATE ' || P_TABLE || ' SET ISDELETED = 1, DELETE_TIME = LOCALTIMESTAMP, DELETE_USER = :1, DELETE_NOTE = :2;'
    || ' WHERE ID = ' TO_CHAR(P_ID);

    execute immediate v_cmd USING P_USER, P_NOTES ;
END;

然后替换此代码。

BEGIN
    IF :P32_TABLE = 'TBLCASE' THEN
        UPDATE TBLCASE SET ISDELETED = 1, DELETE_TIME = LOCALTIMESTAMP, DELETE_USER = :APP_USER, DELETE_NOTE = :P32_NOTE:
        WHERE ID = :P32_ID;
    ELSIF :P32_TABLE = 'TBLCASECALSS' THEN
        UPDATE TBLCASECLASS SET ISDELETED = 1, DELETE_TIME = LOCALTIMESTAMP, DELETE_USER = :APP_USER, DELETE_NOTE = :P32_NOTE:
        WHERE ID = :P32_ID;
    ELSIF :P32_TABLE = 'TBLCASEDOCUMENT' THEN
        UPDATE TBLCASEDOCUMENT SET ISDELETED = 1, DELETE_TIME = LOCALTIMESTAMP, DELETE_USER = :APP_USER, DELETE_NOTE = :P32_NOTE:
        WHERE ID = :P32_ID;
    ELSIF :P32_TABLE = 'TBLCASEEND' THEN
        UPDATE TBLCASEEND SET ISDELETED = 1, DELETE_TIME = LOCALTIMESTAMP, DELETE_USER = :APP_USER, DELETE_NOTE = :P32_NOTE:
        WHERE ID = :P32_ID;
    END IF;
END;

用这个:

BEGIN
    DELETE_OPERATION(:P32_ID, :P32_TABLE, :APP_USER, :P32_NOTE);
END;

相关问题