URL Params使用Oracle拆分

时间:2014-03-26 05:42:41

标签: sql oracle

我有一个保存在特定列中的页面的URL参数,如下所示:

    Query_Params

    type=Outstanding%20Trade%20Ticket%20Report1&fileName=Outstanding%20Trade%20Ticket%20Report_3%20Mar%2014.xlsx
    type=Outstanding%20Trade%20Ticket%20Report2&fileName=Outstanding%20Trade%20Ticket%20Report_3%20Mar%2014.xlsx

我需要编写一个Oracle Query,它将输出返回两列,如下所示。

                Type                                                fileName

    Outstanding%20Trade%20Ticket%20Report1       Outstanding%20Trade%20Ticket%20Report_3%20Mar%2014.xlsx
    Outstanding%20Trade%20Ticket%20Report2       Outstanding%20Trade%20Ticket%20Report_3%20Mar%2014.xlsx

应用程序设计使得这两个参数在插入数据时不能存储为2个不同的列。

我还没能找到select语句的正则表达式。

我该怎么做?

1 个答案:

答案 0 :(得分:0)

如果您希望将结果分成两列:

SQL> set define off;
SQL> SELECT regexp_substr('type=Outstanding%20Trade%20Ticket%20Report1&fileName=Outstanding%20Trade%20Ticket%20Report_3%20Mar%2014.xlsx', '^[^&]+') A,
  2  regexp_substr('type=Outstanding%20Trade%20Ticket%20Report1&fileName=Outstanding%20Trade%20Ticket%20Report_3%20Mar%2014.xlsx', 'fileName(.+)') b
  3  from dual;

输出

   | A                                           |B                                                                 |
   |---------------------------------------------|------------------------------------------------------------------|
   |type=Outstanding%20Trade%20Ticket%20Report1  | fileName=Outstanding%20Trade%20Ticket%20Report_3%20Mar%2014.xlsx |

您的查询将

SQL> set define off;
SQL> SELECT regexp_substr(column_name, '^[^&]+') A,
  2  regexp_substr(columns_name, 'fileName(.+)') b
  3  from table_name;