[英]How to prevent Spring Boot/Hibernate from converting entity column names from PascalCase to snake_case?
[英]Change the values in a column from PascalCase to snake_case using SQL
我有一张雪花表,看起来像这样:
--------------------
| fieldname |
--------------------
|thisIsTestOne |
|thisIsTestTwo |
|this_test |
--------------------
我需要将列中的 PascalCase 值转换为 snake_case。 注意:如果它们是 PascalCase,我只想将它们转换为 snake_case。 output 应该是这样的;
-------------------- ---------------------
| fieldname | newfieldname |
-------------------- ---------------------
|thisIsTestOne |this_is_test_one |
|thisIsTestTwo |this_is_test_two |
|this_test |this_test |
-------------------- ---------------------
您应该能够使用REGEXP_REPLACE
在小写字符后跟大写字符之间插入下划线,然后将LOWER
转换为小写,即
SELECT LOWER(REGEXP_REPLACE(fieldname, '([a-z])([A-Z])', '\\1_\\2'))
FROM yourtable
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.