说明:在这题之前我已经出了一题,大家答这题之前可以做下那个题,那个题的部分逻辑这道题中会用到。http://bbs.itheima.com/forum.php ... mp;extra=#pid742205
已知有字符char a[]="select * from (select * from heima1, (select c, d from temp1 t1,(select g from heima1 h1,temp1 t where g=1) t2 where t1.a=t2.b and t1 in (select f from itcast )))";
学过sql的同学可以看出上面是一个sql语句,含有子查询嵌套的sql,在oracle数据库开发中可能一条sql就是几千行,有时候需要对其中的表和字段进行分析,要找出其中的表名,也就是把里面的表名提取出来,用from关键字来查表显然很麻烦,现在就需要一个程序很方便将表名提取出来。下面是条件
1,写一个程序找出所有表名
2,表名不能有重复
3,只取出表名它的别名不要弄出来比如temp t1只取出temp
4,最后结果按字母顺序排序。
执行结果如下即正确
heima1
itcast
temp1
著名:上面sql逻辑不要管它肯定会产生笛卡尔积,另外此题如不严谨后面会完善
// Copyright (c) 2014 itcast. All rights reserved.
//
#include <stdio.h>
#include <string.h>
char a[]={"select * from (select * from heima1,(select c, d from temp1 t1,(select g from heima1 h1,temp1 t where g=1) t2 where t1.a=t2.b and t1 in (select f from itcast )))"};