Sql 如何循环并输出原始值
我正在将值打印到输出,但我不确定如何在更新和显示原始值之前获取原始值Sql 如何循环并输出原始值,sql,oracle,oracle11g,Sql,Oracle,Oracle11g,我正在将值打印到输出,但我不确定如何在更新和显示原始值之前获取原始值 declare v_ids varchar2(4000); begin update time_line tl set tl.limit_template = 'LIM0178' where tl.limit_template IN (select tl.limit_template from base_timeline_section bbts,
declare
v_ids varchar2(4000);
begin
update time_line tl
set tl.limit_template = 'LIM0178'
where tl.limit_template IN
(select tl.limit_template
from base_timeline_section bbts,
base_timeline_org bts,
trmt_timeline tl
where bbts.base_trmt_set_id = bts.base_trmt_set_id
and tl.limit_id = bts.limit_id
and bbts.bse_trmt_st_tplt_id = '720')
returning listagg(tl.limit_template, ',') within group
(order by tl.limit_template) into v_ids;
dbms_output.put_line('Updated IDs: ' || v_ids || ' to LIM0178');
end;
现在我得到以下输出:更新的ID:
LIM0178至LIM0178
我想要的是
原值:6165改为新值:LIM0178
在更新之前,您可以将值放在一个变量中,并根据需要使用它。 您可以找到此链接了解更多信息
我不确定语法,如果发现任何错误,您可以进一步检查并更正此ans。我认为您可以中断语句,将值返回到变量中,并传递变量以更新值,因为它是逗号分隔的。它可以是一个值列表,这样它将执行选择:-
declare
v_ids clob;
v_ids2 clob;
begin
select RTRIM(XMLAGG(XMLELEMENT(E,tl.limit_template,',').EXTRACT('//text()') ORDER BY tl.limit_template).GetClobVal(),',') into v_ids
from base_timeline_section bbts,
base_timeline_org bts,
trmt_timeline tl
where bbts.base_trmt_set_id = bts.base_trmt_set_id
and tl.limit_id = bts.limit_id
and bbts.bse_trmt_st_tplt_id = '720';
update time_line tl
set tl.limit_template = 'LIM0178'
where tl.limit_template IN (select REGEXP_SUBSTR (DBMS_LOB.substr(v_ids,30000), '[^,]+', 1, level)
from (select rownum from dual )
connect by level <= length(regexp_replace(v_ids,'[^,]*'))+1);
dbms_output.put_line('Updated IDs: ' || v_ids || ' to LIM0178');
select RTRIM(XMLAGG(XMLELEMENT(E,iplu.limit_template_id,',').EXTRACT('//text()') ORDER BY iplu.limit_template_id).GetClobVal(),',') into v_ids2
from base_timeline_section bbts,
base_timeline_org bts,
trmt_timeline tl,
timeline_update_limit iplu
where bbts.base_trmt_set_id = bts.base_trmt_set_id
and tl.limit_id = bts.limit_id
and bbts.bse_trmt_st_tplt_id = '720'
and iplu.limit_template_id = tl.limit_template;
update timeline_update_limit iplu
set iplu.limit_template_id = 'LIM178'
where iplu.limit_template_id IN (select REGEXP_SUBSTR (DBMS_LOB.substr(v_ids2,30000), '[^,]+', 1, level)
from (select rownum from dual )
connect by level <= length(regexp_replace(v_ids2,'[^,]*'))+1);
dbms_output.put_line('Update table 2 IDs: ' || v_ids2 || ' to LIM0178');
end;
感谢我收到了一个符号选择,当我期待下列之一时,开始函数pragma procedure subtype–@jacques我已经更新了代码,因为之前我将v_id直接传递给update语句,但该语句无法工作。您遇到的错误可能是由于缺少或不正确的括号,请尝试新代码,并让我知道它是否有效。如果我有第二个表需要更新,它似乎无法填充列表,我不确定原因,我得到表1更新的ID:130081306913130134021346713532135971359713662137271379213857139221398714052141418221424714371444214507145721463711470214767148971496215027150921515715222152153521541715482155471612162621652216716782到LIM0178表2更新的ID:LIM0178如果您愿意共享第二个ID:表语句,将尝试查看它的错误。如果以前的解决方案工作正常,您可以使用向上箭头接受答案。感谢幸运的是,当我尝试此操作时,我得到了一个ORA-01422:fetch返回的行数超过了请求的行数,这意味着在正在更新的limit_模板列中有多个值。请单独验证此查询,以便根据需要的记录应用筛选器。或者使用distinct来获取记录。
DECLARE
the_variable NUMBER; --- this is varaible declare
declare
v_ids varchar2(4000);
begin
SELECT limit_template INTO the_variable FROM time_line --- here we are setting its value
where tl.limit_template IN
(select tl.limit_template
from base_timeline_section bbts,
base_timeline_org bts,
trmt_timeline tl
where bbts.base_trmt_set_id = bts.base_trmt_set_id
and tl.limit_id = bts.limit_id
and bbts.bse_trmt_st_tplt_id = '720')
returning listagg(tl.limit_template, ',') within group
(order by tl.limit_template) into v_ids;
dbms_output.put_line('Updated IDs: ' || v_ids || ' to LIM0178');;
update time_line tl
set tl.limit_template = 'LIM0178'
where tl.limit_template IN
(select tl.limit_template
from base_timeline_section bbts,
base_timeline_org bts,
trmt_timeline tl
where bbts.base_trmt_set_id = bts.base_trmt_set_id
and tl.limit_id = bts.limit_id
and bbts.bse_trmt_st_tplt_id = '720')
returning listagg(tl.limit_template, ',') within group
(order by tl.limit_template) into v_ids;
dbms_output.put_line('Updated IDs: ' || v_ids || ' to LIM0178');
end;
declare
v_ids clob;
v_ids2 clob;
begin
select RTRIM(XMLAGG(XMLELEMENT(E,tl.limit_template,',').EXTRACT('//text()') ORDER BY tl.limit_template).GetClobVal(),',') into v_ids
from base_timeline_section bbts,
base_timeline_org bts,
trmt_timeline tl
where bbts.base_trmt_set_id = bts.base_trmt_set_id
and tl.limit_id = bts.limit_id
and bbts.bse_trmt_st_tplt_id = '720';
update time_line tl
set tl.limit_template = 'LIM0178'
where tl.limit_template IN (select REGEXP_SUBSTR (DBMS_LOB.substr(v_ids,30000), '[^,]+', 1, level)
from (select rownum from dual )
connect by level <= length(regexp_replace(v_ids,'[^,]*'))+1);
dbms_output.put_line('Updated IDs: ' || v_ids || ' to LIM0178');
select RTRIM(XMLAGG(XMLELEMENT(E,iplu.limit_template_id,',').EXTRACT('//text()') ORDER BY iplu.limit_template_id).GetClobVal(),',') into v_ids2
from base_timeline_section bbts,
base_timeline_org bts,
trmt_timeline tl,
timeline_update_limit iplu
where bbts.base_trmt_set_id = bts.base_trmt_set_id
and tl.limit_id = bts.limit_id
and bbts.bse_trmt_st_tplt_id = '720'
and iplu.limit_template_id = tl.limit_template;
update timeline_update_limit iplu
set iplu.limit_template_id = 'LIM178'
where iplu.limit_template_id IN (select REGEXP_SUBSTR (DBMS_LOB.substr(v_ids2,30000), '[^,]+', 1, level)
from (select rownum from dual )
connect by level <= length(regexp_replace(v_ids2,'[^,]*'))+1);
dbms_output.put_line('Update table 2 IDs: ' || v_ids2 || ' to LIM0178');
end;