MySQL Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsDatabasesMySQL Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old January 10th, 2013, 06:19 PM
oliwin oliwin is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 14 oliwin User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 20 m 7 sec
Reputation Power: 0
Exclamation Condition IF ELSE AT WHILE

Hello! I tried any ways to resolve SQL error in the this query:
Code:
DELIMITER $$
DROP PROCEDURE IF EXISTS test$$
CREATE PROCEDURE test()
BEGIN
DECLARE count INT DEFAULT 0;
DECLARE num INT DEFAULT 0;
DECLARE param INT DEFAULT 0;


WHILE count < 9 DO

IF num = 3 THEN 
SET param = param + 1;
SET num =0;
END IF;

SELECT * FROM instans_type WHERE block = param;
SET count = count + 1;
SET num = num + 1;
        
END WHILE;

END$$
DELIMITER;

My phpmyadmin says that are sintax errors, WTF?
Please, help me.

Reply With Quote
  #2  
Old January 10th, 2013, 08:24 PM
spacebar208's Avatar
spacebar208 spacebar208 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2012
Location: spaceBAR Central
Posts: 191 spacebar208 User rank is Sergeant Major (2000 - 5000 Reputation Level)spacebar208 User rank is Sergeant Major (2000 - 5000 Reputation Level)spacebar208 User rank is Sergeant Major (2000 - 5000 Reputation Level)spacebar208 User rank is Sergeant Major (2000 - 5000 Reputation Level)spacebar208 User rank is Sergeant Major (2000 - 5000 Reputation Level)spacebar208 User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 2 Days 9 h 59 m 25 sec
Reputation Power: 41
Are they getting the error when compiling the procedure or when running it?

Either way, Get them to give you the detailed error text and if it's when they are running it make sure they give you the line number(s).

Reply With Quote
  #3  
Old January 11th, 2013, 05:08 AM
oliwin oliwin is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 14 oliwin User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 20 m 7 sec
Reputation Power: 0
Quote:
Originally Posted by spacebar208
Are they getting the error when compiling the procedure or when running it?

Either way, Get them to give you the detailed error text and if it's when they are running it make sure they give you the line number(s).


SQL-query:

DELIMITER;


Answer MySQL:

#1064 - 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 'DELIMITER' at line 1

Reply With Quote
  #4  
Old January 11th, 2013, 05:28 AM
Jacques1's Avatar
Jacques1 Jacques1 is online now
pollyanna
Click here for more information.
 
Join Date: Jul 2012
Location: Germany
Posts: 1,881 Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 2 Days 8 h 29 m 53 sec
Reputation Power: 813
Code:
DELIMITER<blank>;

Reply With Quote
  #5  
Old January 11th, 2013, 05:51 AM
oliwin oliwin is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 14 oliwin User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 20 m 7 sec
Reputation Power: 0
Quote:
Originally Posted by Jacques1
Code:
DELIMITER<blank>;

If drop DELIMITER then writes

#1064 - 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 'CREATE PROCEDURE test()
BEGIN
DECLARE count INT DEFAULT 0' at line 2

Reply With Quote
  #6  
Old January 11th, 2013, 05:56 AM
Jacques1's Avatar
Jacques1 Jacques1 is online now
pollyanna
Click here for more information.
 
Join Date: Jul 2012
Location: Germany
Posts: 1,881 Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 2 Days 8 h 29 m 53 sec
Reputation Power: 813
Who said anything about dropping "DELMITER"? I'm telling you that the syntax is
Code:
DELIMITER(then a space)(then a semicolon)

Without the parentheses, of course.

Reply With Quote
  #7  
Old January 11th, 2013, 06:37 AM
oliwin oliwin is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 14 oliwin User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 20 m 7 sec
Reputation Power: 0
Quote:
Originally Posted by Jacques1
Who said anything about dropping "DELMITER"? I'm telling you that the syntax is
Code:
DELIMITER(then a space)(then a semicolon)

Without the parentheses, of course.


Okay, thank you for help. Works. But dont understand why returns empty results?
I have at table instans_type notes with block = 1, block = 2, block = 3, block = 4, block = 5 and i wanna to choose only 3 notes for every block
111
222
333
444
555

Reply With Quote
  #8  
Old January 19th, 2013, 01:29 PM
f_razzoli f_razzoli is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Location: Italy
Posts: 36 f_razzoli User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 37 m 48 sec
Reputation Power: 1
You need to read better the manual about the Stored Procedures.


* Your SELECT does nothing. It is executed, but you do nothing with the result.
* Stored procedures return nothing.
* Even Stored Functions, return a single value, not a result set.

You can insert the rows into a tamporary table, and then read it from outside the procedure.

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMySQL Help > Condition IF ELSE AT WHILE

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap