Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.8k views
in Technique[技术] by (71.8m points)

oracle - Make SQL*Plus script quit

I have a few SQL*Plus scripts in a directory that I would like to run automatically using powershell. I can read the directory and but when I tried to execute the script, the scripts terminated but did not quit powershell and go to the next one.

How do I make powershell quit SQL*Plus and go to the next script automatically without me modifying the scripts by explicitly adding a quit at the end of each script?

Below is the illustrated powershell script in its simplest form

$Filename=Get-childitem "D:estTestSQL" -Filter *.sql | Select -ExpandProperty name
foreach ($f in $Filename)
{
  sqlplus -L -S <username>/<password>@<sid> @$f
}

The directory can theoretically contain hundreds of scripts and it is not feasible to add quit command in each script. I would like to force SQL*Plus to quit after completing each script and move on to the next one.

Is it possible to do that?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I'm not familiar plsql but I gather that sqlplus is an exe that executes plsql scripts. If PowerShell is not continuing to the next script it is because sqlplus is not exiting. A little googling suggests that the proper way to end a pssql script is to put a single forward slash on the last line:

/

From what I understand this tells sqlplus to execute everything above, without it sqlplus will not terminate.

You say:

it is not feasible to add quit command in each script

But as far as I can tell that is exactly what you have to do.

Luckily PowerShell can help with that too. Just navigate to the directory containing the scripts and execute the following:

dir *.sql | add-content -value "/"

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share

2.1m questions

2.1m answers

63 comments

56.5k users

...