zoukankan      html  css  js  c++  java
  • PostgreSQL 抛出错误信息(错误行号)

      抛出错误行号是我们在写SQL中常用到的,在SQL Server和Oracle中都很简单,但是在PostgreSQL怎么实现呢?在网上查了下资料只有pg_exception_context包含错误行,我们可以根据具体情况来截取。脚本如下:

    do language plpgsql $$
    declare
        v_state   TEXT;
        v_msg     TEXT;
        v_detail  TEXT;
        v_hint    TEXT;
        v_context TEXT;
    begin
    
        create table yyy(a int);
        create table yyy(a int); -- this will cause an error
    
    exception when others then 
    
        get stacked diagnostics
            v_state   = returned_sqlstate,
            v_msg     = message_text,
            v_detail  = pg_exception_detail,
            v_hint    = pg_exception_hint,
            v_context = pg_exception_context;
    
        raise notice E'Got exception:
            state  : %
            message: %
            detail : %
            hint   : %
            context: %', v_state, v_msg, v_detail, v_hint, v_context;
    
        raise notice E'Got exception:
            SQLSTATE: % 
            SQLERRM: %', SQLSTATE, SQLERRM;     
    
        raise notice '%', message_text; -- invalid. message_text is contextual to GET STACKED DIAGNOSTICS only
    
    end; $$;
  • 相关阅读:
    sqli-labs(43)
    sqli-labs(42)
    sqli-labs(41) and 两php函数的讲解
    php的mysql语法
    msf
    域的建立过程
    sqli-labs(40)
    sqli-labs(39)
    sqli-labs(38)
    虚拟化之docker
  • 原文地址:https://www.cnblogs.com/VicLiu/p/11857931.html
Copyright © 2011-2022 走看看