0

金額が一定額以下のコラムを作りたい。これを試すと、クエリが実行されます

select LOSA_APP.app_ref_no AS "App.Ref.No.",
   LOSA_EXP_SUMM_Z.group_exp AS "Group Exposure Amount",
   LOSA_EXP_SUMM_Z.group_exp - 25000 AS "Less than",
   columns AS "some Name"
   columns AS "some Name"
from 
     losa_app LOSA_APP
INNER JOIN
    code_branch CODE_BRANCH
ON
    LOSA_APP.attend_branch = CODE_BRANCH.branch_id
....
where 
    LOSA_APP.app_status in ('A','R')
and
    ....
 or 
 (
    '&&aplication' = 'Enhancement' 
    and 
    (
        nvl(LOSA_APP.review_type, '-') IN ('Enhancement', 'Additional')  and nvl(LOSA_APP.review_freq, '-') IN ('Enhancement', 'New')
    )
);

しかし、行LOSA_EXP_SUMM_Z.group_exp - 25000 AS "Less than"LOSA_EXP_SUMM_Z.group_exp < 25000 AS "Less than"に変更すると、次のエラーが発生します

ORA-00923: FROM keyword not found where expected
00923. 00000 -  "FROM keyword not found where expected"
*Cause:    
*Action:
Error at Line: 3 Column: 34

3行目はLOSA_EXP_SUMM_Z.group_exp < 25000 AS "Less than"です。使用するとなぜこれが実行subtract signされ、の場合にエラーが発生しrelational operatorますか?

ありがとう

4

1 に答える 1

1

で関係演算子を使用する場合は、次のようなステートメントSELECTで使用する必要があります。CASE

select LOSA_APP.app_ref_no AS "App.Ref.No.",
   LOSA_EXP_SUMM_Z.group_exp AS "Group Exposure Amount",
   CASE 
        WHEN LOSA_EXP_SUMM_Z.group_exp < 25000 
        then 'true'
        else 'false' 
     end AS "Less than",
   columns AS "some Name"
   columns AS "some Name"
from losa_app LOSA_APP
INNER JOIN code_branch CODE_BRANCH
    ONLOSA_APP.attend_branch = CODE_BRANCH.branch_id
....
where  LOSA_APP.app_status in ('A','R')
and
    ....
 or 
 (
    '&&aplication' = 'Enhancement' 
    and 
    (
        nvl(LOSA_APP.review_type, '-') IN ('Enhancement', 'Additional')  and nvl(LOSA_APP.review_freq, '-') IN ('Enhancement', 'New')
    )
);

レコードが 25000 未満の場合は、trueまたはのいずれかが返されるようになりました。次のように、必要に応じて戻り値を変更できます。false

select LOSA_APP.app_ref_no AS "App.Ref.No.",
   LOSA_EXP_SUMM_Z.group_exp AS "Group Exposure Amount",
   CASE WHEN LOSA_EXP_SUMM_Z.group_exp < 25000 
            then LOSA_EXP_SUMM_Z.group_exp - 25000
        else LOSA_EXP_SUMM_Z.group_exp end AS "Less than",
   columns AS "some Name"
   columns AS "some Name"
from losa_app LOSA_APP
INNER JOIN code_branch CODE_BRANCH
    ONLOSA_APP.attend_branch = CODE_BRANCH.branch_id
....
where  LOSA_APP.app_status in ('A','R')
and
    ....
 or 
 (
    '&&aplication' = 'Enhancement' 
    and 
    (
        nvl(LOSA_APP.review_type, '-') IN ('Enhancement', 'Additional')  and nvl(LOSA_APP.review_freq, '-') IN ('Enhancement', 'New')
    )
);
于 2012-12-05T14:27:03.727 に答える