如何将 DEFINE 变量设置为等于 PL/SQL 中另一个定义的 table 的选择

How to set a DEFINE variable equal to the selection from another defined table in PL/SQL

如何使用 DEFINE 函数设置一个等于另一个 SELECT 语句结果的变量? (结果只有 single-column/single-row 个选择)

示例:

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

我目前遇到的错误是 'missing expression' WHERE 子句中的 &usedate 变量。

希望这是有道理的。

刚刚弄明白了。 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

为了完整起见,这是使用 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;