我是PostgreSQl的新手,并且创建了一个下面提到的函数。我想要的是,当我在查询工具中运行SELECT查询时,它可以正常工作并提供所需的结果,但是当我执行以下功能时,则无法工作。 Stageno是一个“字符变化”。我该如何解决?
-- FUNCTION: public.getauditquestion(integer)
-- DROP FUNCTION public.getauditquestion(integer);
CREATE OR REPLACE FUNCTION public.getauditquestion(
auditid integer)
RETURNS TABLE(audit_ques_id bigint, audit_id integer, activityname character varying, question_id integer, question character varying, answer_type integer, answer_lov integer, answertypename character varying, ok_notok integer, oknotokname character varying, answer_min character varying, answer_max character varying, uom integer, uomname character varying, correct_ans integer, created_by integer, created_date timestamp without time zone, stage character varying, stageno character varying, description character varying, severity character varying, who character varying, how character varying, "when" character varying, "where" character varying)
LANGUAGE 'plpgsql'
COST 100.0
VOLATILE
ROWS 1000.0
AS $function$
BEGIN
Return Query
select am.audit_ques_id, am.audit_id ,ddl3.dd_value AS activityName , am.question_id ,
ddl2.question AS question, am.answer_type, am.answer_lov, ddl4.dd_value AS answerTypeName, am.ok_notok ,
ddl5.dd_value AS okNotOkName, am.answer_min, am.answer_max, am.uom, ddl13.dd_value AS uomname, am.correct_ans,
am.created_by, am.created_date,ddl6.dd_value AS stage, ddl14.dd_value AS stage_no, ddl7.description, ddl8.dd_value AS severity,
ddl9.dd_value AS who , ddl10.dd_value AS how , ddl11.dd_value AS "when" , ddl12.dd_value AS "where"
from audit_ques_detail am left join audit_master ddl1 on ddl1.audit_id=am.audit_id
left join dd_type_details ddl3 on ddl3.dd_id=ddl1.activity_id
left join question_master ddl2 on ddl2.question_id=am.question_id
left join dd_type_details ddl4 on ddl4.dd_id = am.answer_type
left join dd_type_details ddl5 on ddl5.dd_id = am.ok_notok
left join dd_type_details ddl6 on ddl6.dd_id = ddl2.stage
left join question_master ddl7 on ddl7.question_id = am.question_id
left join dd_type_details ddl8 on ddl8.dd_id = ddl2.severity
left join dd_type_details ddl9 on ddl9.dd_id = ddl2.who
left join dd_type_details ddl10 on ddl10.dd_id = ddl2.how
left join dd_type_details ddl11 on ddl11.dd_id = ddl2.when
left join dd_type_details ddl12 on ddl12.dd_id = ddl2.where
left join dd_type_details ddl13 on ddl13.dd_id = am.uom
left join dd_type_details ddl14 on ddl14.dd_id = am.stage_no
where am.audit_id = auditid and am.isActive = 1 ORDER BY cast(ddl14.dd_value AS Integer);
END;
$function$;
ALTER FUNCTION public.getauditquestion(integer)
OWNER TO postgres;