Click here to Skip to main content
15,880,905 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
See more:
in a stored procedure i know you can create tables or database or schema, but is it possible to create a function or a view:
here is what i tried:

SQL
create PROCEDURE schemaName.asd()
begin
DECLARE stmt VARCHAR(255);

    SET stmt := concat('CREATE FUNCTION schemaName.asdsfasdf() RETURNS int BEGIN return 1; end;');

    PREPARE stmt FROM @stmt;

    EXECUTE stmt;
end;


when i do
SQL
call schemaName.asd()$$

and i get an ERROR CODE 1064

is it possible to create here functions or views?
if yes how can it be done?

if this can be done a simple example would be just fine :)(i have mysql v5.1)
Posted
Updated 6-Dec-12 4:22am
v3
Comments
ZurdoDev 6-Dec-12 10:10am    
I don't do MySQL but a quick google search suggests that 1064 is a syntax error.
Gabriel Sas 6-Dec-12 10:13am    
but what?
ZurdoDev 6-Dec-12 10:18am    
Do you need to delcare @stmt or does MySQL somehow know what that is?
Gabriel Sas 6-Dec-12 10:20am    
@stmt is a global variable it doesn't need to be declared
ZurdoDev 6-Dec-12 10:23am    
But in your prepare statement isn't the "FROM" part the SQL statement? So, shouldn't you have SET @stmt := ... so that @stmt has the SQL to create your view?

1 solution

i found out that you can't, maybe in the future mysql will have this functionallity.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900