sql server 2005中怎么从一个不确定的sql中截取出表的名称?【哪个知道....急】(万分感激!!!)

解决方案 »

  1.   

    匹配.dbo.table_name 或 ..table_name
    前提是SQL的表名都有前缀。
      

  2.   

    用split 方法对空格分组   查看from是第几个字段  然后获取数组的 from字段所在的索引+1  就是表名前提是没有嵌套的sql  如果有嵌套就多加点判断  如N+1是否是"(" 等等  根据你的需求写吧!
      

  3.   

    have a try
    String sql = "select xxx from aaa, (select yyy from bbb, ccc, (select zzz from ddd) as mmm) as nnn where xxxx";
    Pattern p = Pattern.compile("(?i).*?\\s+from\\s+(([^()]+)([,)])).*?");
    Matcher m = p.matcher(sql);
    while (m.find()) {
        System.out.println(m.group(2));
    }