zoukankan      html  css  js  c++  java
  • mysql GET DIAGNOSTICS 语法

    MySQL 5.6 提供了 get diagnostic 语句来获取错误缓冲区的内容,然后把这些内容输出到不同范围域的变量里,以便我们后续灵活操作 语法如下:

    GET [CURRENT] DIAGNOSTICS
    {
        statement_information_item
        [, statement_information_item] ... 
      | CONDITION condition_number
        condition_information_item
        [, condition_information_item] ...
    }
    
    statement_information_item:
        target = statement_information_item_name
    
    condition_information_item:
        target = condition_information_item_name
    
    statement_information_item_name:
        NUMBER
      | ROW_COUNT
    
    condition_information_item_name:
        CLASS_ORIGIN
      | SUBCLASS_ORIGIN
      | RETURNED_SQLSTATE
      | MESSAGE_TEXT
      | MYSQL_ERRNO
      | CONSTRAINT_CATALOG
      | CONSTRAINT_SCHEMA
      | CONSTRAINT_NAME
      | CATALOG_NAME
      | SCHEMA_NAME
      | TABLE_NAME
      | COLUMN_NAME
      | CURSOR_NAME
    
    condition_number, target:
        (see following discussion)

    例子:获取删除表时的错误信息

    mysql> DROP TABLE test.no_such_table;
    ERROR 1051 (42S02): Unknown table 'test.no_such_table'
    mysql> GET DIAGNOSTICS CONDITION 1
        ->   @p1 = RETURNED_SQLSTATE, @p2 = MESSAGE_TEXT;
    mysql> SELECT @p1, @p2;
    +-------+------------------------------------+
    | @p1   | @p2                                |
    +-------+------------------------------------+
    | 42S02 | Unknown table 'test.no_such_table' |
    +-------+------------------------------------+

    参考:

    13.6.7.3 GET DIAGNOSTICS Syntax

  • 相关阅读:
    ADO.Net对Oracle数据库的操作(转)
    代码反思(1)
    继承与多态
    存储过程
    linux学习流程及内容概括
    Linux下终端快捷键
    查找算法
    epoll解读
    TCP/udp编程
    如何学习嵌入式
  • 原文地址:https://www.cnblogs.com/langtianya/p/5534222.html
Copyright © 2011-2022 走看看