View Single Post

   
  #2 (permalink)  
Old 02-28-2008, 08:13 AM
Giuseppe Maxia
 
Posts: n/a
Default Re: StoredProc: How to pass 'table' as argument ?

Artur Baæ wrote:
> I have such StoredProc (Function)
> Is it possible to pass 'Table' to stored proc as argument?
>
> code
> -----------------------------
> CREATE FUNCTION `DDT`.`GetSelectMd5`() RETURNS varchar(255)
> BEGIN
> DECLARE done INT DEFAULT 0;
>
> DECLARE row_crc32 INT;
> DECLARE column_concat longtext;
> DECLARE column_md5 varchar (64);
> DECLARE reader CURSOR FOR SELECT CRC32_DATA FROM Table;
> DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done = 1;
> OPEN reader;
> SET column_concat = '';
> WHILE not done DO
> FETCH reader INTO row_crc32;
> SET column_concat = concat(column_concat,row_crc32);
> end while;
> CLOSE reader;
> set column_md5 = md5(column_concat);
> RETURN md5(column_md5);
> END
> -----------------
>
> How to use TableName from variable inside CURSOR FOR SELECT ...FROM
> 'TableName'?
>
>
>


Unfortunately, with the current implementation of cursors, you can't.
You need to know the table name in advance if you want to use cursors.
A variable table name means that you should use dynamic SQL (server side
prepared statements), but they are not currently supported with cursors.

ciao
gmax

--
_ _ _ _
(_|| | |(_|><
_|
http://gmax.oltrelinux.com
Reply With Quote