Benutzer-Werkzeuge

Webseiten-Werkzeuge


windows:powershell_sqlplus_db_abfragen

Unterschiede

Hier werden die Unterschiede zwischen zwei Versionen angezeigt.

Link zu dieser Vergleichsansicht

Beide Seiten der vorigen RevisionVorhergehende Überarbeitung
Nächste Überarbeitung
Vorhergehende Überarbeitung
Letzte ÜberarbeitungBeide Seiten der Revision
windows:powershell_sqlplus_db_abfragen [2017/12/01 16:52] gpipperrwindows:powershell_sqlplus_db_abfragen [2017/12/01 17:11] – [Auslesen] gpipperr
Zeile 85: Zeile 85:
  
 Variante 12c R2 SQL*Plus mit der „set markup csv“ Formatierung: Variante 12c R2 SQL*Plus mit der „set markup csv“ Formatierung:
-<code powershell>+ 
 +<code powershell getData.ps1>
  
 #============================================================================== #==============================================================================
Zeile 163: Zeile 164:
  
  
-===Einlesen===+===Einlesen der CSV Daten=== 
 + 
 +SQL Beispiel mit einem Update 
 + 
 +<code powershell updateData.ps1 >
  
-<code powershell> 
 #============================================================================== #==============================================================================
-# Desc:   write data to the oracle database with sqlplus +# Author: Gunther Pippèrr ( http://www.pipperr.de ) 
-# Date:   01.12.2017+# Desc:   Library for the Oracle Data import / Export  scripts 
 +# Date:   01.Dezember 2017 
 +# Site:   http://orapowershell.codeplex.com
 #============================================================================== #==============================================================================
  
 <# <#
   .NOTES   .NOTES
- Created: 01.2017 :+ Created: 11.2017 :
  .SYNOPSIS  .SYNOPSIS
  write data to the oracle database with sqlplus  write data to the oracle database with sqlplus
Zeile 183: Zeile 189:
  
 #============================================================================== #==============================================================================
-Enviroment+Environment
 #============================================================================== #==============================================================================
 Set-Variable CONFIG_VERSION "0.2" -option constant Set-Variable CONFIG_VERSION "0.2" -option constant
  
-# Set enviroment +# Rember the script path to find the csv 
-$oracle_home="C:\oracle\instantclient_12_2"+$Invocation = (Get-Variable MyInvocation -Scope 0).Value 
 +$scriptpath=Split-Path $Invocation.MyCommand.Path 
 + 
 +$starttime=get-date 
 + 
 +write-host "Info -- start the Script in the path $scriptpath at $starttime"  -ForegroundColor "green"  
 + 
 +cd  $scriptpath # Set working directory if executed as job 
 + 
 +# My local Settings 
 + 
 +$oracle_home="C:\oracle\products\12.2.0.1\client_64"
 $sql_connect_string="gpi/gpi@gpidb" $sql_connect_string="gpi/gpi@gpidb"
-$data_csv="C:\s-akaby\userPWDImport.csv"+$data_csv="$scriptpath\userDataImport.csv"
  
  
-#set Oracle HOME variable+# set the Oracle HOME variable
 try { try {
- set-item -path env:ORACLE_HOME -value $oracle_home+  set-item -path env:ORACLE_HOME -value $oracle_home
 } }
 catch { catch {
- new-item -path env: -name ORACLE_HOME -value $oracle_home+   new-item -path env: -name ORACLE_HOME -value $oracle_home
 } }
   
-#read input+  
 +#============================================================================== 
 +#read the data input
 $input_csv = Get-Content "$data_csv" $input_csv = Get-Content "$data_csv"
  
-# loop over each line+# loop over each line of the data input
  
 foreach( $line in $input_csv ) foreach( $line in $input_csv )
 { {
-#debug 
-#write-host $line  
  
-#split the csv + #debug 
-$val1,$val2,$val3 = $line.split(' ')+ #write-host $line  
 +  
 + #check for empty lines and skip this lines 
 + for ($line.length() -le 5) {  
 +     # exit from this iteration round 
 + continue 
 + }
  
-#debug + split the csv 
-$val1="'$val1'" +  
-write-host $val1 + $val1,$val2,$val3 = $line.split('|')
-$val2="'$val2'" +
-write-host $val2 +
-$val3="'$val3'+
-write-host $val3+
  
-$command="select $val1 as val1, $val2 as val2, $val3 as val3 from dual;"+ #debug 
 + write-host $val1 
 + write-host $val2 
 + write-host $val3
  
-#Write  the data with sqlplus + $command="update dataTab set val1='$val1' , val2='$val2' where val3='$val3'" 
 + 
 +# Write  the data with sqlplus  
 +# must be on start of line!!
 $writeData=@" $writeData=@"
 set pagesize 0  set pagesize 0 
Zeile 233: Zeile 258:
 "@| & "$env:ORACLE_HOME\sqlplus" -s "$sql_connect_string" "@| & "$env:ORACLE_HOME\sqlplus" -s "$sql_connect_string"
  
-try { + # trim the response 
-  $writeData=$writeData.trim() + try { 
-+   $writeData=$writeData.trim() 
-catch { +
-   write-host "Object is empty - check your code"+ catch { 
 +    write-host "Object is empty - check your code" 
 +
 + 
 + #DEBUG 
 + write-host $writeData 
 } }
  
-#DEBUG +$stoptime=get-date 
-write-host $writeData+write-host "Info -- finsh the Script at $stoptime"  -ForegroundColor "green"
  
-} 
  
 #============================= End of File ==================================== #============================= End of File ====================================
windows/powershell_sqlplus_db_abfragen.txt · Zuletzt geändert: 2017/12/01 17:16 von gpipperr