1

我有一个表格,其中有一列类型为 varchar2(4000)。该列包含我想使用正则表达式检索表名的查询。

前任:

 create table sam ( query_1 varchar2(4000)); 

数据为:

insert into sam values(
'select ename e, empno d , sal f,dname from emp e, dept d where e.deptno=d.deptno');
insert into sam values(
'SELECT B.DN,  A.DN , C.BN FROM A.DoG,   b.caT,  C.rAt')

如何将 query_1 列中的表名检索到另一个表中?

4

2 回答 2

0

这将为单行完成工作,但在选择多行时无法正常工作。也许比我更熟练的人可以改进这一点:

select
  regexp_substr(c.split, '\S+') as table_name
from (
  select 
    regexp_substr(b.match, '[^,]+', 1, rownum) as split 
  from (
    select
      regexp_replace(regexp_substr(query_1, 'from.+?(where|group|order|$)', 1, 1, 'i'), '(from|where|group|order)', '', 1, 0, 'i') as match
    from
     sam
  )b
   connect by level <= length (regexp_replace (b.match, '[^,]+'))  + 1
) c
于 2013-02-04T22:03:27.993 回答
0

您不能在直接的 Oracle SQL 中执行此操作。您不能有动态表或列名。您将需要使用 PL/SQL 和Dynamic SQL

于 2013-02-05T01:54:42.637 回答