mysqlstored-functions

MySQL stored function: CONTAINS SQL or NO SQL?


For the stored functions below, which is the correct flag: CONTAINS SQL or NO SQL?

CREATE FUNCTION BigIntHash(str VARCHAR(255)) RETURNS BIGINT UNSIGNED DETERMINISTIC
RETURN CONV(SUBSTRING(CAST(SHA(str) AS CHAR), 1, 15), 16, 10)

and

CREATE FUNCTION upi(a VARCHAR(14), b INT(8) UNSIGNED, c VARCHAR(13)) RETURNS BIGINT UNSIGNED DETERMINISTIC
RETURN IF(a IS NULL, 
  IF(b IS NULL, 
    IF(c IS NULL, 
      NULL, 
      BigIntHash(CONCAT("a-", a))
    ), 
    BigIntHash(CONCAT("b-", b))
  ), 
  BigIntHash(CONCAT("c-", c))
)

The definitions are on http://dev.mysql.com/doc/refman/5.1/en/create-procedure.html but I am still not sure:


Solution

  • Both are NO SQL as they do not access data in tables, cursors or variables.

    For reference on what constitutes an SQL statement see: http://dev.mysql.com/doc/refman/5.1/en/sql-syntax.html

    Notice that functions like CONV() SHA() or CONCAT() are not mentioned in this chapter.