[英]laravel SQLSTATE[22007]: Invalid datetime format: 1366 Incorrect decimal value: 'buy_amt * 0.00097812555575316' for column 'price' at row 1 error
I am trying to update the entire data, but I need to divide the exchange rate by the margin rate on the purchase price, and data format error occurs. 我正在尝试更新整个数据,但是我需要将汇率除以购买价格上的保证金率,并且会发生数据格式错误。
SQLSTATE[22007]: Invalid datetime format: 1366 Incorrect decimal value: 'buy_amt * 0.00097812555575316' for column 'prod' at row 1 (SQL: update prod set value = 10, price = buy_amt * 0.00097812555575316 ) SQLSTATE [22007]:无效的日期时间格式:1366不正确的十进制值:行1的列'prod'的'buy_amt * 0.00097812555575316'(SQL:更新prod设置值= 10,价格= buy_amt * 0.00097812555575316)
my code: 我的代码:
DB::update("update prod set value = ?, price = ?, ",
[
$datas["value"],
"buy_amt * ".(1+($datas["value"]/100))/$datas["price"],
]);
prod table 产品表
price value datatype DECIMAL buy_amt datatype INT
price | value | buy_amt
11 | 10 | 10
22 | 10 | 20
This piece of code 这段代码
"buy_amt * ".(1+($datas["value"]/100))/$datas["price"]
will yield a string which wont fit into the price field in database which is a number 将产生一个字符串,该字符串将不适合数据库中的price字段,该字符串是一个数字
You meant this 你是这个意思
$buy_amt * (1+($datas["value"]/100))/$datas["price"]
? ?
I solved this problem... 我解决了这个问题
DB::table("prod")
->update([
"value" => $datas["value"],
"price" => DB::raw("buy_amt * ".(1+($datas["value"]/100))/$datas["price"]),
]),
Need to use DB :: raw to have the query calculate. 需要使用DB :: raw来进行查询计算。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.