Home » SQL & PL/SQL » Client Tools » How to save contents? (SQL*PLUS COMMAND LINE (Oracle DB10g))
How to save contents? [message #401281] Sun, 03 May 2009 18:05 Go to next message
Konfused
Messages: 2
Registered: May 2009
Junior Member
Hi im quite (very!) new to SQL and Oracle,

basically in the command line, i have created a few tables, and inserted the relevent data..

I want to know how to 'save' everything I have done so far, so I can resume it tomorrow for example


We've been told (school) to use 'SPOOL c:\name.txt' or 'ed c:\name.sql' to do this, but it doesnt seem to work.

Also i was reading around, and came across the 'COMMIT' function which saves the data also?

Any help would be appreciated

Thanks
Re: How to save contents? [message #401285 is a reply to message #401281] Sun, 03 May 2009 18:10 Go to previous messageGo to next message
BlackSwan
Messages: 22845
Registered: January 2009
Senior Member
>Also i was reading around, and came across the 'COMMIT' function which saves the data also?
Good for you.
COMMIT will make the data permanent.

Go research the difference between DDL & DML.
In Oracle DDL statements have a implicit COMMIT; whereas DML can be ROLLBACK.


You need to help us by following the Posting Guidelines as stated below.
http://www.orafaq.com/forum/t/88153/0/

Re: How to save contents? [message #401306 is a reply to message #401281] Mon, 04 May 2009 00:35 Go to previous messageGo to next message
Littlefoot
Messages: 19651
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
As a newbie, you'd perhaps want to save all statements you've used in a file. SPOOL can't do that, so - use editor of your choice (such as Notepad on MS Windows) and put CREATE TABLE, INSERT INTO, ... in there so that you'll be able to review them later. There is a way to create all of these afterwards, but - as a newbie (again) - this is probably not what you should do now.

If overnight noone recreates schema you are working on, COMMIT will save data you've entered and/or modified so, in the morning, you'll find everything just as you've left yesterday afternoon. If not, you'll use file saved in the first paragraph of this message to set the whole environment up again.
Re: How to save contents? [message #401355 is a reply to message #401306] Mon, 04 May 2009 04:22 Go to previous messageGo to next message
Konfused
Messages: 2
Registered: May 2009
Junior Member
Thanks for the help,

When you say

use editor of your choice (such as Notepad on MS Windows) and put CREATE TABLE, INSERT INTO,

Would i have to enter it myself manually or is there a command i can type in the command line to do this, (assuming i've entered all of this in the command line before hand)
Re: How to save contents? [message #401362 is a reply to message #401355] Mon, 04 May 2009 04:48 Go to previous messageGo to next message
Littlefoot
Messages: 19651
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
SAVE SQL*Plus command will do the job; note that it will save only the last statement.
SQL> select count(*) from emp;

  COUNT(*)
----------
        14

SQL> select count(*) from dept;

  COUNT(*)
----------
         4

SQL> save my_count.sql
Created file my_count.sql
SQL>
SQL> get my_count.sql
  1* select count(*) from dept       --> see? Only the last statement has been saves!
SQL>
SQL> @my_count

  COUNT(*)
----------
         4

SQL>
Re: How to save contents? [message #404509 is a reply to message #401355] Fri, 22 May 2009 01:03 Go to previous message
Barbara Boehmer
Messages: 7991
Registered: November 2002
Location: California, USA
Senior Member
There is probably already a default editor set up. So, if, from the SQL*Plus command prompt you type:

ed c:\name.sql

it should open up a window that you can type in. You can put your create table, insert, and commit commands in there and save them. You can also add spool commands to spool the results to a file when you run the c:\name.sql. There should be a drop-down menu at the top where you can select file and save when you are done. So, if you enter something like:

spool c:\name.txt
drop table your_table;
create table your_table (your_column number);
insert into your_table (your_column) values (1);
commit;
spool off

and save it, then when you run it by typing from SQL*Plus:

start c:\name.sql

your table will be created, your data will be entered and saved, and the results will be spooled to a file c:\name.txt which you can then view by typing:

ed c:\name.txt
Previous Topic: output the result to a flat file in local PC
Next Topic: echo on slow with large stored procedure
Goto Forum:
  


Current Time: Thu Oct 02 01:13:34 CDT 2014

Total time taken to generate the page: 0.10545 seconds