admin管理员组文章数量:1202334
my goal is to extract millions of data from a specific Oracle table, clean useless spaces (trim each element of the table) and join once again each value delimited by "|" into a new csv file.
The table named "tablename1":
----------COL1----------+----------COL2----------+----------COL3----------
row2Col1 | |12345
row3 Col1 |12345 |row3, col3
row4Col1 |row4 col2 |
...
...
I've found the code below (from .bat windows):
SET HEADING OFF
SET FEEDBACK OFF
SET ECHO OFF
SET VERIFY OFF
SET COLSEP '|'
SET TRIMSPOOL ON
set lines 1000
set pages 1000
SPOOL .\export\data_extraction.csv
SELECT LISTAGG(COLUMN_NAME, '|') WITHIN GROUP (ORDER BY COLUMN_ID)
FROM USER_TAB_COLUMNS
WHERE TABLE_NAME = 'tablename1';
SPOOL .\export\data_extraction.csv append;
select * from tablename1;
SPOOL OFF;
but opening the "data_extraction.csv" with Notepad++ the result seems to mantain the original columns formatting and, more, there are still spaces:
COL1|COL2|COL3
row1Col1 |row1 col2 |row1, col3
row2Col1 | |12345
row3 Col1 |12345 |row3, col3
row4Col1 |row4 col2 |
What i expect:
COL1|COL2|COL3
row1Col1|row1 col2|row1, col3
row2Col1||12345
row3 Col1|12345|row3, col3
row4Col1|row4 col2|
Is it possible to eventually run some additional and helpful powershell script to gain that?
Thanks in advance, Fab
my goal is to extract millions of data from a specific Oracle table, clean useless spaces (trim each element of the table) and join once again each value delimited by "|" into a new csv file.
The table named "tablename1":
----------COL1----------+----------COL2----------+----------COL3----------
row2Col1 | |12345
row3 Col1 |12345 |row3, col3
row4Col1 |row4 col2 |
...
...
I've found the code below (from .bat windows):
SET HEADING OFF
SET FEEDBACK OFF
SET ECHO OFF
SET VERIFY OFF
SET COLSEP '|'
SET TRIMSPOOL ON
set lines 1000
set pages 1000
SPOOL .\export\data_extraction.csv
SELECT LISTAGG(COLUMN_NAME, '|') WITHIN GROUP (ORDER BY COLUMN_ID)
FROM USER_TAB_COLUMNS
WHERE TABLE_NAME = 'tablename1';
SPOOL .\export\data_extraction.csv append;
select * from tablename1;
SPOOL OFF;
but opening the "data_extraction.csv" with Notepad++ the result seems to mantain the original columns formatting and, more, there are still spaces:
COL1|COL2|COL3
row1Col1 |row1 col2 |row1, col3
row2Col1 | |12345
row3 Col1 |12345 |row3, col3
row4Col1 |row4 col2 |
What i expect:
COL1|COL2|COL3
row1Col1|row1 col2|row1, col3
row2Col1||12345
row3 Col1|12345|row3, col3
row4Col1|row4 col2|
Is it possible to eventually run some additional and helpful powershell script to gain that?
Thanks in advance, Fab
Share Improve this question edited Jan 21 at 8:45 Olaf 5,2322 gold badges18 silver badges26 bronze badges asked Jan 21 at 8:02 FabfiscFabfisc 11 bronze badge 1- What are the table column types like? – vonPryz Commented Jan 21 at 8:17
1 Answer
Reset to default 0Try this.
Obviously the various "col1", "col2" etc should be replaced by the actual column names.
$CsvPath = '.\export\data_extraction.csv'
$TrimmedCols = @{Name = 'Col1'; Expression = { $_.Col1.trim() } },
@{Name = 'Col2'; Expression = { $_.Col3.trim() } },
@{Name = 'Col3'; Expression = { $_.Col2.trim() } }
$CsvPath | Import-Csv -Delimiter '|' -Header col1, col2, col3 |
Select-Object -Skip 1 -Property $TrimmedCols
本文标签:
版权声明:本文标题:database - Extract Oracle data to csv file (UTF8 and pipe "|" separator), trim and re-join into new file - Sta 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738647415a2104669.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论