在Oracle的SQL*Plus环境中,LIST命令用于显示当前缓冲区(也就是你正在输入或已经输入的SQL命令)中的内容。这在你需要查看或修改已经输入的SQL语句时非常有用。
LIST命令的基本用法非常简单。如果你只是输入LIST而不带任何参数,它会显示从缓冲区开始到当前光标位置的所有内容。你也可以使用LIST n来显示缓冲区中从第n行开始的内容,或者LIST m n来显示从第m行到第n行的内容。但是,你提到的;符号并不是LIST命令的一部分或其直接用法。
然而,在SQLPlus中,;(分号)用作SQL语句的结束符。当你输入了一个SQL语句并按下分号后,SQLPlus会尝试执行该语句。如果你的意图是在使用LIST命令查看语句时注意到语句以;结束,那么这只是因为该语句在之前已经被完整地输入并准备执行。
1、Syntax 语法
L[IST] [n | n m | n * | n LAST | * | * n | * LAST | LAST]
Lists one or more lines of the SQL buffer.
列出SQL缓冲区的一行或多行。
In SQLPlus command-line you can also use “;” to list all the lines in the SQL buffer.
在SQLPlus命令行中,您还可以使用“;”列出SQL缓冲区中的所有行。
2、Term
| Term | Description |
|---|---|
| n | Lists line n. |
| n m | Lists lines n through m. |
| n * | Lists line n through the current line. |
| n LAST | Lists line n through the current line. |
| * | Lists the current line. |
| * n | Lists the current line through line n. |
| * LAST | Lists the current line through line n. |
| LAST | Lists the current line through line n. |
Enter LIST with no clauses, or “;” to list all lines. The last line listed becomes the new current line (marked by an asterisk).
3、Examples
3.1、To list the contents of the buffer, enter
TESTUSER@FREEPDB1> SELECT table_name, comments
2 FROM user_tab_comments
3 WHERE table_name = 'EMPLOYEES';
TABLE_NAME COMMENTS
--------------------------------- ----------------------------
EMPLOYEES 雇员信息
TESTUSER@FREEPDB1> list;
1 SELECT table_name, comments
2 FROM user_tab_comments
3* WHERE table_name = 'EMPLOYEES'
or enter
TESTUSER@FREEPDB1> ;
1 SELECT table_name, comments
2 FROM user_tab_comments
3* WHERE table_name = 'EMPLOYEES'
OR list 1 3 已知SQL执行的所有行数时
TESTUSER@FREEPDB1> list 1 3
1 SELECT table_name, comments
2 FROM user_tab_comments
3* WHERE table_name = 'EMPLOYEES'
The asterisk indicates that line 3 is the current line.
星号表示第3行是当前行。
3.2、要仅列出第二行,请输入
To list the second line only, enter
TESTUSER@FREEPDB1> list 2 2* FROM user_tab_comments
3.3、要从当前行(现在是第2行)到最后一行列出,请输入
To list from the current line (now line 2) to the last line, enter
TESTUSER@FREEPDB1> list * last 2 FROM user_tab_comments 3* WHERE table_name = 'EMPLOYEES'
注意此步是紧接着上一步3.2执行的结果,如果current line不同,则list * last结果也不同,如下:
TESTUSER@FREEPDB1> list;
1 SELECT table_name, comments
2 FROM user_tab_comments
3* WHERE table_name = 'EMPLOYEES'
TESTUSER@FREEPDB1> list * last
3* WHERE table_name = 'EMPLOYEES'
TESTUSER@FREEPDB1> list 2
2* FROM user_tab_comments
TESTUSER@FREEPDB1> list * 2
2* FROM user_tab_comments
TESTUSER@FREEPDB1> list * 3
2 FROM user_tab_comments
3* WHERE table_name = 'EMPLOYEES'
TESTUSER@FREEPDB1> list *
3* WHERE table_name = 'EMPLOYEES'
充分理解星号表示第几行是当前行。
4、分号的作用:
当你看到语句末尾的;时,这仅表示该语句已经结束,并可以被SQL*Plus执行。LIST命令与;的使用是独立的。
总结
记住,LIST命令仅在你正在与SQLPlus进行交互时使用,用于查看或编辑缓冲区中的SQL语句。而;则是你告诉SQLPlus你已经完成了SQL语句的输入,可以执行它的信号。




