SQL 更改单词命令
SQL change word command
如何更改 sql 中字母 5 和 6 的位置。例如:
word:weather new word:weatehr
你可以尝试使用SUBSTRING
和LEN
的功能来制作。
CREATE TABLE T(
col varchar(40)
);
INSERT INTO T VALUES ('weather')
查询 1:
SELECT
col 'word' ,CONCAT(SUBSTRING(col,1,4),SUBSTRING(col,6,1),SUBSTRING(col,5,1),SUBSTRING(col,7,LEN(col) - 5)) 'new word'
FROM T
| word | new word |
|---------|----------|
| weather | weatehr |
declare @s varchar(32) = 'weather';
set @s = stuff(@s, 5, 2, reverse(substring(@s, 5, 2)));
由于您只是颠倒相邻字符,因此比交换任意字符要容易一些。
如何更改 sql 中字母 5 和 6 的位置。例如:
word:weather new word:weatehr
你可以尝试使用SUBSTRING
和LEN
的功能来制作。
CREATE TABLE T(
col varchar(40)
);
INSERT INTO T VALUES ('weather')
查询 1:
SELECT
col 'word' ,CONCAT(SUBSTRING(col,1,4),SUBSTRING(col,6,1),SUBSTRING(col,5,1),SUBSTRING(col,7,LEN(col) - 5)) 'new word'
FROM T
| word | new word |
|---------|----------|
| weather | weatehr |
declare @s varchar(32) = 'weather';
set @s = stuff(@s, 5, 2, reverse(substring(@s, 5, 2)));
由于您只是颠倒相邻字符,因此比交换任意字符要容易一些。