久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

MYSQL - 警告:#1287 在表達式中設(shè)置用戶變量已被棄

MYSQL - Warning: #1287 Setting user variables within expressions is deprecated and will be removed in a future release(MYSQL - 警告:#1287 在表達式中設(shè)置用戶變量已被棄用,并將在未來版本中刪除) - IT屋-程序員軟件
本文介紹了MYSQL - 警告:#1287 在表達式中設(shè)置用戶變量已被棄用,并將在未來版本中刪除的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

警告:#1287 在表達式中設(shè)置用戶變量已被棄用,并將在未來版本中刪除.考慮替代方案:SET variable=expression, ..."或SELECT expression(s) INTO variables(s)".

Warning: #1287 Setting user variables within expressions is deprecated and will be removed in a future release. Consider alternatives: 'SET variable=expression, ...', or 'SELECT expression(s) INTO variables(s)'.

這是 MySQL 8.0.21 吐出來的.代碼有效......但我也需要它在未來版本中工作......所以我的問題是這個警告的正確方法是什么?

This is what MySQL 8.0.21 spits out. The code works... But I need it to work in future versions too.... So my question is what is the correct approach to this warning?

我需要將一個變量設(shè)置為某個數(shù)字(我將通過一行的 ID 獲得).而且我需要它在每個 SET 語句中加 1.

I need a variable to be set to some number (which I will get via ID of a row). And I need it to be incremented by 1 with every SET statement.

我應(yīng)該如何更改此代碼以使警告消失?

How should I change this code so the warning would go away?

SET @fromorder = (SELECT `order` FROM forms WHERE id=5);
/* SET @fromorder = 4;  - so this is the same in the example below */
UPDATE forms SET `order` = @fromorder := @fromorder + 1 WHERE `order` > -1 and `order` <= 4 ORDER BY `order` ASC;
SET @fromorder = null;

據(jù)我所知,問題在于:

`order` = @fromorder := @fromorder + 1

我猜這需要改變嗎?

因此:

+-------+-----------+
|   id  |   order   |
+-------+-----------+
|   1   |   0       |
|   2   |   1       |
|   3   |   2       |
|   4   |   3       |
|   5   |   4       |
+-------+-----------+

我想通過這個查詢得到這個(例如):

I want to get this (for example) with this query:

+-------+-----------+
|   id  |   order   |
+-------+-----------+
|   1   |   5       |
|   2   |   6       |
|   3   |   7       |
|   4   |   8       |
|   5   |   9       |
+-------+-----------+

這是一個簡單的 for 循環(huán),增量 += 1;

It is an easy for loop with incrementation += 1;

推薦答案

你的 MySql 版本支持窗口函數(shù),通過使用 ROW_NUMBER() 窗口函數(shù)你可以避免變量:

Your version of MySql supports window functions and by using ROW_NUMBER() window function you can avoid variables:

UPDATE forms f
CROSS JOIN (SELECT `order` FROM forms WHERE id = 5) c
INNER JOIN (
  SELECT *, ROW_NUMBER() OVER (ORDER BY `order`) rn
  FROM forms
  WHERE `order` > -1 and `order` <= 4 
) t ON t.id = f.id
SET f.`order` = c.`order` + t.rn;

請參閱演示.

這篇關(guān)于MYSQL - 警告:#1287 在表達式中設(shè)置用戶變量已被棄用,并將在未來版本中刪除的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

Typeorm Does not return all data(Typeorm 不返回所有數(shù)據(jù))
MySQL return extra records when using a long type number to filter varchar type(MySQL在使用長類型數(shù)字過濾varchar類型時返回額外記錄)
MySQL Error #1071 - Specified key was too long; max key length is 767 bytes(MySQL 錯誤 #1071 - 指定的鍵太長;最大密鑰長度為 767 字節(jié))
MySQL command-line table column width with utf8(MySQL命令行表列寬與utf8)
Python unicode encoding issue(Python unicode 編碼問題)
Create a MySQL stored function with a dynamic number of arguments(創(chuàng)建一個帶有動態(tài)參數(shù)數(shù)量的 MySQL 存儲函數(shù))
主站蜘蛛池模板: 毛片a区 | 成人免费视频网站在线观看 | 日日干夜夜操 | 亚洲精彩免费视频 | 天堂免费看片 | 日韩视频在线观看中文字幕 | 99色综合| 欧美激情99 | 婷婷色婷婷 | 国产精品一区三区 | 伊伊综合网 | 日韩超碰| 草草影院ccyy | 久久久久久亚洲精品 | aaaaa毛片 | 欧美亚洲国产一区二区三区 | 国产精品精品久久久 | 久久不卡区 | 免费的色网站 | 成在线人视频免费视频 | av影音资源| 欧美操操操 | 91视频在线看 | 在线观看不卡av | 2019天天操 | 中文字幕日韩专区 | 国产精品一区在线 | 亚洲美女一区二区三区 | 国产日韩精品一区 | 欧美一级在线 | 在线成人av | 在线观看国产wwwa级羞羞视频 | 亚洲国产二区 | 一级看片免费视频囗交动图 | 999国产视频 | 日韩在线视频一区二区三区 | 91最新在线视频 | 伊人网在线播放 | 在线播放一区 | 久久亚洲天堂 | 男人的天堂中文字幕 |