DROP FUNCTION test_DynamicColumn();
DROP TYPE sc_month_report_result;
CREATE TYPE sc_month_report_result AS (
score TEXT,
count INTEGER
);
CREATE OR REPLACE FUNCTION test_DynamicColumn()
RETURNS VOID AS $$
DECLARE sc_month_report_result_obj sc_month_report_result [];
DECLARE columns TEXT [];
DECLARE result TEXT;
BEGIN
columns [0] = 'repay';
EXECUTE 'SELECT apply_no FROM sc_month_report
WHERE substr(' || scores[0] || '_date:: VARCHAR, 7, 1) = 1 :: VARCHAR
AND sc_month_report.score = ''1_0-60''' INTO result;
RAISE NOTICE '--->%', (columns [0] || '_date');
RAISE NOTICE '--->%', result;
END;
$$ LANGUAGE plpgsql;
SELECT test_DynamicColumn();
网友评论