我们已经知道,Trafodion提供CLI给用户以交互式的方式去操作数据库。常用的CLI包括Trafci和Sqlci。拿Trafci来说,当在服务器上或客户端执行trafci后便开启了一个会话,即Session。CLI中其实有很多命令是跟Session有关,下面就一一通过例子尝试一下。
- ENV/SESSION/SHOW SESSION
--显示当前会话的属性和设置
SQL>session;
COLSEP " "
HISTOPT DEFAULT [No expansion of script files]
IDLETIMEOUT 30 min(s)
LIST_COUNT 0 [All Rows]
LOG OFF
MARKUP RAW
PROMPT SQL>
SCHEMA SEABASE
SERVER localhost:23400
SQLTERMINATOR ;
STATISTICS OFF
TIME OFF
TIMING OFF
USER zz
- SET/SHOW IDLETIMEOUT
--设置会话的保留时间,单位是分钟,set idletimeout 0表示会话永不过期,通过show idletimeout显示设置
SQL>set idletimeout 0;
SQL>set idletimeout 5;
SQL>show idletimeout;
IDLETIMEOUT 1 min(s)
- SET PROMPT
--设置/修改CLI的提示符,默认是SQL>
SQL>set prompt "%USER ENTER>"
zz ENTER>
- SET TIME ON/OFF
--在提示前打印/隐藏出当前时间
SQL>set time on;
17:33:15 SQL>
17:33:18 SQL>set time off;
SQL>
- SET/SHOW SQLTERMINATOR
--设置SQL语句的结束标识符,默认是逗号
SQL>show sqlterminator;
SQLTERMINATOR ;
SQL>set sqlterminator .
SQL>select * from test1 .
A B
----------- ----------
1 Zhang
2 Li
--- 2 row(s) selected.
- SET TIMING ON/OFF
--显示/隐藏SQL语句执行时间
SQL>set timing on;
SQL>select * from test1;
A B
----------- ----------
1 Zhang
2 Li
--- 2 row(s) selected.
Elapsed: 00:00:00.006
SQL>set timing off;
- SET/SHOW SCHEMA
--设置/显示当前schema
SQL>show schema;
SCHEMA SEABASE
SQL>set schema "_MD_";
--- SQL operation complete.
SQL>show schema;
SCHEMA "_MD_"
- SET/SHOW LIST_COUNT
--设置SQL结果显示行数,默认值为0,表示不限制
SQL>show list_count;
LIST_COUNT 0 [All Rows]
SQL>set list_count 1;
SQL>select * from test1;
A B
----------- ----------
1 Zhang
--- 1 row(s) selected. LIST_COUNT was reached.
- HISTORY [number]
--显示当前SESSION中历史命令,可以指定显示几条
SQL>history;
1> show list_count;
2> set list_count 1;
3> select * from test1;
- SAVEHIST
--把历史命令保存成一个文件
SQL>savehist history.txt
SQL>exit
[trafodion@cent-2 sql]$ ls
history.txt scripts
[trafodion@cent-2 sql]$ cat history.txt
show list_count;
set list_count 1;
select * from test1;
history;
- FC [text | [-]number]
--编辑并重新执行一条历史命令,可以通过d删除字符,i插入字符,r替换字符;
--注:fc可以结合history一起使用,重新执行历史中固定的一条语句,默认指定上一条命令
SQL>select * from test1;
A B
----------- ----------
1 Zhang
2 Li
--- 2 row(s) selected.
SQL>fc
SQL>select * from test1;
....
A B
----------- ----------
1 Zhang
2 Li
--- 2 row(s) selected.
SQL>history
1> select * from test1;
2> select * from test1;
3> clear
4> select current_date from (values(1));
SQL>fc 1
SQL>select * from test1;
....
A B
----------- ----------
1 Zhang
2 Li
--- 2 row(s) selected.
- CLEAR
--清除当前界面中的所有输出,相当于LINUX下面的clear命令,执行完后提示符回到窗口最顶端