I need to write a query to display multiple rows from DB in tabular format using PowerShell script (sqlplus command).
Database: Oracle 12c
I wrote the below query, but it returns single row value. How can I get all the data? I am not understanding how to implement for loop to access all rows.
Expected output:
Script:
$username='root'
$password='password'
$tnsalias='localhost:1521/xe'
$sql1=@"
set echo off;
set pagesize 0
set head off;
set feedback off;
set pause off;
set verify off;
set trimspool on;
set linesize 300;
set colsep ,;
set termout off;
SELECT * FROM employees where dept_id =30;
"@
$output1 = $sql1 |sqlplus -silent $username/$password@$tnsalias
$output2 =$output1.Split(",")
$eid=$output2[0]
$first_nm=$output2[1]
$middl_nm=$output2[2]
$last_nm=$output2[3]
$sal= $output2[4]
$HtmlTable3 += "<tr style='font-size:13px;background-color:#FFFFFF'>
<td>"+ $eid +"</td>
<td>" + $first_nm + "</td>
<td>"+ $middl_nm +"</td>
<td>"+ $last_nm+"</td>
<td>"+ $sal +"</td>
</tr> "
$HtmlTable3 +="</table> </div>"
write-host $HtmlTable3
