Hi Guys,
I’ve ran into an issue that I can’t seem to find any answers to so maybe you can help me out:
I have a table in SQL
Column1|Column2|Column3|Column4|Column5
I am importing data from a *.csv file into a SQL table using the following code
$CsvPath = "C:\Temp\File.csv"
$Csv = Import-Csv $CsvPath -Delimiter ";"
Add-Type -Path "C:\ProgramData\oracle\odp.net\bin\4\Oracle.DataAccess.dll"
$ConStr = New-Object Oracle.DataAccess.Client.OracleConnection("User Id=;Password=;Data Source=")
$CMD = $ConStr.CreateCommand()
$ConStr.Open()
foreach ($Item in $Csv)
{
$Col1 = $Item.col1
$Col2 = $Item.col2
$Col3 = $Item.col3
$Col4 = $Item.col4
$Col5 = $Item.col5
## Insert data in table FOLDER_PERMISSION
$CMD.CommandText = "INSERT INTO (Col1 ,Col2 ,Col3 ,Col4 ,Col5 ) VALUES('{0}','{1}','{2}','{3}','{4}')" -f "$Col1", "$Col2", "$Col3 ", "$Col4", "$Col5"
$CMD.executenonquery()
}
$ConStr.close()
This works nicely until I encounter a large string in Column5 and it throws an error, and then again I have found a workaround for this directly in SQL:
cCol5 clob :=
begin
insert into
(col1,col2,col3,col4,col5)
values
('Test Value',
'Test Value2',
'Test Value3',
cCol5
);
So this little peace of code works in SQL and I have no clue how to translate this in a SQL powershell statement that would do the same thing from PS.
I have tried the following with no result:
...
$CMD.CommandText = "
cCol5 clob :=
begin
insert into
(col1,col2,col3,col4,col5)
values
('Test Value',
'Test Value2',
'Test Value3',
cCol5
);
"
...
Any and all help will be useful, please let me know if further details are required.
Regards,
Sergiu Creifelean