Function cannot call String Function LOCATE
Hi !
I want to call MySQL string function LOCATE inside a function .
but when i try to execute then it says the string function LOCATE doesnt exist .
The error is as follows.
mysql> select GET_TRUNC(122344.535345345,'9999.99');//
ERROR 1305 (42000): FUNCTION <databasename>.LOCATE does not exist
i have also tried to run it dynamically , but is giving the same error.
set @fmt=format;
SET @query=" select LOCATE ('.',@fmt) into @pos " ;
PREPARE stmt from @query;
EXECUTE stmt;
The code is as follows
DELIMITER //
DROP function IF EXISTS GET_TRUNC //
create function GET_TRUNC( value INT , format VARCHAR (200))
returns INT
BEGIN
DECLARE position INT DEFAULT 0;
DECLARE ret INT;
set position = LOCATE ('.',format);
if position != 0 then
set ret = TRUNCATE(value,LENGTH(format)-position);
else
set ret =TRUNCATE(value,0);
end if;
return ret ;
END;
//
Please suggest how to resolve this .
Thanks in Advance
Rajarshi
Subject
Views
Written By
Posted
Function cannot call String Function LOCATE
6481
November 06, 2006 10:39PM
2645
November 07, 2006 08:03PM
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.