MySQL Forums
Forum List  »  UDF

Re: Function in order by clause problem
Posted by: Michel DOMINIQUE
Date: September 25, 2015 10:26AM

-----------------
How to reproduce:
-----------------

DROP TABLE test;

CREATE TABLE test (
idtest INT NOT NULL ,
test_name VARCHAR(45) NULL ,
PRIMARY KEY (idtest) );

INSERT INTO test(idtest, test_name) VALUES (1, '1.0'), (2, '1.1'), (3, '2.0');

DROP FUNCTION IF EXISTS ftest;

DELIMITER $$

CREATE FUNCTION ftest(ver CHAR(50), order_sort CHAR(50))
RETURNS TEXT
DETERMINISTIC
BEGIN
RETURN CONCAT(ver, ' ',order_sort);
END;
$$

DELIMITER ;

select ftest("test_name", "desc") from test;
displays
test_name desc
select test_name from test order by ftest("test_name", "desc");
displays
1.0
1.1
2.0
==> NOOK
select test_name from test order by test_name desc;
displays
2.0
1.1
1.0
==> OK

Options: ReplyQuote


Subject
Views
Written By
Posted
1379
September 25, 2015 07:45AM
Re: Function in order by clause problem
883
September 25, 2015 10:26AM


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.