if(从表中选择列,其中column =:var_input from table)?不会工作:(

时间:2018-12-11 22:53:21

标签: oracle if-statement plsql

很抱歉,但是我不知道应该如何使用pl / SQL的if,end语句

这是我希望它能解释我想要做什么的代码

DECLARE 

        S1 NUMBER(2) := :ID;
        S2 VARCHAR2(32) := :USERNAME;
        S3 VARCHAR(32)  := :PASSWORD;
        X  VARCHAR2(300);
        BEGIN

        INSERT INTO TEST1 (ID,USERNAME,PASSWORD)
        VALUES (S1,S2,S3);
      COMMIT;

    IF((SELECT USERNAME FROM TEST1 WHERE USERNAME = S2) =S2 )
        THEN
        X:= SHOW_ALERT('ALERT12');
         IF (X=ALERT_BUTTON1)
             THEN EXIT_FORM;
         END IF;
    END IF;  

    END;

1 个答案:

答案 0 :(得分:1)

您可以使用此:

DECLARE 

    S1 NUMBER(2) := :ID;
    S2 VARCHAR2(32) := :USERNAME;
    S3 VARCHAR(32)  := :PASSWORD;
    X  VARCHAR2(300);
    v_count number;

    BEGIN

    INSERT INTO TEST1 (ID,USERNAME,PASSWORD)
    VALUES (S1,S2,S3);
  COMMIT;
 SELECT Count(*) into v_count FROM TEST1 WHERE USERNAME = S2;
IF(v_count = 1 )
    THEN
    X:= SHOW_ALERT('ALERT12');
     IF (X=ALERT_BUTTON1)
         THEN EXIT_FORM;
     END IF;
END IF;  

END;