Mysql(Mariadb)之select into 语句分析(英文)

SELECT INTO

Syntax

SELECT col_name [, col_name] ...
    INTO var_name [, var_name] ...
    table_expr

Contents

  1. Syntax
  2. Description
  3. Examples
  4. See Also

Description¶

SELECT ... INTO enables selected columns to be stored directly into variables. No resultset is produced. The query should return a single row. If the query returns no rows, a warning with error code 1329 occurs (No data), and the variable values remain unchanged. If the query returns multiple rows, error 1172 occurs (Result consisted of more than one row). If it is possible that the statement may retrieve multiple rows, you can use LIMIT 1 to limit the result set to a single row.

The INTO clause can also be specified at the end of the statement.

In the context of such statements that occur as part of events executed by the Event Scheduler, diagnostics messages (not only errors, but also warnings) are written to the error log, and, on Windows, to the application event log.

This statement can be used with both local variables and user-defined variables.

For the complete syntax, see SELECT.

Another way to set a variable's value is the SET statement.

SELECT ... INTO results are not stored in the query cache even if SQL_CACHE is specified.

Examples

SELECT id, data INTO @x,@y 
FROM test.t1 LIMIT 1;

See Also

  • SELECT - full SELECT syntax.
  • SELECT INTO OUTFILE - formatting and writing the result to an external file.
  • SELECT INTO DUMPFILE - binary-safe writing of the unformatted results to an external file.

原文链接:https://mariadb.com/kb/en/selectinto/


欢迎加我们微信wang1415035017进入微信高级技术群共同进步,或者扫码加入我们哦(V_V) 

你可能感兴趣的:(mysql)