MySQL Forums
Forum List  »  Stored Procedures

Re: Stored Procedure with a "ORDER BY" parameter
Posted by: peter.hamilton-scott
Date: November 09, 2005 04:33PM

Roland, I now have this and it works ok. Maybe you mentioned this in the other thread where we discussed this concept, but does it mean you cannot use parameters in the execute statement? That is, where I had before:

execute stmt_handle using @sorder;

and @sorder was the replacement for the ? placeholder, we now know does not work. But the SP below does work. I'm wondering if you cannot have ? parameters in the prepare statement?

DELIMITER $$

DROP PROCEDURE IF EXISTS `cachelistener`.`AuditTest` $$
CREATE PROCEDURE `AuditTest`(in sorder varchar(250))
BEGIN
set @stmt_text := concat('select * from audit order by ', sorder);
prepare stmt_handle from @stmt_text;
execute stmt_handle;
deallocate prepare stmt_handle;
END $$

DELIMITER ;

Options: ReplyQuote


Subject
Views
Written By
Posted
Re: Stored Procedure with a "ORDER BY" parameter
2887
November 09, 2005 04:33PM


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.