|
houen
初级用户
 
积分 139
发帖 13
注册 2005-4-6
状态 离线
|
『楼 主』:
这样的批处理文件该怎么写
使用 LLM 解释/回答一下
auto.bat 内容为:(目的是在oracle数据库里自动建一张表)
sqlplus system/manager
create table a (a varchar2(10));
exit
但是当执行完第一句后,就进入了sqlplus模式,这时批处理文件已经无法向下执行了,如何才能解决这个问题呢?请高手赐教!谢谢!
The content of auto.bat is: (The purpose is to automatically create a table in the oracle database)
sqlplus system/manager
create table a (a varchar2(10));
exit
But after executing the first sentence, it enters the sqlplus mode, and then the batch processing file can no longer execute downward. How can this problem be solved? Please expert give advice! Thank you!
|
|
2005-4-6 00:00 |
|
|
Climbing
铂金会员
       网络独行侠
积分 6962
发帖 2753
注册 2003-4-16 来自 河北保定
状态 离线
|
『第 2 楼』:
使用 LLM 解释/回答一下
将后两句放入一个SQL文件中,然后用sqlplus执行这个SQL文件即可。例如:set tmpsql=%temp%\tmp.sql
> %tmpsql% echo create table a (a varchar2(10));
>> %tmpsql% echo exit
sqlplus system/manager @%tmpsql%
del %tmpsql%
set tmpsql=
Put the last two sentences into a SQL file, and then execute this SQL file with sqlplus. For example:
set tmpsql=%temp%\tmp.sql
> %tmpsql% echo create table a (a varchar2(10));
>> %tmpsql% echo exit
sqlplus system/manager @%tmpsql%
del %tmpsql%
set tmpsql=
|

偶只喜欢回答那些标题和描述都很清晰的帖子!
如想解决问题,请认真学习“这个帖子”和“这个帖子”并努力遵守,如果可能,请告诉更多的人!
|
|
2005-4-6 00:00 |
|
|
houen
初级用户
 
积分 139
发帖 13
注册 2005-4-6
状态 离线
|
『第 3 楼』:
使用 LLM 解释/回答一下
楼上的,谢谢你的方法,是可以的,但是还是不太明白为什么要这么写?能不能讲讲set tmpsql=%temp%\tmp.sql tmp.sql是什么意思?做什么用的?%temp%呢
> %tmpsql% echo create table a (a varchar2(10)); > 和 >>是什么区别?
>> %tmpsql% echo exit
还有就是如果sqlplus后面我不输入system/manager ,而是在提示输入用户名的是后通过echo送用户名,然后回车,再提示密码的时候回送密码,可不可以?如果可以又该怎么写呢?谢谢,期待中……
Upstairs, thank you for your method, it works, but I still don't quite understand why it's written like this? Can you explain what tmp.sql means? What's it for? What about %temp%
> %tmpsql% echo create table a (a varchar2(10)); > What's the difference between > and >>?
>> %tmpsql% echo exit
Also, if I don't enter system/manager after sqlplus, but when prompted to enter the username, send the username via echo, then press Enter, and when prompted for the password, send the password, can it be done? If it can, how to write it? Thanks, looking forward to it...
|
|
2005-4-7 00:00 |
|
|
Climbing
铂金会员
       网络独行侠
积分 6962
发帖 2753
注册 2003-4-16 来自 河北保定
状态 离线
|
『第 4 楼』:
使用 LLM 解释/回答一下
你问的问题都属于DOS的基础知识,如果要给你讲明白,恐怕要讲上几个小时。你可以去认真学习一下本论坛的置顶帖子。
The questions you asked all belong to the basic knowledge of DOS. If I want to explain them clearly to you, it might take several hours. You can go and study the sticky posts of this forum carefully.
|

偶只喜欢回答那些标题和描述都很清晰的帖子!
如想解决问题,请认真学习“这个帖子”和“这个帖子”并努力遵守,如果可能,请告诉更多的人!
|
|
2005-4-8 00:00 |
|
|
houen
初级用户
 
积分 139
发帖 13
注册 2005-4-6
状态 离线
|
『第 5 楼』:
使用 LLM 解释/回答一下
谢谢Climbing。我看了一些资料,了解了一些知识: > 、>> 输出重定向命令如果使用的是 > ,原文件会被删除,重新生成新的文件,其内容如上所述;如果使用的是 >> ,原文件内容会被保留,新的内容会添加到原文件件的内容的后面批处理文件还可以像C语言的函数一样使用参数(相当于DOS命令的命令行参数),需要用到一个参数表示符“%”。但是对于 set tmpsql=%temp%\tmp.sql
> %tmpsql% echo create table a (a varchar2(10));
>> %tmpsql% echo exit
还是不是很理解?我想这几句的意思应该是将create table a (a varchar2(10));和exit写到tem.sql文件中。但是set tmpsql的tmpsql和> %tmpsql%中的tmpsql是什么关系?%temp%是参数吗?那什么地方给它传递值了呢?还有就是“sqlplus后面我不输入system/manager ,而是在提示输入用户名的是后通过echo送用户名,然后回车,再提示密码的时候回送密码”这样的例子好象没有能够找到,能不能再指点指点?谢谢!
Thanks Climbing. I read some materials and learned some knowledge: The output redirection commands > and >>. If > is used, the original file will be deleted and a new file will be recreated, and its content is as described above; if >> is used, the content of the original file will be retained and the new content will be added to the back of the content of the original file. Batch files can also use parameters like functions in the C language (equivalent to command-line parameters of DOS commands), and a parameter identifier "%" is needed. But for set tmpsql=%temp%\tmp.sql
> %tmpsql% echo create table a (a varchar2(10));
>> %tmpsql% echo exit
I still don't understand very well? I think the meaning of these few sentences should be to write create table a (a varchar2(10)); and exit into the tem.sql file. But what is the relationship between tmpsql in set tmpsql and tmpsql in > %tmpsql%? Is %temp% a parameter? Then where is the value passed to it? Also, the example like "I don't enter system/manager after sqlplus, but when prompted to enter the username, send the username through echo, then press Enter, and when prompted for the password, send the password" seems not to be found. Can you give more guidance? Thanks!
|
|
2005-4-12 00:00 |
|
|
Climbing
铂金会员
       网络独行侠
积分 6962
发帖 2753
注册 2003-4-16 来自 河北保定
状态 离线
|
『第 6 楼』:
使用 LLM 解释/回答一下
%temp%是引用环境变量的方法,例如系统中有一个环境变量为temp,那么使用这个环境变量的方法就是使用%temp%来引用。假设temp=d:\temp,那么%temp%就表示D:\temp,这样你明白了吗?
理解了环境变量,那么你就可以理解tmpsql的作用,我建立这个环境变量用来保存临时生成的sql文件,而后面的:
> %tmpsql% echo create table a (a varchar2(10));
>> %tmpsql% echo exit
就是用来生成这个临时的SQL文件,然后通过SQLPlus运行它。
至于你所说的用echo来输入用户名和密码是不行的,我只能说:用“sqlplus 用户名/密码”的方式是最标准的,当然你也可以在SQL文件中使用“connect 用户名/密码”的方式,但绝对不是你想象的使用echo输入用户名和密码,这只是你想当然吧!
%temp% is a way to reference an environment variable. For example, if there is an environment variable named temp in the system, the way to use this environment variable is to use %temp% to reference it. Suppose temp = d:\temp, then %temp% means D:\temp. Do you understand this?
After understanding environment variables, then you can understand the role of tmpsql. I created this environment variable to save the temporarily generated SQL file, and the following:
> %tmpsql% echo create table a (a varchar2(10));
>> %tmpsql% echo exit
is to generate this temporary SQL file, and then run it through SQLPlus.
As for what you said about using echo to enter the username and password, it won't work. I can only say: The way of "sqlplus username/password" is the most standard. Of course, you can also use "connect username/password" in the SQL file, but definitely not using echo to enter the username and password, this is just your wishful thinking!
|

偶只喜欢回答那些标题和描述都很清晰的帖子!
如想解决问题,请认真学习“这个帖子”和“这个帖子”并努力遵守,如果可能,请告诉更多的人!
|
|
2005-4-13 00:00 |
|
|
houen
初级用户
 
积分 139
发帖 13
注册 2005-4-6
状态 离线
|
『第 7 楼』:
使用 LLM 解释/回答一下
谢谢Climbing原来是这个意思!至于我所说的用echo来输入用户名和密码,实际的目的就是想通过一个批处理文件或一条dos命令来测试出sqlplus是不是能正常工作(执行完后同时能够退出sqlplus,返回dos命令模式)。因为当sqlplus正常工作时输入正确的用户名密码后就进入sqlplus工作模式,能够响应正常的sql语句,我可以通过exit退出sqlplus模式;但是如果用户名密码不正确,或者sqlplus不能正常工作时,会要求输入3次用户名密码才能退出返回dos命令模式,此时我输入exit它会认为是输入的用户名,只有连续几次回车后才能退出!不知道我这么讲你是不是明白?能实现吗?
Thanks, Climbing turns out to be this meaning! As for what I said about using echo to input the username and password, the actual purpose is to test whether sqlplus can work normally through a batch file or a single DOS command (and at the same time be able to exit sqlplus and return to the DOS command mode after execution). Because when sqlplus works normally, after entering the correct username and password, it enters the sqlplus working mode and can respond to normal SQL statements, and I can exit sqlplus mode through exit; but if the username or password is incorrect, or sqlplus cannot work normally, it will require entering the username and password 3 times to exit and return to the DOS command mode. At this time, if I enter exit, it will think it is the entered username, and I can only exit after pressing the Enter key several times continuously! I don't know if you understand what I'm talking about? Can it be achieved?
|
|
2005-4-13 00:00 |
|
|
Climbing
铂金会员
       网络独行侠
积分 6962
发帖 2753
注册 2003-4-16 来自 河北保定
状态 离线
|
『第 8 楼』:
使用 LLM 解释/回答一下
我明白你的意思,针对你所提的要求,我进行了实际的测试,我发现通过sqlplus @xxx.sql这种方式确实存在用户名和密码不正确要输入三次回车才能退出这种情况,然后我又测试了其它几种方式(我使用的oracle 是oracle 8.1.6),基本上可以满足你的要求。第一种方式:仍然使用sqlplus @xxx.sql的方式,但xxx.sql内容要变成这样,即三个用户名和密码组合:
system/manager
system/manager
system/manager
exit第二种方式:使用sqlplus < xxx.txt,xxx.txt内容:
system/manager
exit
第三种方式:type xxx.txt | sqlplus,xxx.txt内容同上。
第四种方式:使用echo也是可以的,如果用户名和密码不正确,可以直接退出。
echo system/manager | sqlplus
I understand what you mean. For the requirements you mentioned, I conducted actual tests and found that when using the sqlplus @xxx.sql method, there is indeed a situation where you need to press Enter three times to exit if the username and password are incorrect. Then I tested several other methods (I am using Oracle 8.1.6), and basically they can meet your requirements. The first method: still use the sqlplus @xxx.sql method, but the content of xxx.sql should be like this, that is, three username and password combinations:
system/manager
system/manager
system/manager
exit The second method: use sqlplus < xxx.txt, and the content of xxx.txt is:
system/manager
exit The third method: type xxx.txt | sqlplus, and the content of xxx.txt is the same as above. The fourth method: using echo is also okay. If the username and password are incorrect, you can exit directly.
echo system/manager | sqlplus
|

偶只喜欢回答那些标题和描述都很清晰的帖子!
如想解决问题,请认真学习“这个帖子”和“这个帖子”并努力遵守,如果可能,请告诉更多的人!
|
|
2005-4-14 00:00 |
|
|
houen
初级用户
 
积分 139
发帖 13
注册 2005-4-6
状态 离线
|
『第 9 楼』:
使用 LLM 解释/回答一下
谢谢热心的Climbing!不过还有个问题!如果在重定向输出时取的环境变量中有空格时好象就会出问题?比如:echo hello > %recoverpath%\Log\ListenLog.txt如果%recoverpath%取得的环境变量的值中空格 比如:c:\program files\test那么输出的文件位置就变成了c:\program ,然后文件的内容就为Files\test\Log\ListenLog.txt有方法解决呢?
Thanks to enthusiastic Climbing! But there is another problem! When redirecting output, if there are spaces in the environment variables taken, it seems there will be problems? For example: echo hello > %recoverpath%\Log\ListenLog.txt If the value of the environment variable obtained by %recoverpath% has a space, such as: c:\program files\test Then the output file location becomes c:\program, and the content of the file becomes Files\test\Log\ListenLog.txt Is there a way to solve it?
|
|
2005-4-15 00:00 |
|
|
小石头
初级用户
 
积分 165
发帖 28
注册 2004-8-9
状态 离线
|
『第 10 楼』:
使用 LLM 解释/回答一下
echo hello > "%recoverpath%\Log\ListenLog.txt"
echo hello > "%recoverpath%\Log\ListenLog.txt"
|
|
2005-4-17 00:00 |
|