SQL Developer将不会插入数据

问题描述 投票:1回答:1
create or replace PROCEDURE ADD_TO_BLACKLIST(
P_EMPLOYEE_USERNAME IN VARCHAR2,
T_CURSOR OUT SYS_REFCURSOR
)
AS 
BEGIN
DECLARE E_COUNT PLS_INTEGER := 0;
BEGIN
    SELECT COUNT(*) INTO E_COUNT FROM EXAMPLE_TABLE WHERE UPPER(EMPLOYEE_USERNAME) LIKE UPPER(P_EMPLOYEE_USERNAME)||'%';
    IF E_COUNT = 0 THEN
        INSERT INTO EXAMPLE_TABLE 
            (employee_number, employee_username) 
            SELECT EMPLOYEE_NUMBER, EMAIL FROM EXAMPLE_VIEW WHERE UPPER(EMAIL)=CONCAT(UPPER(P_EMPLOYEE_USERNAME), '@microsoft.com');
    ELSE
        UPDATE EXAMPLE_TABLE SET (EMPLOYEE_NUMBER, EMPLOYEE_USERNAME) = (SELECT EMPLOYEE_NUMBER, EMAIL FROM EXAMPLE_VIEW WHERE UPPER(EMAIL)=CONCAT(UPPER(P_EMPLOYEE_USERNAME), '@microsoft.com'));
        COMMIT;
    END IF;
    OPEN T_CURSOR For
        SELECT * FROM EXAMPLE_VIEW WHERE EMAIL LIKE CONCAT(UPPER(P_EMPLOYEE_USERNAME), '%');
END;
END ADD_TO_BLACKLIST;

这会编译,但是当我尝试使用有效的P_EMPLOYEE_USERNAME(已确认在EXAMPLE_VIEW中进行测试)时,我看不到正在插入任何数据。

我是PLSQL的新手,不确定如何计算E_COUNT的值

Example_Table DDL为

CREATE TABLE "Example_Table"
(   "EMPLOYEE_NUMBER" NUMBER NOT NULL ENABLE, 
    "EMPLOYEE_USERNAME" VARCHAR2(250 BYTE) NOT NULL ENABLE, 
    "ACCOUNT_STATUS" NUMBER DEFAULT 0, 
    "ACCOUNT_STATUS_LAST_UPDATE" TIMESTAMP (6) DEFAULT SYSDATE NOT NULL ENABLE, 
     CONSTRAINT "BOE_SAFEGAURD_PK" PRIMARY KEY ("EMPLOYEE_USERNAME"))
oracle plsql plsqldeveloper
1个回答
0
投票

您只需要在IF-ELSE条件之后提交即可,而不是在其中提交。我已经更新了您的代码以及其他一些小更新-

© www.soinside.com 2019 - 2024. All rights reserved.