为什么列不填充

时间:2017-07-20 06:34:32

标签: sql oracle

我真的很难过。我在表格中显示了我需要的所有值,此代码由实验室提供,但出于某种原因,rental_item_price列只是不会填充。如果它保留为null,那么我必须添加垃圾代码,以便我可以向NOT NULL列添加约束。有什么想法为什么这个代码不起作用?

UPDATE   rental_item ri
SET      rental_item_price =
      (SELECT   p.amount
       FROM     price p INNER JOIN common_lookup cl1
       ON       p.price_type = cl1.common_lookup_id CROSS JOIN rental r
                CROSS JOIN common_lookup cl2 
       WHERE    p.item_id = ri.item_id AND ri.rental_id = r.rental_id
       AND      ri.rental_item_type = cl2.common_lookup_id
       AND      cl1.common_lookup_code = cl2.common_lookup_code
       AND      r.check_out_date
                  BETWEEN p.start_date AND NVL(p.end_date, TRUNC(SYSDATE) + 1);

我可能会问错误的问题或者过多考虑。我收到的错误是这个

 UPDATE   rental_item ri
 ERROR at line 1
 ORA-00921: unexpected end of SQL command 

1 个答案:

答案 0 :(得分:0)

你打开select语句,用a(但是从不关闭它。添加一个)。

UPDATE   rental_item ri
SET      rental_item_price =
      (SELECT   p.amount
       FROM     price p INNER JOIN common_lookup cl1
       ON       p.price_type = cl1.common_lookup_id CROSS JOIN rental r
                CROSS JOIN common_lookup cl2 
       WHERE    p.item_id = ri.item_id AND ri.rental_id = r.rental_id
       AND      ri.rental_item_type = cl2.common_lookup_id
       AND      cl1.common_lookup_code = cl2.common_lookup_code
       AND      r.check_out_date
                  BETWEEN p.start_date AND NVL(p.end_date, TRUNC(SYSDATE) + 1))