我真的不知道为什么我的phpmyadmin中的函数和视图返回null而不是DATETIME。
这是我的功能:
DELIMITER $$
CREATE FUNCTION `return_file`( name varchar(10), number int )
RETURNS datetime
DETERMINISTIC
BEGIN DECLARE transdate DATETIME;
SET trans_date = (SELECT `date` from `sample_table` WHERE `name_ref` = name and `ref_number` = number and `type` = 10);
RETURN trans_date;
END$$
DELIMITER ;
虽然这是我的看法:
CREATE VIEW getsME as
SELECT id,type,date,name_ref,ref_number,return_file(name_ref,ref_number) as transDate
FROM sample_table
WHERE type= 11
ORDER BY id ASC