[英]Sql UPDATE STATEMENT oracle
I need to update a quantity in to my database. 我需要更新数据库中的数量。 I tried with a update statement, (trigger oracle, don't work because definitely something wrong)
我尝试了一条更新语句,(触发oracle,不起作用,因为肯定有问题)
My sql string is: 我的SQL字符串是:
String sql1 = "update book set qty = qty - 1 where isbn='" + txt_carr.getText() + "'";
txt_carr
is a txtField where I write a isbn
(for add a cart), but the quantity don't change for that precise ISBN
. txt_carr
是一个txtField,我在其中写了一个isbn
(用于添加购物车),但是数量对于那个精确的ISBN
不会改变。
Also in the cart when you close the program, should update the quantity (even at a fixed, for example 5) 另外,当您关闭程序时,在购物车中也应更新数量(即使是固定的数量,例如5)
I tried this: 我尝试了这个:
String sql3= "UPDATE book SET quantity= 5 (select isbn cart where isbn=) ";
Where isbn
= to all isbn in your cart. isbn
=您购物车中所有isbn的位置。 So it should only update the quantity (in table book) of the books in the shopping cart and not all. 因此,它只应更新购物车中(而不是表中)书籍的数量,而不是全部。
I know that a trigger would work much better, but do not know how to write it. 我知道触发器会更好,但不知道如何编写。
SQL语法无效:
String sql3= "UPDATE book SET quantity= '5' where book.isbn = 'YOUR_ISBN'";
Try this one: 试试这个:
UPDATE book b SET b.quantity =
(SELECT COUNT (*)
FROM cards c
WHERE c.isbn = b.isbn) WHERE b.isbn = 'YOUR_ISBN';
So your code will be as: 因此,您的代码将为:
String sql1= "UPDATE book b SET b.quantity =(SELECT COUNT (*) FROM card c WHERE c.isbn = b.isbn) WHERE b.isbn = '" + txt_carr.getText() + "' ";
Not: I'm not sure about table names. 不是:我不确定表名。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.