0

我有一个列名为“REMARKS”的表 temp

创建脚本

Create table temp (id number,remarks varchar2(2000));

插入脚本

Insert into temp values (1,'NAME =GAURAV Amount=981 Phone_number =98932324 Active Flag =Y');
Insert into temp values (2,'NAME =ROHAN Amount=984 Phone_number =98932333  Active Flag =N');

现在,我想从表的备注栏中获取 NAME 、Amount 、phone_number、active_flag 的对应值。

我想过使用正则表达式,但我不习惯使用它。我尝试使用 substr 和 instr 从 remakrs 列中获取名称,但如果我想获取所有四个,我需要编写一个 pl sql。我们可以使用正则表达式来实现这一点。

我能得到像这样的输出(CURSOR)吗

id  Name    Amount phone_number Active flag
------------------------------------------
1  Gaurav   981    98932324     Y
2  Rohan    984    98932333     N
-------------------------------------------

谢谢你的帮助

4

1 回答 1

1

你可以使用类似的东西:

SQL> select regexp_replace(remarks, '.*NAME *=([^ ]*).*', '\1') name,
  2         regexp_replace(remarks, '.*Amount *=([^ ]*).*', '\1') amount,
  3         regexp_replace(remarks, '.*Phone_number *=([^ ]*).*', '\1') ph_number,
  4         regexp_replace(remarks, '.*Active Flag *=([^ ]*).*', '\1') flag
  5    from temp;

NAME                 AMOUNT               PH_NUMBER            FLAG
-------------------- -------------------- -------------------- --------------------
GAURAV               981                  98932324             Y
ROHAN                981                  98932324             N
于 2013-03-20T15:37:27.687 回答