如下所示:
CREATE OR REPLACE PROCEDURE p_xlstooracle IS
v_file utl_file.file_type;
out_v VARCHAR2(4000);
v_id NUMBER;
v_service_competition NUMBER;
v_cu_market_share NUMBER(6, 4);
v_ct_market_share NUMBER(6, 4);
v_cm_market_share NUMBER(6, 4);
v_other_market_share NUMBER(6, 4);
BEGIN
IF utl_file.is_open(v_file) THEN
utl_file.fclose(v_file);
END IF;
v_file := utl_file.fopen('UTL_FILE_DIR', 'i_exch_info2.xls', 'r');
LOOP
BEGIN
utl_file.get_line(v_file, out_v);
EXCEPTION
WHEN no_data_found THEN
EXIT;
END;
v_id := substr(out_v, 1, instr(out_v, ' ', 1, 1) - 1);
v_service_competition := substr(out_v,
instr(out_v, ' ', 1, 1) + 1,
instr(out_v, ' ', 1, 2) - instr(out_v, ' ', 1, 1)-1);
v_cu_market_share := substr(out_v,
instr(out_v, ' ', 1, 2) + 1,
instr(out_v, ' ', 1, 3) - instr(out_v, ' ', 1, 2)-1);
v_ct_market_share := substr(out_v,
instr(out_v, ' ', 1, 3) + 1,
instr(out_v, ' ', 1, 4) - instr(out_v, ' ', 1, 3)-1);
v_cm_market_share := substr(out_v,
instr(out_v, ' ', 1, 4) + 1,
instr(out_v, ' ', 1, 5) - instr(out_v, ' ', 1, 4)-1);
v_other_market_share := substr(out_v,
instr(out_v, ' ', 1, 5) + 1,
length(out_v) - instr(out_v, ' ', 1, 5));
UPDATE i_exch_info
SET service_competition = v_service_competition,
cu_market_share = v_cu_market_share,
ct_market_share = v_ct_market_share,
cm_market_share = v_cm_market_share,
other_market_share = v_other_market_share
WHERE gwm_fid = v_id;
dbms_output.put_line(out_v);
END LOOP;
utl_file.fclose(v_file);
END p_xlstooracle;
注:分隔符不是空格,我是直接拷贝的excel输出文本的那个间隔字符才行。 v_file utl_file.file_type;
out_v VARCHAR2(4000);
v_id NUMBER;
v_service_competition NUMBER;
v_cu_market_share NUMBER(6, 4);
v_ct_market_share NUMBER(6, 4);
v_cm_market_share NUMBER(6, 4);
v_other_market_share NUMBER(6, 4);
BEGIN
IF utl_file.is_open(v_file) THEN
utl_file.fclose(v_file);
END IF;
v_file := utl_file.fopen('UTL_FILE_DIR', 'i_exch_info2.xls', 'r');
LOOP
BEGIN
utl_file.get_line(v_file, out_v);
EXCEPTION
WHEN no_data_found THEN
EXIT;
END;
v_id := substr(out_v, 1, instr(out_v, ' ', 1, 1) - 1);
v_service_competition := substr(out_v,
instr(out_v, ' ', 1, 1) + 1,
instr(out_v, ' ', 1, 2) - instr(out_v, ' ', 1, 1)-1);
v_cu_market_share := substr(out_v,
instr(out_v, ' ', 1, 2) + 1,
instr(out_v, ' ', 1, 3) - instr(out_v, ' ', 1, 2)-1);
v_ct_market_share := substr(out_v,
instr(out_v, ' ', 1, 3) + 1,
instr(out_v, ' ', 1, 4) - instr(out_v, ' ', 1, 3)-1);
v_cm_market_share := substr(out_v,
instr(out_v, ' ', 1, 4) + 1,
instr(out_v, ' ', 1, 5) - instr(out_v, ' ', 1, 4)-1);
v_other_market_share := substr(out_v,
instr(out_v, ' ', 1, 5) + 1,
length(out_v) - instr(out_v, ' ', 1, 5));
UPDATE i_exch_info
SET service_competition = v_service_competition,
cu_market_share = v_cu_market_share,
ct_market_share = v_ct_market_share,
cm_market_share = v_cm_market_share,
other_market_share = v_other_market_share
WHERE gwm_fid = v_id;
dbms_output.put_line(out_v);
END LOOP;
utl_file.fclose(v_file);
END p_xlstooracle;
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 【自荐】一款简洁、开源的在线白板工具 Drawnix