Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/oracle/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何将DEFINE变量设置为PL/SQL中另一个已定义表中的选择_Sql_Oracle_Sqlplus - Fatal编程技术网

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

如何将DEFINE变量设置为PL/SQL中另一个已定义表中的选择,sql,oracle,sqlplus,Sql,Oracle,Sqlplus,如何使用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.e

如何使用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变量上的“缺少表达式”


希望这是有意义的。

刚刚想好了。WHERE子句中的&use\u日期需要放在括号中

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
或者将定义查询放在括号中:

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

为了完整起见,这是使用列的另一种方式。。新值命令:

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;