是否可以使用 replace 编写更新语句,我们只知道要剪切的字符串的开头和结尾
Is it possible to write an update statement using replace where we just know the start and end of a string that we want to cut
我有一个名为 service
的 table 和一个名为 xml
的列。在其中一条记录中,xml
值为:-
select xml from service where xml like '%Password% ;
xml
<UseUDS>true</UseUDS><UseUserCredential>true</UseUserCredential>**<DN>amrit</DN><Password>amrit</Password>**<SearchContext1></SearchContext1><SearchContext2></SearchContext2><SearchContext3></SearchContext3><RecursiveSearch1>true</RecursiveSearch1><SearchTimeout>5</SearchTimeout><BaseFilter></BaseFilter><PredictiveSearchFilter></PredictiveSearchFilter>
我想使用替换函数编写一个更新语句,它应该从列值中删除 <DN>amrit</DN><Password>amrit</Password>
并保留其余部分。
请注意,字符串 amrit
可以是任何内容。
我尝试使用通配符,但没有用——如下所示:-
update service set xml = REPLACE(xml,'<DN>%</DN><Password>%</Password>','')
where xml like '%Password% ;
是否可以使用 REPLACE 编写更新语句,我们只知道要剪切的字符串的开头和结尾。
我假设您使用的是相对较新版本的 Informix(如 11.70 或 12.10)。
这是实现您想要做的事情的一种方法,前提是您的 xml 字符串将如您所示的那样保持相当直接:
update service set xml = concat(substring_index(xml, "<DN>", 1), substring_index(xml, "</Password>", -1)) where xml like '%Password%' ;
这是 Informix https://www.ibm.com/support/knowledgecenter/SSGU8G_12.1.0/com.ibm.sqls.doc/ids_sqs_1554.htm#ids_sqs_1554
中可用的字符串操作函数的完整列表
我有一个名为 service
的 table 和一个名为 xml
的列。在其中一条记录中,xml
值为:-
select xml from service where xml like '%Password% ;
xml
<UseUDS>true</UseUDS><UseUserCredential>true</UseUserCredential>**<DN>amrit</DN><Password>amrit</Password>**<SearchContext1></SearchContext1><SearchContext2></SearchContext2><SearchContext3></SearchContext3><RecursiveSearch1>true</RecursiveSearch1><SearchTimeout>5</SearchTimeout><BaseFilter></BaseFilter><PredictiveSearchFilter></PredictiveSearchFilter>
我想使用替换函数编写一个更新语句,它应该从列值中删除 <DN>amrit</DN><Password>amrit</Password>
并保留其余部分。
请注意,字符串 amrit
可以是任何内容。
我尝试使用通配符,但没有用——如下所示:-
update service set xml = REPLACE(xml,'<DN>%</DN><Password>%</Password>','')
where xml like '%Password% ;
是否可以使用 REPLACE 编写更新语句,我们只知道要剪切的字符串的开头和结尾。
我假设您使用的是相对较新版本的 Informix(如 11.70 或 12.10)。
这是实现您想要做的事情的一种方法,前提是您的 xml 字符串将如您所示的那样保持相当直接:
update service set xml = concat(substring_index(xml, "<DN>", 1), substring_index(xml, "</Password>", -1)) where xml like '%Password%' ;
这是 Informix https://www.ibm.com/support/knowledgecenter/SSGU8G_12.1.0/com.ibm.sqls.doc/ids_sqs_1554.htm#ids_sqs_1554