OracleのネイティブクエリをDenodoで動作するように整形する
Xはスペース、ピリオド
Yはスペース、カンマ、行末
-- 1. 使用カラムの取得
事前定義のストアドを使用してカラム一覧を大文字で取得する
select upper(column_name) from GET_VIEW_COLUMNS('db02','b_tab1');
-- 2. シェル
シェル本体: a.sh
カラム一覧: a.txt
クエリ: a.sql
vim a.txt
COL1
COL2
COL3
COL4
COL5
COL6
COL7
cat a.txt
SELECT
COL1 COL1,
col2 ,
col3 AS AAA,
T1.COL4,
col5
FROM B_TAB1 T1
ORDER BY
COL1,
COL2,
COL3
;
cat a.sql
vim a.sh
#!/bin/bash
OLDIFS=$IFS
IFS=$'\n'
for i in $(cat a.txt); do
sed -i -E "s/([. ])(${i})([,\r ]|$)/\1\"${i}\"\3/gi" a.sql
sed -i -E "s/([. ])(${i})([,\r ]|$)/\1\"${i}\"\3/gi" a.sql
done
IFS=$OLDIFS
exit 0
--
cat a.sh
chmod +x a.sh
./a.sh
cat a.sql
-- 3. パワーシェル
シェル本体: a.ps1
カラム一覧: a.txt
クエリ: a.sql
notepad a.txt
COL1
COL2
COL3
COL4
COL5
COL6
COL7
cat a.txt
notepad a.sql
SELECT
COL1 COL1,
col2 ,
col3 AS AAA,
T1.COL4,
col5
FROM B_TAB1 T1
ORDER BY
COL1,
COL2,
COL3
;
cat a.sql
notepad a.ps1
Write-Output $null > b.sql
foreach ($i in Get-Content a.sql) {
foreach ($k in Get-Content a.txt) {
$i = $i -replace "([\. ])($k)([, ]|$)", "`$1""$k""`$3"
$i = $i -replace "([\. ])($k)([, ]|$)", "`$1""$k""`$3"
}
Write-Output $i >> b.sql
}
--
cat a.ps1
.\a.ps1
cat b.sql