ODACを使用してOracle CLOBでXMLを読み書きするために過去に行ったことは次のとおりです。これは、わずかな変更で NCLOB に対して機能するはずです。
# Load ODAC. This might fail if it is not installed or is the wrong bitness.
$assembly = [System.Reflection.Assembly]::LoadWithPartialName("Oracle.DataAccess")
# Connect to Oracle.
$connStr = 'Data Source=hostname:1521/sidname; User Id=sys; Password=password; DBA Privilege=SYSDBA;'
$conn = New-Object Oracle.DataAccess.Client.OracleConnection -ArgumentList $connStr
$conn.Open()
# Query the table.
$q = "select MY_CLOB_FIELD from My_Table"
$command = new-object Oracle.DataAccess.Client.OracleCommand($q, $conn)
# Process records.
$reader = $command.ExecuteReader()
while ($reader.Read()) {
# Read the CLOB field and cast to an XML document.
$xmlDoc = [xml] $reader.getstring(0) # XML
#... XML Processing Here ....
# Commit the updated XML.
$sql = "UPDATE My_Table SET MY_CLOB_FIELD = :1"
$updateCmd = New-Object Oracle.DataAccess.Client.OracleCommand ($sql, $conn)
$param = New-Object Oracle.DataAccess.Client.OracleParameter (
"xml", #Name
[Oracle.DataAccess.Client.OracleDbType]::Clob, #Type
$xmlDoc.OuterXml, #Data
'Input' #Direction
)
$newParam = $updateCmd.Parameters.Add($param)
$result = $updateCmd.ExecuteNonQuery()
}