Click here to Skip to main content
13,089,433 members (60,594 online)
Rate this:
Please Sign up or sign in to vote.
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:

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 :)(i have mysql v5.1)
Posted 6-Dec-12 4:01am
Updated 6-Dec-12 4:22am
ryanb31 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?
ryanb31 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
ryanb31 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 6-Dec-12 10:24am
i tried it, it's the same error
Member 9581488 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
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web04 | 2.8.170813.1 | Last Updated 26 Dec 2012
Copyright © CodeProject, 1999-2017
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