Jump to content

[SOLVED] Need help creating simple SPROC


EvilCoatHanger

Recommended Posts

mySQL Version: 5.0.18

Running on Mac OSX 10.4

Running also phpMyAdmin 2.7.0-pl2

 

I've been trying to create a simple stored procedure.. For example:

 

CREATE PROCEDURE usp_GetPaymentLocationsByZip(INOUT zipcode VARCHAR(5))
BEGIN
SELECT * FROM dpl_PaymentLocations WHERE Zip = zipcode; 
END;

 

I'm new to mySQL, but have a basic understanding of SQL. Please help, I'm going insane trying to figure this out!!

 

I get the following error:

#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 'SELECT * FROM dpl_PaymentLocations WHERE Zip = zipcode' at line 3

 

Everything just seems so cryptic to me.

 

Thanks in advance,

Cavin

Link to comment
Share on other sites

You have specified your delimiter twice (;)

You need to change the delimiter at the start then change it back at the end.

 

CREATE PROCEDURE usp_GetPaymentLocationsByZip(IN zipcode VARCHAR(5))
DELIMITER $$
BEGIN
SELECT * FROM dpl_PaymentLocations WHERE Zip = zipcode; 
END $$
DELIMITER ;

Link to comment
Share on other sites

Do Stored Procedures work the same way in mySQL vs SQL2000?

 

For reference, heres my current SPROC:

CREATE PROCEDURE usp_GetPaymentLocationsByZip(IN zipcode VARCHAR(5))
SELECT * FROM dpl_PaymentLocations WHERE Zip = zipcode; 

(Thank you everybody that got me this far..)

 

Example.. I could say:

 

usp_GetPaymentLocationsByZip @ZipCode=43040

 

and get a record back with all of the information pertaining to that.

 

In mySQL, (This is from my understand, please correct me if I'm wrong..), it would be...

 

CALL usp_GetPaymentLocationsByZip(43040);

 

.. but it wouldn't select anything back. Do I have to create another parameter using OUT and call that specifically?

 

 

On Another Note.. can you only pull back one record with a stored procedure?

Link to comment
Share on other sites

After further reading and spending tons of time trying to develop this stored procedure. It finally comes down to this:

SQL query:

call usp_GetPaymentLocationsByZipCode( 43040, @AgentName , @Address )

MySQL said: 

#1172 - Result consisted of more than one row 

 

From what I have read, I will need to include a CURSOR inside my Stored Procedure. Correct? I'm just trying to figure this out so I don't keep going down the wrong path.

Link to comment
Share on other sites

Okay, after reading over my past posts.. I'm wondering what in the hell I was thinking.

 

I need a way to pull back multiple records by passing in a variable. I am doing a straight SELECT:

SELECT * FROM dpl_PaymentLocations WHERE Zip LIKE '45324' AND DeleteFlag = 0 ORDER BY AgentName

Which Returns:
CRICKET - C WIRELESS	85 E DAYTON YELLOWSPRINGS RD FAIRBORN, OH 45324	937-754-7350	Click Here
DISCOUNT DRUG MART #73	7617 DAYTON SPRINGFIELD FAIRBORN, OH 45324	330-725-2343	Click Here

 

I want to avoid using a straight SELECT due to SQL Injection. In SQL2000, a Stored Procedure would of been my best bet. In mySQL I don't know what the best way to do this is. Can somebody point me in the right direction?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.