如何使用DEFINE函数设置一个变量,该变量等于另一个SELECT语句的结果? (结果仅是单列/单行选择)
示例:
DEFINE source_table = mysourcetable
DEFINE use_date = select distinct max(txn_date) from &source_table
select asdf1, asdf2
from &source_table s
where &use_date between s.eff_date and s.end_date
我当前遇到的错误是WHERE子句中&usedate变量上的“缺少表达式”。
希望如此。
答案 0 :(得分:1)
只是想通了。 WHERE子句中的&use_date需要放在括号中...
DEFINE source_table = mysourcetable
DEFINE use_date = select distinct max(txn_date) from &source_table
select asdf1, asdf2
from &source_table s
where (&use_date) between s.eff_date and s.end_date
OR 将DEFINE查询放在括号中:
DEFINE source_table = mysourcetable
DEFINE use_date = (select distinct max(txn_date) from &source_table)
select asdf1, asdf2
from &source_table s
where &use_date between s.eff_date and s.end_date
答案 1 :(得分:0)
仅出于完整性考虑,这是使用COLUMN .. NEW_VALUE
命令的另一种方式:
DEFINE source_table = mysourcetable
column the_col new_value use_date
select distinct max(txn_date) the_col from &source_table;
PROMPT The value is &use_date
select asdf1, asdf2
from &source_table s
where TO_DATE('&use_date') between s.eff_date and s.end_date;