什么是mysql对等的@ identity和@@error,以及如何在mysql中使用try catch

时间:2022-01-05 09:36:00

I am looking for few global variable in mysql which are equivalent of sql server.

我正在寻找mysql中的几个全局变量,它们相当于sql server。

I want the whole list eg.

我要整张表。

Sql Server Equivalent

Sql Server等效

@@error ---

@ error - - -

@@Identity ---

@@Identity - - -

etc.

等。

Basically right now I want to know what are the equivalent variable of @@error and @@identity.

基本上现在我想知道@error和@@identity的等价变量是什么。

But it will be helpfull if u could provide some other variable also

但是如果你也能提供一些其他的变量,那将会很有帮助

1 个解决方案

#1


5  

The last auto_increment value (i.e. the last identity) generated for the current connection can be found using the LAST_INSERT_ID() function.

可以使用LAST_INSERT_ID()函数找到为当前连接生成的最后一个auto_increment值(即最后一个标识)。


About errors, not sure ; there doesn't seem to be any system variable that corresponds to the last error message.

关于错误,不确定;似乎没有任何系统变量对应于最后一条错误消息。

There is a show errors statement :

有一个show errors语句:

mysql> select a from b;
ERROR 1046 (3D000): No database selected

mysql> show errors;
+-------+------+----------------------+
| Level | Code | Message              |
+-------+------+----------------------+
| Error | 1046 | No database selected | 
+-------+------+----------------------+
1 row in set (0,00 sec)

But not sure how you can use this result...

但不知道如何使用这个结果……


After searching a bit more, I found out this thread : Getting the last error message, which says (quoting) :

在进一步搜索之后,我发现了这个线程:获取最后一条错误消息(引用):

I think there should be something like @@last_error_id and @@last_error_message, but I can`t find anything in the current manual.

我认为应该有@@last_error_id和@last_error_message这样的内容,但是我在当前手册中找不到任何内容。

And the first answer states (quoting) :

第一个回答说(引用):

This isn't possible currently, from what we understand error handling will be improved in version 5.2 and hopefully something like this may be possible.

这在目前是不可能的,根据我们所理解的错误处理将在5.2版本中得到改进,希望类似这样的事情能够成为可能。

#1


5  

The last auto_increment value (i.e. the last identity) generated for the current connection can be found using the LAST_INSERT_ID() function.

可以使用LAST_INSERT_ID()函数找到为当前连接生成的最后一个auto_increment值(即最后一个标识)。


About errors, not sure ; there doesn't seem to be any system variable that corresponds to the last error message.

关于错误,不确定;似乎没有任何系统变量对应于最后一条错误消息。

There is a show errors statement :

有一个show errors语句:

mysql> select a from b;
ERROR 1046 (3D000): No database selected

mysql> show errors;
+-------+------+----------------------+
| Level | Code | Message              |
+-------+------+----------------------+
| Error | 1046 | No database selected | 
+-------+------+----------------------+
1 row in set (0,00 sec)

But not sure how you can use this result...

但不知道如何使用这个结果……


After searching a bit more, I found out this thread : Getting the last error message, which says (quoting) :

在进一步搜索之后,我发现了这个线程:获取最后一条错误消息(引用):

I think there should be something like @@last_error_id and @@last_error_message, but I can`t find anything in the current manual.

我认为应该有@@last_error_id和@last_error_message这样的内容,但是我在当前手册中找不到任何内容。

And the first answer states (quoting) :

第一个回答说(引用):

This isn't possible currently, from what we understand error handling will be improved in version 5.2 and hopefully something like this may be possible.

这在目前是不可能的,根据我们所理解的错误处理将在5.2版本中得到改进,希望类似这样的事情能够成为可能。