gpt4 book ai didi

xml - 在 postgresql 上使用 sql 查询更新 xml 数据

转载 作者:行者123 更新时间:2023-11-29 12:20:37 25 4
gpt4 key购买 nike

我有 XML 数据要更新,而我只有 SQL 查询来执行此操作。如何做到这一点?

我用过

UPDATE TABLE 
SET ARCH = 'XML DATA'
WHERE name='xxx';

但是当在 shell 上粘贴 XML 代码时,它会编译,当然知道代码有一些特殊字符,比如 ' 字符。

我在 Ubuntu 服务器 shell 上。

最佳答案

update TABLE NAME set  COL NAME=xml(REPLACE(OLDXML::text,'</NODE NAME>', NEW VALUE TO UPDATE ||'</NODE NAME>')) where name='xxxx'




Example.
CREATE TABLE notify_test (id integer NOT NULL , notifyxml text)

select * from notify_test

insert into notify_test values(1,'<root><from>Core Integra</from><fromId>mahesh@gm.com</fromId><to></to><cc></cc><bcc></bcc><subject>Accoutn created</subject><body><![CDATA[<div class="container" style="width:800px; margin:auto;font-family: Helvetica Neue, Helvetica, Arial, sans-serif; color: #696969;font-size:14px;"><p>Dear {!User.Username}, </p> <p> Your account is created .Your login details: </p> <p> Username : {!User.Email} </p><p> Password: {!password} </p> <p style="line-height:15px;">Best Regards,</p><p>Core Integra Team</p> <img style="width:76px;height:24px;" alt="OrgUnit Small Logo" src=""></div>]]></body><replyTo /></root>')

-------------------------------------------------


CREATE OR REPLACE FUNCTION public.usf_cic_update_templatexml(
templateid integer,
to_mail text,
cc_mail text)
returns integer as
$BODY$
declare xml text;

declare ccxml text;


begin
SELECT notifyxml into xml from notify_test where id =templateid;
raise notice 'Value: %', to_mail;
raise notice 'Value: %', cc_mail;

if to_mail!='' then

update notify_test set notifyxml=xml(REPLACE(xml::text,'</to>', to_mail ||'</to>')) where id =templateid;

if cc_mail!='' then

SELECT notifyxml into ccxml from notify_test where id =templateid;
update notify_test set notifyxml=xml(REPLACE(ccxml::text,'</cc>', cc_mail ||'</cc>')) where id =templateid;

end if;
end if;
return 1;
END

$BODY$
LANGUAGE plpgsql VOLATILE
COST 100;

关于xml - 在 postgresql 上使用 sql 查询更新 xml 数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26978035/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com