Click here to Skip to main content
11,410,750 members (63,511 online)
Rate this: bad
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()
    SET stmt := concat('CREATE FUNCTION schemaName.asdsfasdf() RETURNS int BEGIN return 1; end;');
    PREPARE stmt FROM @stmt;
    EXECUTE stmt;

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
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

1 solution

Rate this: bad
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.

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,920
1 OriginalGriff 6,918
2 Maciej Los 3,390
3 Abhinav S 3,248
4 Peter Leow 3,059

Advertise | Privacy | Mobile
Web01 | 2.8.150414.5 | 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