我想通過一個表格,並將'notify4-N'的所有實例更改爲'notify5-N',其中N是1-9的數字。有沒有辦法在SQL中做到這一點?在perl中很容易,但我不確定客戶甚至在他的服務器上安裝perl。在更新中使用通配符?
2
A
回答
6
您可能正在尋找REGEXP_REPLACE
和REGEXP_LIKE
函數與更新結合使用。
update sometable set somecol = REGEXP_REPLACE(somecol, ...) where REGEXP_LIKE(somecol, ...)
1
沒有測試,但是:
UPDATE my_table SET name = 'notify5-' || SUBSTR(name, 9) WHERE name LIKE 'notify4-%'
這應該不支持正則表達式匹配的數據庫服務器。 :-)(但是,我看到您的帖子標有Oracle,所以我推測Klaus的答案也適用於您。)
2
這顯示了將用於更新的值。 where條件確保notify4-11保持不變。
create table notify(n varchar(20));
insert into notify(n) values('notify4-0');
insert into notify(n) values('notify4-1');
insert into notify(n) values('notify4-2');
insert into notify(n) values('notify4-8');
insert into notify(n) values('notify4-9');
insert into notify(n) values('notify4-11');
select n, regexp_replace(n,'^notify4-([1-9]{1})$', 'notify5-\1') from notify where regexp_like(n, '^notify4-[1-9]{1}$') order by n;
相關問題
- 1. 如何在使用更新時在MongoDB中使用通配符?
- 2. 使用通配符更新和替換
- 3. 在角度更新中使用通配符
- 4. 在更新語句中使用通配符
- 5. Mysql更新值通配符
- 6. 在excel中使用通配符在產品中使用通配符
- 7. 通配符在使用PowerShell
- 8. 使用通配符在Javascript
- 9. 使用通配符或ILIKE進行更新的SQLAlchemy
- 10. 通配符使用更新7zip與相似標題的Sfx
- 11. 使用通配符
- 12. 使用通配符
- 13. 使用通配符
- 14. 使用通配符
- 15. 如何在createQueryBuilder中使用通配符?
- 16. 在WebDriver中使用通配符By.XPATH
- 17. 在preg_match中使用通配符
- 18. 在tox命令中使用通配符
- 19. 在單詞宏中使用通配符
- 20. 如何在ElasticSearch中使用通配符?
- 21. 在表數據中使用通配符
- 22. 在global.asax中使用通配符MapPageRoute
- 23. 在ruby/watir中使用通配符
- 24. 在Selenium IDE中使用通配符
- 25. 在Glob中使用部分通配符
- 26. 問題在Makefile中使用通配符(*)
- 27. 在java中使用通配符類型
- 28. GROUP BY在MySQL中使用通配符
- 29. 想在xpath中使用通配符
- 30. 在僞造中使用通配符