schilly Posted May 28, 2010 Share Posted May 28, 2010 I'm trying to create this procedure: CREATE PROCEDURE make_intervals(startdate Date, enddate Date, intval integer, unitval varchar(10)) BEGIN -- ************************************************************************* -- Procedure: make_intervals() -- Author: Ron Savage -- Date: 02/03/2009 -- -- Description: -- This procedure creates a temporary table named time_intervals with the -- interval_start and interval_end fields specifed from the startdate and -- enddate arguments, at intervals of intval (unitval) size. -- ************************************************************************* declare thisDate Date; declare nextDate Date; set thisDate = startdate; -- ************************************************************************* -- Drop / create the temp table -- ************************************************************************* drop temporary table if exists time_intervals; create temporary table if not exists time_intervals ( interval_start Date, interval_end Date ); -- ************************************************************************* -- Loop through the startdate adding each intval interval until enddate -- ************************************************************************* repeat select case unitval when 'MICROSECOND' then timestampadd(MICROSECOND, intval, thisDate) when 'SECOND' then timestampadd(SECOND, intval, thisDate) when 'MINUTE' then timestampadd(MINUTE, intval, thisDate) when 'HOUR' then timestampadd(HOUR, intval, thisDate) when 'DAY' then timestampadd(DAY, intval, thisDate) when 'WEEK' then timestampadd(WEEK, intval, thisDate) when 'MONTH' then timestampadd(MONTH, intval, thisDate) when 'QUARTER' then timestampadd(QUARTER, intval, thisDate) when 'YEAR' then timestampadd(YEAR, intval, thisDate) end into nextDate; insert into time_intervals select thisDate, timestampadd(MICROSECOND, -1, nextDate); set thisDate = nextDate; until thisDate >= enddate end repeat; END which I got from http://stackoverflow.com/questions/510012/get-a-list-of-dates-between-two-dates When I run this however, I receive "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'PROCEDURE make_intervals(startdate Date, enddate Date, intval integer, unitval v' at line 1" Any ideas? I thought it might be a delimiter issue but doing this: delimiter // CREATE PROCEDURE make_intervals(startdate Date, enddate Date, intval integer, unitval varchar(10)) BEGIN -- ************************************************************************* -- Procedure: make_intervals() -- Author: Ron Savage -- Date: 02/03/2009 -- -- Description: -- This procedure creates a temporary table named time_intervals with the -- interval_start and interval_end fields specifed from the startdate and -- enddate arguments, at intervals of intval (unitval) size. -- ************************************************************************* declare thisDate Date; declare nextDate Date; set thisDate = startdate; -- ************************************************************************* -- Drop / create the temp table -- ************************************************************************* drop temporary table if exists time_intervals; create temporary table if not exists time_intervals ( interval_start Date, interval_end Date ); -- ************************************************************************* -- Loop through the startdate adding each intval interval until enddate -- ************************************************************************* repeat select case unitval when 'MICROSECOND' then timestampadd(MICROSECOND, intval, thisDate) when 'SECOND' then timestampadd(SECOND, intval, thisDate) when 'MINUTE' then timestampadd(MINUTE, intval, thisDate) when 'HOUR' then timestampadd(HOUR, intval, thisDate) when 'DAY' then timestampadd(DAY, intval, thisDate) when 'WEEK' then timestampadd(WEEK, intval, thisDate) when 'MONTH' then timestampadd(MONTH, intval, thisDate) when 'QUARTER' then timestampadd(QUARTER, intval, thisDate) when 'YEAR' then timestampadd(YEAR, intval, thisDate) end into nextDate; insert into time_intervals select thisDate, timestampadd(MICROSECOND, -1, nextDate); set thisDate = nextDate; until thisDate >= enddate end repeat; END// I receive the same error: "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'PROCEDURE make_intervals(startdate Date, enddate Date, intval integer, unitval v' at line 1" Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/203236-problem-creating-procedure/ Share on other sites More sharing options...
Mchl Posted May 28, 2010 Share Posted May 28, 2010 Are you running it through phpMyAdmin? If yes, there's an input box below SQL input box, whre you need to enter your delimiter (as defined in the first line), and paste the SQL without DELIMITER statement. Quote Link to comment https://forums.phpfreaks.com/topic/203236-problem-creating-procedure/#findComment-1064842 Share on other sites More sharing options...
schilly Posted May 28, 2010 Author Share Posted May 28, 2010 I'm using Sequel Pro but tried through command line as well with the same results. I'll try through phpmyadmin with the delimiter option now. Quote Link to comment https://forums.phpfreaks.com/topic/203236-problem-creating-procedure/#findComment-1064843 Share on other sites More sharing options...
schilly Posted May 28, 2010 Author Share Posted May 28, 2010 hmmm no luck in phpmyadmin 2.8.2.4. There wasn't any spot for entering the delimiter. Quote Link to comment https://forums.phpfreaks.com/topic/203236-problem-creating-procedure/#findComment-1064846 Share on other sites More sharing options...
Mchl Posted May 28, 2010 Share Posted May 28, 2010 I did run it with no problems using DELIMITER || and END || Which MySQL version you use? Quote Link to comment https://forums.phpfreaks.com/topic/203236-problem-creating-procedure/#findComment-1064847 Share on other sites More sharing options...
schilly Posted May 28, 2010 Author Share Posted May 28, 2010 Looks like 4.1.22 Is Procedure only available in 5+? I'm guessing that's why it's complaining about the Procedure line. How is procedure different from function? Quote Link to comment https://forums.phpfreaks.com/topic/203236-problem-creating-procedure/#findComment-1064851 Share on other sites More sharing options...
Mchl Posted May 28, 2010 Share Posted May 28, 2010 Sorry, no stored routines (neither procedures nor functions) for you. They come with MySQL 5.x A function returns a value. You can use it in query like SELECT ID, MyFunction(column1,column2) AS someAlias FROM someTable Procedures on the other hand do not return a value, but perform some operations on data. You have to CALL them. http://dev.mysql.com/doc/refman/5.0/en/stored-programs-views.html Quote Link to comment https://forums.phpfreaks.com/topic/203236-problem-creating-procedure/#findComment-1064852 Share on other sites More sharing options...
schilly Posted May 28, 2010 Author Share Posted May 28, 2010 grrrr damn. guess i'll have to look into upgrading. thanks for the help. Quote Link to comment https://forums.phpfreaks.com/topic/203236-problem-creating-procedure/#findComment-1064859 Share on other sites More sharing options...
Mchl Posted May 28, 2010 Share Posted May 28, 2010 Yeah, high time. MySQL 4.x hasn't been supported for like a year now? Quote Link to comment https://forums.phpfreaks.com/topic/203236-problem-creating-procedure/#findComment-1064861 Share on other sites More sharing options...
schilly Posted June 11, 2010 Author Share Posted June 11, 2010 Yeah upgraded. Our db seems to be running much faster. Was their a lot of performance improvements for 4.x->5.x? Quote Link to comment https://forums.phpfreaks.com/topic/203236-problem-creating-procedure/#findComment-1070820 Share on other sites More sharing options...
Mchl Posted June 11, 2010 Share Posted June 11, 2010 There was a lot of improvements in almost all aspects of MySQL. The storage engines got their share of upgrades too (some recent upgrades to InnoDB are especially noteworthy). Quote Link to comment https://forums.phpfreaks.com/topic/203236-problem-creating-procedure/#findComment-1070839 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.