亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

使用 select 和 update 更新 double 類型的列

使用 select 和 update 更新 double 類型的列

MM們 2022-01-12 16:05:15
我在表帳戶中有一個列,我已將其定義為雙列。我想更新我正在調用的字段account_balance。這是我的代碼Query theQuery2 = currentSession.createSQLQuery("update account set account_balance =    (select account_balance from account where telephone_number = ?4 AND nid_number = ?5) + ?6 where telephone_number = ?4 AND nid_number = ?5") ;theQuery2.setParameter(6, the_loss);theQuery2.setParameter(5, nid_number);theQuery2.setParameter(4, telephone_number);theQuery2.executeUpdate();這是mysql查詢update account    set account_balance = (select account_balance where telephone_number = ?4 AND nid_number = ?5) + ?6我怎么能有這個查詢(select account_balance where telephone_number = ?4 AND nid_number = ?5)給我一個類型的值,double以便我添加準備好的值?6,它是 java 中的 double 類型?。
查看完整描述

1 回答

?
繁星點點滴滴

TA貢獻1803條經驗 獲得超3個贊

這個查詢:


update account

    set account_balance = (select account_balance where telephone_number = ?4 AND nid_number = ?5) + ?6

真的沒有意義。大概,您打算:


update account

    set account_balance = account_balance + ?6

    where telephone_number = ?4 and nid_number = ?5;

換句話說,過濾器繼續,update并且嵌套select是不必要的。


你真的不需要擔心類型。您將值作為參數傳遞,如果參數是數字類型(即支持加法),那么它將被添加到account_balance.


我會說應該使用numeric/ decimal(即定點值)而不是 double (浮點值)來存儲貨幣金額。


查看完整回答
反對 回復 2022-01-12
  • 1 回答
  • 0 關注
  • 279 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號