using currval in where clause

时间:2017-04-06 16:58:41

标签: sql oracle

Is there a way to get the currval in a where clause ? I'm trying to check if the id = currval. I've tried the following:

insert into order values(   
orderid_seq.nextval,
SYSDATE ,
&quantity, 
&student_number,
&room_number, 
&menu_item ,
(select item_cost  * order_quantity 
FROM order_stock,order
WHERE order_stock.menu_item = 
order.menu_item and 
order_id   =  orderid_seq.currval
));

2 个答案:

答案 0 :(得分:0)

You should use IN if there are many in orderid_seq.currval, and the correct syntax is :

   select item_cost  * order_quantity 
    FROM order_stock,order
    WHERE order_stock.menu_item = 
    order.menu_item and 
    order_id   IN  (select order_id from orderid_seq.currval)

updated

 select item_cost  * order_quantity 
    FROM order_stock,order
    WHERE order_stock.menu_item = 
    order.menu_item and 
    order_id  =  (select order_id from Your_table where orderid_seq = 'currval')

答案 1 :(得分:0)

What database is this? If it's Oracle and orderid_seq is a sequence, no you can't use sequence methods in a where clause.

https://docs.oracle.com/database/121/SQLRF/pseudocolumns002.htm