我有一个非常长的Oracle SQL脚本,用于过滤多个地方的商品编号,即:
[...]
where article_nr = 12345
[...]
为了避免在更改文章时手动调整20行代码,我引入了变量,即:
define article_1 = 12345
[...]
where article_nr = &&article_1
[...]
然而,现在,我收到一个错误,说它“缺少右括号”。我没有碰到关于括号的任何内容,只是用变量替换了12345。 我是否必须逃避“&&”不知何故?
很抱歉没有发布完整代码,但是它有多个嵌套选择。
由于
编辑(工作示例):
这有效:
select * from stores
where
(opening_date >= '21.11.2016')
;
这不起作用(使用一个或两个“&”):
define opening = '21.11.2016'
select * from stores
where
(opening_date >= &&opening)
;
==> “缺少右括号”
答案 0 :(得分:1)
数字文字不需要引号......
where article_nr = 12345
但是日期(和字符串)文字做...
(opening_date >= '21.11.2016')
相同的规则适用于替代变量。数字分配:
where article_nr = &&article_1
日期分配:
(opening_date >= '&&opening')
正如其他人所评论的那样,明确投射日期是一种很好的做法:
(opening_date >= to_date('&&opening', 'dd.mm.yyyy'))