【发布时间】:2018-07-21 07:55:39
【问题描述】:
我正在尝试将 mySQL 存储过程转换为 postgrSQL 存储函数。我是 postgreSQL 的新手。我第一次尝试将 join Store 过程转换为 store 函数。但我收到以下错误
ERROR: structure of query does not match function result type
DETAIL: Returned type text does not match expected type character varying in column 3.
CONTEXT: PL/pgSQL function getsummarypagecontentsurveyform(numeric) line 3 at RETURN QUERY
存储过程
CREATE PROCEDURE [dbo].[GetSummaryPageContentSurveyForm]
@nRoomAllocationID bigint
AS
BEGIN
SELECT Employee.sEmpName, RoomInvestigatorMapping.sComment,
Employee.sEmpName + ' : ' + RoomInvestigatorMapping.sComment as CommentsToDisplay
FROM RoomInvestigatorMapping INNER JOIN Employee
ON RoomInvestigatorMapping.nInvestigatorID = Employee.nEmpID
Where RoomInvestigatorMapping.nRoomAllocationID = @nRoomAllocationID
END
GO
存储功能
CREATE OR REPLACE FUNCTION GetSummaryPageContentSurveyForm (
p_nroom_allocation_id numeric)
RETURNS Table(res_semp_name character varying,res_scomment character varying,
res_comments_to_display character varying)
AS $$
BEGIN
Return Query
SELECT employee.semp_name, roominvestigatormapping.scomment,
employee.semp_name || ' : ' || roominvestigatormapping.scomment as comments_to_display
FROM roominvestigatormapping INNER JOIN employee
ON roominvestigatormapping.ninvestigator_id = employee.nemp_id
Where roominvestigatormapping.nroom_allocation_id = p_nroom_allocation_id;
END;
$$ LANGUAGE plpgsql;
【问题讨论】:
标签: mysql postgresql stored-procedures stored-functions