【发布时间】:2016-06-07 08:23:57
【问题描述】:
所以,我是使用 PL/SQL 的新手。我已经定义了一个名为 startDate 的变量,然后我想稍后在某些查询中引用它。但是,当我稍后使用 &&startDate 引用它时,系统会提示我输入变量。
/* Define the date bounds used */
/* Depending on the current quarter I want to set my start and end dates differently */
DROP TABLE DATE_BOUNDS;
CREATE TABLE DATE_BOUNDS AS
select
case when to_char(sysdate, 'Q') = '1' then to_date('10/01' || to_char(to_char(sysdate, 'YYYY')-1))
when to_char(sysdate, 'Q') = '2' then to_date('01/01/' || to_char(sysdate, 'YYYY'))
when to_char(sysdate, 'Q') = '3' then to_date('04/01/' || to_char(sysdate, 'YYYY'))
when to_char(sysdate, 'Q') = '4' then to_date('07/01/' || to_char(sysdate, 'YYYY'))
end as date1,
case when to_char(sysdate, 'Q') = '1' then add_months(to_date('10/01' || to_char(to_char(sysdate, 'YYYY')-1))-1,12)
when to_char(sysdate, 'Q') = '2' then add_months(to_date('01/01/' || to_char(sysdate, 'YYYY'))-1 ,12)
when to_char(sysdate, 'Q') = '3' then add_months(to_date('04/01/' || to_char(sysdate, 'YYYY'))-1,12)
when to_char(sysdate, 'Q') = '4' then add_months(to_date('07/01/' || to_char(sysdate, 'YYYY'))-1,12)
end as date2
from dual;
/* Defining the variable 'startDate' as 'date1' from the previous table */
DECLARE
startDate date;
BEGIN
SELECT date1 INTO startDate
FROM DATE_BOUNDS;
END;
当我尝试一些简单的事情时,比如:
select &&startDate from dual;
当我在 SQL Developer 中运行它时,系统会提示我输入 startDate 而不是仅使用 supposed 在 DECLARE 步骤中定义的内容。 . 什么给了?
【问题讨论】:
标签: sql oracle variables dynamic