I want to make column in which my amount is less than certain value. When i try this, the query runs
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')
)
);
But when i change the line LOSA_EXP_SUMM_Z.group_exp - 25000 AS "Less than"
to LOSA_EXP_SUMM_Z.group_exp < 25000 AS "Less than"
, then i get the error that
ORA-00923: FROM keyword not found where expected
00923. 00000 - "FROM keyword not found where expected"
*Cause:
*Action:
Error at Line: 3 Column: 34
line 3 is LOSA_EXP_SUMM_Z.group_exp < 25000 AS "Less than"
. Why this runs when we use subtract sign
and give error in case of relational operator
?
Thanks
If you want to use a relational operator in a SELECT
then you will need to use it in a CASE
statement similar to this:
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')
)
);
This will now return either a true
or false
if the record is less than 25000. You can change the return to whatever you need, including:
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')
)
);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.