[PL/SQL]CASE文とNULL文のサンプル

2021年8月25日

書式
CASE 条件式
WHEN xxx
ELSE NULL;

使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
CREATE OR REPLACE PROCEDURE SCOREPROC (
SCORE CHAR
) AUTHID DEFINER AS
BEGIN
CASE SCORE
WHEN 'A' THEN DBMS_OUTPUT.PUT_LINE('優秀');
WHEN 'B' THEN DBMS_OUTPUT.PUT_LINE('上等');
WHEN 'C' THEN DBMS_OUTPUT.PUT_LINE('良い');
WHEN 'D' THEN DBMS_OUTPUT.PUT_LINE('普通');
WHEN 'F' THEN DBMS_OUTPUT.PUT_LINE('下手');
ELSE NULL;
END CASE;
END;
CREATE OR REPLACE PROCEDURE SCOREPROC ( SCORE CHAR ) AUTHID DEFINER AS BEGIN CASE SCORE WHEN 'A' THEN DBMS_OUTPUT.PUT_LINE('優秀'); WHEN 'B' THEN DBMS_OUTPUT.PUT_LINE('上等'); WHEN 'C' THEN DBMS_OUTPUT.PUT_LINE('良い'); WHEN 'D' THEN DBMS_OUTPUT.PUT_LINE('普通'); WHEN 'F' THEN DBMS_OUTPUT.PUT_LINE('下手'); ELSE NULL; END CASE; END;
CREATE OR REPLACE PROCEDURE SCOREPROC (
  SCORE CHAR
) AUTHID DEFINER AS
BEGIN
  CASE SCORE
    WHEN 'A' THEN DBMS_OUTPUT.PUT_LINE('優秀');
    WHEN 'B' THEN DBMS_OUTPUT.PUT_LINE('上等');
    WHEN 'C' THEN DBMS_OUTPUT.PUT_LINE('良い');
    WHEN 'D' THEN DBMS_OUTPUT.PUT_LINE('普通');
    WHEN 'F' THEN DBMS_OUTPUT.PUT_LINE('下手');
    ELSE NULL;
  END CASE;
END;

 

Oracle

Posted by arkgame