In MySQL:
Code: Select all
MySQL> SELECT c1, c2, strcmp(c1, c2) FROM t1;
+---------+---------+----------------+
| c1 | c2 | strcmp(c1, c2) |
+---------+---------+----------------+
| text | text | 0 |
| text123 | text | 1 |
| text | text123 | -1 |
+---------+---------+----------------+
3 rows in set (0.00 sec)
Code: Select all
dbadmin=> CREATE FUNCTION strcmp(p1 VARCHAR, p2 VARCHAR) RETURN INT
dbadmin-> AS
dbadmin-> BEGIN
dbadmin-> RETURN SIGN(LENGTH(p1) - LENGTH(p2));
dbadmin-> END;
CREATE FUNCTION
dbadmin=> SELECT c1, c2, strcmp(c1, c2) FROM t1;
c1 | c2 | strcmp
---------+---------+--------
text | text123 | -1
text | text | 0
text123 | text | 1
(3 rows)