Total Pageviews

2020/08/09

[Oracle] CASE Statement example

Requirement
以下是用來將幣別轉換為代號的邏輯
case 幣別
  when 'NTD' then '01'
  when 'USD' then '51'
  when 'HKD' then '52'
  when 'JPY' then '53'

Example
以下是使用 CASE Statement 的範例
FUNCTION FN_GET_CCY_CODE (i_ccy IN VARCHAR2)
    RETURN VARCHAR2 IS o_ccy_code VARCHAR2(2) := '';
    BEGIN
        CASE i_ccy
            WHEN 'NTD' THEN o_ccy_code := '01';
            WHEN 'USD' THEN o_ccy_code := '51';
            WHEN 'HKD' THEN o_ccy_code := '52';
            WHEN 'JPY' THEN o_ccy_code := '53';
        END CASE;

        RETURN o_ccy_code;
    END FN_GET_CCY_CODE;


No comments: