Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

mysql - is it possible to call a sql script from a stored procedure in another sql script?

I'd like to use . to call sql script from inside a stored proc like so...

delimiter ///
create procedure append_procedure()
BEGIN
. test.sql;    
END; ///
delimiter ;

I'm getting a "failed to open 'test.sql;' " error when I run it this way. I've also tried ! but then I get a permission denied error. However, I can't eliminate the ; or the whole thing is broken. Is there a way around this?

What am I doing wrong?

See Question&Answers more detail:os

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

1 Reply

0 votes
by (71.8m points)

There is a set of commands that are builtin to the mysql client. They're documented under "mysql Commands." These include DELIMITER, SOURCE, HELP, CONNECT, USE, QUIT, etc.

The . (or SOURCE) command is one of these builtins. You can't execute these builtin commands programmatically, nor from within a stored procedure.

It'd be like trying to run a UNIX shell builtin from a C program using execl().

A different analogy might be in a web browser, where you can type in special requests like "about:" that are handled by the browser app itself; these don't result in any HTTP request to a remote web site.

Also, it wouldn't help if you could source a script from within a stored procedure, because the script itself likely contains a bunch of commands that are mysql client builtins, and thus cannot be run by the stored proc.


See also my answers to these related questions:


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...