MySQL Forums
Forum List  »  Stored Procedures

Can we dynamically build select statements in a stored procedure?
Posted by: J D
Date: July 20, 2005 07:24PM

I was wondering if it's possible to dynamically build a select statement using a stored procedure?

Please excuse the syntax. I'm just wondering if it is possible to do this (assuming the syntax was correct)

Ex.
DELIMITER $$
CREATE PROCEDURE test (
IN param1 VARCHAR(11),
IN param2 VARCHAR(5),
IN param3 VARCHAR(5),
IN param4 INTEGER(5),
)
BEGIN
SELECT a, b, c from table d

if (param1 != null){
where d=e
}
else{
where f=g
}

if (param2 != null){
order by f
if (param3 != null){
desc
}
}
else{
limit param4
}
END$$

DELIMITER ;




Edited 2 time(s). Last edit at 07/20/2005 07:27PM by J D.

Options: ReplyQuote




Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.