Oracle中如何比较列和参数?

发布于 2024-11-27 20:15:04 字数 516 浏览 1 评论 0原文

我的代码是这样的..

SELECT ALL TBL_MONITOR.ITEM_ID, TBL_MONITOR.CATEGORY, 
TBL_MONITOR.BRANDNAME, TBL_MONITOR.PRICE, TBL_MONITOR.QUANTITY
FROM TBL_MONITOR
where 
case when :pricetag = 'Great' then tbl_monitor.price >= :para_price end,
case when :pricetag = 'Less' then tbl_monitor.price >= :para_price end

这部分不起作用,它说..缺少关键字==> >= :para_price end

==> >= :para_price end,

我想要做的是,如果用户输入“更大”,报告将显示大于“:para_price”的价格 我该如何解决这个问题?预先非常感谢:)

my code goes like this..

SELECT ALL TBL_MONITOR.ITEM_ID, TBL_MONITOR.CATEGORY, 
TBL_MONITOR.BRANDNAME, TBL_MONITOR.PRICE, TBL_MONITOR.QUANTITY
FROM TBL_MONITOR
where 
case when :pricetag = 'Great' then tbl_monitor.price >= :para_price end,
case when :pricetag = 'Less' then tbl_monitor.price >= :para_price end

this part does not work, it says.. missing keyword ==> >= :para_price end

==> >= :para_price end,

wat i want to do is if the user input 'Greater' the reports will show prices greater than the ':para_price'
how would i fix this? Thanks a lot in advance :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

未央 2024-12-04 20:15:04

试试这个

WHERE 
(:pricetag = 'Great' AND tbl_monitor.price >= :para_price)
OR
(:pricetag = 'Less' AND tbl_monitor.price <= :para_price)

Try out this

WHERE 
(:pricetag = 'Great' AND tbl_monitor.price >= :para_price)
OR
(:pricetag = 'Less' AND tbl_monitor.price <= :para_price)
请止步禁区 2024-12-04 20:15:04

SQL CASE 语句(除了您所犯的语法错误之外)不是像 C 或 PHP 中那样的流程控制指令。它是一个返回值的表达式,而不是决定将执行代码的哪一部分的方法。

您并不想说出您想要完成什么或它是如何失败的,但看起来您想要一个简单的表达式:

WHERE (:pricetag = 'Great' AND tbl_monitor.price >= :para_price)
OR (:pricetag = 'Less' AND tbl_monitor.price <= :para_price)

The SQL CASE statement (apart from the syntax errors you are making) is not a flow control instruction like in C or PHP. It's an expression that returns a value and not a way to decide which part of your code will be executed.

You didn't care to say what you are trying to accomplish or how is it failing, but it looks like you want a simple expression:

WHERE (:pricetag = 'Great' AND tbl_monitor.price >= :para_price)
OR (:pricetag = 'Less' AND tbl_monitor.price <= :para_price)
水染的天色ゝ 2024-12-04 20:15:04

尝试这样:

SELECT ALL TBL_MONITOR.ITEM_ID, 
      TBL_MONITOR.CATEGORY, 
      TBL_MONITOR.BRANDNAME, 
      TBL_MONITOR.PRICE, 
      TBL_MONITOR.QUANTITY
FROM TBL_MONITOR
WHERE (:pricetag = 'Great' AND tbl_monitor.price >= :para_price)
OR (:pricetag = 'Less' AND tbl_monitor.price <= :para_price)

Try like this:

SELECT ALL TBL_MONITOR.ITEM_ID, 
      TBL_MONITOR.CATEGORY, 
      TBL_MONITOR.BRANDNAME, 
      TBL_MONITOR.PRICE, 
      TBL_MONITOR.QUANTITY
FROM TBL_MONITOR
WHERE (:pricetag = 'Great' AND tbl_monitor.price >= :para_price)
OR (:pricetag = 'Less' AND tbl_monitor.price <= :para_price)
要走就滚别墨迹 2024-12-04 20:15:04
SELECT ALL TBL_MONITOR.ITEM_ID, TBL_MONITOR.CATEGORY, 
TBL_MONITOR.BRANDNAME, TBL_MONITOR.PRICE, TBL_MONITOR.QUANTITY
FROM TBL_MONITOR
where 
1 = CASE 
      WHEN :pricetag = 'Great' 
      AND  tbl_monitor.price >= :para_price
      THEN  1
      WHEN :pricetag = 'Less' 
      AND  tbl_monitor.price <= :para_price
      THEN 1
      ELSE 0
    END
SELECT ALL TBL_MONITOR.ITEM_ID, TBL_MONITOR.CATEGORY, 
TBL_MONITOR.BRANDNAME, TBL_MONITOR.PRICE, TBL_MONITOR.QUANTITY
FROM TBL_MONITOR
where 
1 = CASE 
      WHEN :pricetag = 'Great' 
      AND  tbl_monitor.price >= :para_price
      THEN  1
      WHEN :pricetag = 'Less' 
      AND  tbl_monitor.price <= :para_price
      THEN 1
      ELSE 0
    END
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文