我有一组非常庞大且令人讨厌的查询,我想从中提取列名,它们都将采用以下格式<table>.<column>
我是正则表达式的新手,似乎看不到我的模式匹配失败的地方,它不会返回任何东西。
# Read file in and parse out all column names, they must be of the
# form <table>.<column>
$data_file="C:\\VW_DEP_MTHLY_PROJTD_UNPROJTD_STK_FACT.sql";
open SQL_FILE, $data_file or die "Could not open file: $data_file";
while (<SQL_FILE>) {
if((/ \w+\.\w+/)) {
print $1;
}
}
close SQL_FILE;
您可以像这样想象部分查询:
SELECT PHARMACY_FACT.REC_TYP_ID,
PHARMACY_FACT.PACK_ID,
("VARCHAR"(DATE_PART('YEAR'::"VARCHAR", ASSET.MTHLY_CYC_END_DT)) || LPAD("VARCHAR"(ASSET.IMS_CYC_WK_NBR), 2, '0'::"VARCHAR")) AS IMS_CYC_WK_NBR,
ASSET.WKLY_CYC_END_DT,
PHARMACY_FACT.TAX_PCT_RT,
CASE WHEN ((CASE WHEN (PHARMACY_FACT.INDIR_PUR_AMT NOTNULL) THEN PHARMACY_FACT.INDIR_PUR_AMT WHEN (0 NOTNULL) THEN '0'::"NUMERIC"
ELSE NULL::"NUMERIC"
END + CASE WHEN (PHARMACY_FACT.DIR_PUR_AMT NOTNULL) THEN PHARMACY_FACT.DIR_PUR_AMT WHEN (0 NOTNULL) THEN '0'::"NUMERIC"
ELSE NULL::"NUMERIC"
END) <> '0'::"NUMERIC") THEN (CASE WHEN (PHARMACY_FACT.INDIR_PUR_AMT NOTNULL) THEN PHARMACY_FACT.INDIR_PUR_AMT WHEN (0 NOTNULL) THEN '0'::"NUMERIC"
ELSE NULL::"NUMERIC"
END + CASE WHEN (PHARMACY_FACT.DIR_PUR_AMT NOTNULL) THEN PHARMACY_FACT.DIR_PUR_AMT WHEN (0 NOTNULL) THEN '0'::"NUMERIC"
ELSE NULL::"NUMERIC"
END)
ELSE NULL::"NUMERIC"
END AS UNPRJ_TOT_PUR_AMT
...