Postgresql:动态sql的例子

前端之家收集整理的这篇文章主要介绍了Postgresql:动态sql的例子前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
  1. CREATEorReplaceFUNCTIONfunc_getnextid(
  2. tablenamevarchar(240),
  3. idnamevarchar(20)default'id')
  4. RETURNSintegerAS$funcbody$
  5. Declare
  6. sqlstringvarchar(240);
  7. currentIdinteger;
  8. Begin
  9. sqlstring:='selectmax("'||idname||'")from"'||tablename||'";';
  10. EXECUTEsqlstringintocurrentId;
  11. ifcurrentIdisNULLorcurrentId=0then
  12. return1;
  13. else
  14. returncurrentId+1;
  15. endif;
  16. End;
  17. $funcbody$LANGUAGEplpgsql;
  18. CREATE OR REPLACE FUNCTION test_get_sql(IN sql character varying,OUT io_cursor_ref refcursor)
    RETURNS record AS
    $BODY$
    DECLARE
    BEGIN
    OPEN IO_CURSOR_REF FOR
    execute sql;

    RETURN; END; $BODY$ LANGUAGE plpgsql VOLATILE COST 100; ALTER FUNCTION test_get_sql(character varying)

原文链接:https://www.f2er.com/postgresql/196376.html

猜你在找的Postgre SQL相关文章