最近在做一个小的自用项目,里面有一段 Sql:
string = "SELECT PROD_CODE,SUM(TTL_AMT) AS SUM_AMT FROM PRODMSTR A INNER JOIN (SELECT PROD_KEY,TTL_AMT FROM SaleDetail WHERE ENTRY_DATE > '20150601') B ON A.PROD_KEY = B.PROD_KEY WHERE EXISTS ( SELECT BRND_CODE FROM CodeBrand C WHERE A.BRND_CODE = C.BRND_CODE AND BRND_DESC = 'BRAND_NAME') GROUP BY PROD_CODE ORDER BY PROD_CODE"
这部分 sql 想变成数组进行处理,最终想得出一个数组,为如下结果:
string_split_result
=>["SELECT",
"PROD_CODE,SUM(TTL_AMT) AS SUM_AMT",
"FROM",
"PRODMSTR",
"A",
"INNER JOIN",
"(SELECT PROD_KEY,TTL_AMT FROM SaleDetail WHERE ENTRY_DATE > '20150601') ",
"B",
"ON ",
"A.PROD_KEY = B.PROD_KEY",
"WHERE",
"EXISTS ( SELECT BRND_CODE FROM CodeBrand C WHERE A.BRND_CODE = C.BRND_CODE AND BRND_DESC = 'BRAND_NAME')",
"GROUP BY",
"PROD_CODE",
"ORDER BY",
"PROD_CODE"]
想请教一下各位,应该用什么思路来处理?
补充应用场合:
我自己在做一个独立逻辑测试单元,用途是把目前现有系统产生的 SQL 查询语句结果提取出来,转换成数组重新进行组合或拼接处理。最终依赖这个数组:
1:靠系统提取出主查询表和 JOIN 表。然后自动产生对这些表的 COUNT 查询语句。 2:查询相应字段的表结构,如果是数字类型,则生成数字汇总 SQL 语句。 3:生成除去 join 的 SQL 语句。
二次生成以后,再执行这些 Sql 语句去获取数据。