简体   繁体   English

可以在JDBC中运行此MySQL吗?

[英]Can this MySQL Be Run in JDBC?

I am tasked with keeping a sequence number in a table sequential for a certain product ID. 我的任务是在表中保持某个产品ID的顺序编号。 Apart from the argument over whether this is a good thing (I lost the argument), can this SQL statement be run in JDBC? 除了关于这是否是一件好事的争论(我输掉了争论)之外,还可以在JDBC中运行此SQL语句吗? Actually, I guess there are two statements here. 实际上,我想这里有两个陈述。 We are using Spring JDBCTemplates. 我们正在使用Spring JDBCTemplates。

SET @rank:=0; 

UPDATE my_table
SET product_set=@rank:=@rank+1 
WHERE product_id = '123456'; 

you can define a variable inside your query like this 您可以像这样在查询中定义一个变量

UPDATE my_table
inner join (select @rank:= 0) r
SET product_set = @rank:=@rank+1 
WHERE product_id = '123456'; 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM