使用split_part()
和lower()
select '<root>'||lower(split_part(split_part('<root>Here is July''s best food</root>',' ',1),'>',2)) || split_part('<root>Here is July''s best food</root>',split_part(split_part('<root>Here is July''s best food</root>',' ',1),'>',2),2)
结果:
"<root>here is July's best food</root>"
UPDATE my_table
SET my_string = '<root>'||lower(split_part(split_part(my_string,' ',1),'>',2)) || split_part(my_string,split_part(split_part(my_string,' ',1),'>',2),2)
WHERE my_id = 1;
以下功能是可选的
您可以制作如下功能
create or replace function lower_first_word(txt text,del text) returns text as
$$
select del||lower(split_part(split_part(txt ,' ',1),'>',2)) || split_part(txt ,split_part(split_part(txt ,' ',1),'>',2),2)
$$
language sql
并更新
UPDATE my_table
SET my_string = lower_first_word('<root>Here is July''s best food</root>','<root>')
WHERE my_id = 1;
或者
使用regex
和substring()
select lower(substring('<root>Here is July''s best food</root>',E'[A-Za-z<>]+'))||substring('<root>Here is July''s best food</root>',E'[^ ]* (.*)')
并且更新语句是
UPDATE my_table
SET my_string = lower(substring('<root>Here is July''s best food</root>', E '[A-Za-z<>]+')) || substring('<root>Here is July''s best food</root>', E '[^ ]* (.*)')
WHERE my_id = 1;