我有这个表和示例数据,我想在文件中假脱机。 我不确定什么是正确的方法或语法。我从互联网上尝试了几种方法,但无法得到正确的答案。
CREATE TABLE RoomType
(
RoomType Varchar2(25),
RoomTypeDesc Varchar2(50)
);
INSERT INTO RoomType VALUES ('STD', 'Standard Room');
INSERT INTO RoomType VALUES ('Business', 'Business Class');
答案 0 :(得分:0)
SPOOL path/file/to/save/log.log(or txt)
PROMPT ************************************
PROMPT *** CREATION OF OBJECTS ***
PROMPT ************************************
CREATE TABLE RoomType
(
RoomType Varchar2(25),
RoomTypeDesc Varchar2(50)
);
PROMPT ************************************
PROMPT *** INSERTION ***
PROMPT ************************************
INSERT INTO RoomType VALUES (STD, 'Standard Room');
INSERT INTO RoomType VALUES (Business, 'Business Class');
答案 1 :(得分:0)
使用您喜欢的编辑器(如vi
)将您的命令保存在一个文件中,在您喜欢的路径中(让我们将/home/oracle/scripts
)作为.sql
文件:
[oracle@DoonieDB scripts]$ vi RoomTypes.sql
set term[out] off
set feed[back] off
col RoomType format a25
col RoomTypeDesc format a25
spool /home/oracle/scripts/RoomTypes.txt
select * from RoomType;
spool off;
其中col设置用于限制列的长度以使它们保持单行。
连接到您的相关架构,并通过添加.sql
符号前缀来@
,并使用格式化信息获取RoomTypes.txt
文件:
[oracle@DoonieDB scripts]$ pwd
/home/oracle/scripts
[oracle@DoonieDB scripts]$ sqlplus hotels/myKey
...
Connected to:
Oracle Database xxx Enterprise Edition Release 1x.x.x.x.x - 64bit Production
SQL> @RoomTypes.sql
SQL> exit
Disconnected from Oracle Database xxx Enterprise Edition Release 1x.x.x.x.x - 64bit Production
[oracle@barbdb12c scripts]$ cat RoomTypes.txt
ROOMTYPE ROOMTYPEDESC
------------------------- -------------------------
STD Standard Room
Business Business Class