Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
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:
 
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
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 Smile | :) (i have mysql v5.1)
Posted 6-Dec-12 5:01am
Edited 6-Dec-12 5:22am
v3
Comments
ryanb31 at 6-Dec-12 10:10am
   
I don't do MySQL but a quick google search suggests that 1064 is a syntax error.
Gabriel Sas at 6-Dec-12 10:13am
   
but what?
ryanb31 at 6-Dec-12 10:18am
   
Do you need to delcare @stmt or does MySQL somehow know what that is?
Gabriel Sas at 6-Dec-12 10:20am
   
@stmt is a global variable it doesn't need to be declared
ryanb31 at 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?
Gabriel Sas at 6-Dec-12 10:24am
   
i tried it, it's the same error
Member 9581488 at 6-Dec-12 22:05pm
   
Refer this.Might help
http://stackoverflow.com/questions/495700/can-we-write-a-sub-function-or-procedure-inside-another-stored-procedure-sql-s

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 8,478
1 OriginalGriff 6,516
2 Peter Leow 3,567
3 Zoltán Zörgő 3,351
4 Richard MacCutchan 2,397


Advertise | Privacy | Mobile
Web03 | 2.8.150123.1 | Last Updated 26 Dec 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100