oracle SQL Plus 更改当前目录

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/509048/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 01:43:19  来源:igfitidea点击:

SQL Plus change current directory

oraclesqlplus

提问by Andrew Stein

How does one change the current directory in SQL Plus under windows.

windows下如何在SQL Plus中更改当前目录。

I am trying to write a script with several "@ filename" commands.

我正在尝试使用几个“@ filename”命令编写脚本。

I know that one can open a script with the File --> Open command, which will change the current directory, but I am looking for a way to do this automatically unattended.

我知道可以使用 File --> Open 命令打开一个脚本,该命令将更改当前目录,但我正在寻找一种自动无人值守的方法。



Resolution

解析度

Based on Plasmer's response, I set the SQLPATH environment variable in Windows, and got something that's good enough for me. I did not try to set it with the HOST command (I doubt that it will work).

根据 Plasmer 的响应,我在 Windows 中设置了 SQLPATH 环境变量,并得到了一些对我来说足够好的东西。我没有尝试使用 HOST 命令设置它(我怀疑它是否会起作用)。

Pourquoi Litytestdata's answer is a good one, but will not work for me (the directories are too far apart). And of course Guy's answer that it cannot be done is also correct. I will vote these two up, and accept Plasmer's answer.

Pourquoi Litytestdata 的回答很好,但对我不起作用(目录相距太远)。当然,盖伊的回答是不能完成的也是正确的。我会投票给这两个,并接受 Plasmer 的回答。

采纳答案by Plasmer

Could you use the SQLPATH environment variable to tell sqlplus where to look for the scripts you are trying to run? I believe you could use HOST to set SQLPATH in the script too.

您能否使用 SQLPATH 环境变量来告诉 sqlplus 在哪里查找您要运行的脚本?我相信您也可以使用 HOST 在脚本中设置 SQLPATH。

There could potentially be problems if two scripts have the same name and both directories are in the SQLPATH.

如果两个脚本具有相同的名称并且两个目录都在 SQLPATH 中,则可能会出现问题。

回答by Tom

Here is what I do.

这就是我所做的。

Define a variable to help you out:

定义一个变量来帮助你:

define dir=C:\MySYSTEM\PTR190\Tests\Test1

@&dir\myTest1.sql

You can't cdin SQL*Plus (you can cdusing the host command, but since it is a child process, the setting won't persist in your parent process).

您不能cd在 SQL*Plus 中cd使用(您可以使用 host 命令,但由于它是一个子进程,因此该设置不会保留在您的父进程中)。

回答by Luke Woodward

I don't think that you can change the directory in SQL*Plus.

我认为您不能更改 SQL*Plus 中的目录。

Instead of changing directory, you can use @@filename, which reads in another script whose location is relative to the directory the current script is running in. For example, if you have two scripts

您可以使用@@filename,而不是更改目录,它会读入另一个脚本,该脚本的位置相对于当前脚本正在运行的目录。例如,如果您有两个脚本

C:\Foo\Bar\script1.sql
C:\Foo\Bar\Baz\script2.sql

then script1.sqlcan run script2.sqlif it contains the line

然后script1.sql可以运行,script2.sql如果它包含该行

@@Baz\script2.sql

See thisfor more info about @@.

有关更多信息,请参阅内容@@

回答by Guy

I don't think you can!

我不认为你可以!

/home/export/user1 $ sqlplus / 
> @script1.sql
> HOST CD /home/export/user2
> @script2.sql

script2.sql has to be in /home/export/user1.

script2.sql 必须在/home/export/user1.

You either use the full path, or exit the script and start sqlplusagain from the right directory.

您要么使用完整路径,要么退出脚本并sqlplus从正确的目录重新开始。

#!/bin/bash
oraenv .
cd /home/export/user1
sqlplus / @script1.sql
cd /home/export/user2
sqlplus / @script2.sql

(something like that - doing this from memory!)

(类似的事情 - 从记忆中做这件事!)

回答by Chetan Sastry

Have you tried creating a windows shortcut for sql plus and set the working directory?

您是否尝试过为 sql plus 创建 Windows 快捷方式并设置工作目录?

回答by eRick

I think that the SQLPATH environment variable is the best way for this - if you have multiple paths, enter them separated by semi-colons (;). Keep in mind that if there are script files named the same in among the directories, the first one encountered (by order the paths are entered) will be executed, the second one will be ignored.

我认为 SQLPATH 环境变量是最好的方法 - 如果您有多个路径,请输入以分号 (;) 分隔的路径。请记住,如果目录中存在名称相同的脚本文件,则会执行遇到的第一个(按输入路径的顺序),第二个将被忽略。

回答by IOIO

Years later i had the same problem. My solution is the creation of a temporary batchfile and another instance of sqlplus:

多年后我遇到了同样的问题。我的解决方案是创建一个临时批处理文件和另一个 sqlplus 实例:

In first SQL-Script:

在第一个 SQL 脚本中:

:
set echo off
spool sqlsub_tmp.bat
prompt cd /D D:\some\dir
prompt sqlplus user/passwd@tnsname @second_script.sql
spool off
host sqlsub_tmp.bat
host del sqlsub_tmp.bat
:

Note that "second_script.sql" needs an "exit" statement at end if you want to return to the first one..

请注意,如果您想返回到第一个,“second_script.sql”在末尾需要一个“exit”语句。

回答by Kris Rice

With Oracle's new SQLcl there is a cd command now and accompanying pwd. SQLcl can be downloaded here: http://www.oracle.com/technetwork/developer-tools/sqlcl/overview/index.html

在 Oracle 的新 SQLcl 中,现在有一个 cd 命令和伴随的 pwd。SQLcl 可以在这里下载:http: //www.oracle.com/technetwork/developer-tools/sqlcl/overview/index.html

Here's a quick example:

这是一个快速示例:

SQL>pwd
/Users/klrice/
NOT_SAFE>!ls *.sql
db_awr.sql  emp.sql     img.sql     jeff.sql    orclcode.sql    test.sql
db_info.sql fn.sql      iot.sql     login.sql   rmoug.sql

SQL>cd sql
SQL>!ls *.sql
003.sql             demo_worksheet_name.sql     poll_so_stats.sql
1.sql               dual.sql            print_updates.sql

SQL>

回答by Dirk Schumacher

for me shelling-out does the job because it gives you possibility to run [a|any] command on the shell:

对我来说,shelling-out 可以完成这项工作,因为它使您可以在 shell 上运行 [a|any] 命令:

http://www.dba-oracle.com/t_display_current_directory_sqlplus.htm

http://www.dba-oracle.com/t_display_current_directory_sqlplus.htm

in short see the current directory:

简而言之,查看当前目录:

!pwd

!pwd

change it

更改

!cd /path/you/want

!cd /path/you/want