基本上,您不需要PL / SQL。
表格:
SQL> create table test
2 (emp_id number,3 emp_first_name varchar2(20),4 emp_last_name varchar2(20),5 emp_salary number);
Table created.
代码:
SQL> insert into test (emp_id,emp_first_name,emp_last_name,emp_salary)
2 with
3 data (col) as
4 (select '1$shubham$tathe$5000#2$vijaj$bakse$10000#3$ram$sharma$200' from dual),5 red as
6 (select regexp_substr(col,'[^#]+',1,level) val,7 level lvl
8 from data
9 connect by level <= regexp_count(col,'#') + 1
10 ),11 emp as
12 (select regexp_substr(val,'\w+',1) emp_id,13 regexp_substr(val,2) emp_first_name,14 regexp_substr(val,3) emp_last_name,15 regexp_substr(val,4) emp_salary
16 from red
17 )
18 select * From emp;
3 rows created.
结果:
SQL> select * From test;
EMP_ID EMP_FIRST_NAME EMP_LAST_NAME EMP_SALARY
---------- -------------------- -------------------- ----------
1 shubham tathe 5000
2 vijaj bakse 10000
3 ram sharma 200
SQL>
如果必须是一个过程,也没问题。
程序:
SQL> rollback;
Rollback complete.
SQL> create or replace procedure p_test (par_col in varchar2) is
2 begin
3 insert into test (emp_id,emp_salary)
4 with
5 red as
6 (select regexp_substr(par_col,7 level lvl
8 from dual
9 connect by level <= regexp_count(par_col,'#') + 1
10 ),11 emp as
12 (select regexp_substr(val,13 regexp_substr(val,14 regexp_substr(val,15 regexp_substr(val,4) emp_salary
16 from red
17 )
18 select * From emp;
19 end;
20 /
Procedure created.
测试:
SQL> exec p_test('1$shubham$tathe$5000#2$vijaj$bakse$10000#3$ram$sharma$200');
PL/SQL procedure successfully completed.
SQL> select * From test;
EMP_ID EMP_FIRST_NAME EMP_LAST_NAME EMP_SALARY
---------- -------------------- -------------------- ----------
1 shubham tathe 5000
2 vijaj bakse 10000
3 ram sharma 200
SQL>
本文链接:https://www.f2er.com/3157708.html