ORCL 游標 CLOB應用 拼接JSON

2021-10-06 04:18:38 字數 1491 閱讀 6941

游標的初步應用:遍歷資料,根據資料中的某個字段,然後再做查詢並迴圈拼接json資料並返回,使用者後續資料的插入。

dbms_lob.createtemporary(var_flow_log,true);
declare

cursor  emp_cur  is select f.c_id,f.flow_ins_id,to_char(replace(f.do_status, f.operator_name||'【'||f.operator_own_dept||'】', '')) ||''as content,f.operator,f.operator_name,f.operator_own_dept,(to_date(to_char(f.operate_time,'yyyy-mm-dd hh24:mi:ss'),'yyyy-mm-dd hh24:mi:ss')-to_date('1970-01-01 08:00:00','yyyy-mm-dd hh24:mi:ss'))*86400000 as c_submitor_time from cos_odoc_flow_log f where f.flow_ins_id=ec.flow_ins_id order by f.operate_time asc;

var_str_log clob;

begin

for es  in emp_cur loop

-- if es.content!='完成瀏覽' then

var_str_log:=var_str_log |||| |||| |||| |||| ||'","submitordept":"'||es.operator_own_dept||'","submittime":'|| es.c_submitor_time|||| ||;

var_flow_log:=var_str_log;

end loop;

end;

insert into dev_wz.cos_odoc_archives_details(c_id,c_temp_version,c_createby,c_createtime,c_deleted,c_updateby,c_updatetime,c_uuid,c_docdetails,c_flowlog,c_flowadvice,c_doc_id)

select ec.id,ec.odoc_code||'-v2-1','gsoft-2018',sysdate,'0','gsoft-2018',sysdate,'',var_json ,'['||substr(var_flow_log,2)||']','['||substr(var_advice_json,2)||']',ec.id from dual

where not exists(select tf.c_id from dev_wz.cos_odoc_archives_details tf  where tf.c_id=ec.id);

update wzococ.cos_odoc_archives_info s set s.c_uuid = 1000 where s.source = ec.id;

end loop;

end;

Oracle 游標 以及CLOB的簡單操作

sample declare cursor mycursor is select from auto event where event id between 54652 and 54681 begin for myoncursor in mycursor loop if myoncursor.st...

ORACLE游標的應用

在oracle資料庫中,可以使用游標瀏覽資料 更新資料和刪除資料,接下來列舉以幾個簡單的例子 通過使用游標既可以逐行檢索結果集中的記錄,又可以更新或刪除當前游標行的資料如果要通過游標更新或刪除資料,在定義游標時必須要帶有for update子句其語句格式如下 cursor cursor name i...

游標的簡單應用

使用游標前資料 declare loginid varchar 50 declare loginpass varchar 50 declare cursor1 cursor for 定義游標cursor1 select loginid,loginpassword from users where l...