8

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?

2 Answers 2

5

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:

Sign up to request clarification or add additional context in comments.

2 Comments

so, are you saying that there is no way to do this? or that I just can't do it using \.?
There is no way for a stored proc to source a script, nor to run many of the commands in the script even if you could source it.
0

If you're on Sql Sevrer 2005 you can use the xp_cmdshell command.

http://msdn.microsoft.com/en-us/library/ms175046(SQL.90).aspx

Or

http://www.sqlservercentral.com/articles/Administering/scriptscheduling/450/

3 Comments

but i think he wants it for mysql
yeah, I'm tied to mySQL unfortunately.
@GeniaS. I highly doubt the 3K to 15K license for Microsoft SQL Server is worth the capability of calling a script from a stored procedure... (and, having used MS SQL Server even more than MySQL but being experienced with both: there aren't any other features that are worth the price tag, or the requirement to run on an expensive Windows server OS)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.