How do you save SQL work in Oracle?

LuDaCriS66

Platinum Member
Nov 21, 2001
2,057
0
0
If I use SQL*Plus in Oracle.. how are you supposed to save your work? As in printout what you typed up and so on.
The prof said to "Create a script file and execute the queries using spooling to a file." but I'm not sure what he means by that.

any ideas?
 

Linflas

Lifer
Jan 30, 2001
15,395
78
91
There is a command you issue in SQL Plus to do this, I am searching for one of my scripts now since I don't use this all that much.

Got it, it is Spool and the path and file name ie "spool c:\test\test.sql"
 

Linflas

Lifer
Jan 30, 2001
15,395
78
91
Dunno I just tried it on the system here and it worked. Maybe try it using the File menu. In SQL Plus do File-> Spool->File and try it that way.
 

Linflas

Lifer
Jan 30, 2001
15,395
78
91
It spools real time so it will not place previous commands in the file, only commands executed after the spool was turned on. Up arrow should work to get your old commands back I think.
 

LuDaCriS66

Platinum Member
Nov 21, 2001
2,057
0
0
hm.. yeah it looks like I lost everything I did earlier.. fortunately it wasn't a whole lot.

thanks for the help
 

LuDaCriS66

Platinum Member
Nov 21, 2001
2,057
0
0
Yeah.. I didn't think of the notepad thing at first..


btw,
can anyone think of a way to use both the "insert" and "select" functions to add a new field that copies itself from an exisiting field?
 

isasir

Diamond Member
Aug 8, 2000
8,609
0
0
Originally posted by: LuDaCriS66
Yeah.. I didn't think of the notepad thing at first..


btw,
can anyone think of a way to use both the "insert" and "select" functions to add a new field that copies itself from an exisiting field?

Yup. But do your own damn homework. ;)
 

LuDaCriS66

Platinum Member
Nov 21, 2001
2,057
0
0
Originally posted by: RishiS
Originally posted by: LuDaCriS66
Yeah.. I didn't think of the notepad thing at first..


btw,
can anyone think of a way to use both the "insert" and "select" functions to add a new field that copies itself from an exisiting field?

Yup. But do your own damn homework. ;)

I'm tryin.. lol.. it's a tough class when your teacher is from India and has a damn strong accent.. can't understand a word he says. I'm basically trying to learn this thing from the book
 

xchangx

Golden Member
Mar 23, 2000
1,692
1
71
cut and paste it to a text file, rename it to .sql

edit using notepad and put in the syntax to use a script.

I can't remember how to import a file, I think $c:\file.sql

 

xchangx

Golden Member
Mar 23, 2000
1,692
1
71
Here's a copy of a script:

SET TERMOUT ON

CREATE TABLE CUSTOMER(
CID NUMBER(3) NOT NULL,
CLASTNAME VARCHAR2(25) NOT NULL,
CFIRSTNAME VARCHAR2(15) NOT NULL,
AGE NUMBER(2),
RESID_CITY VARCHAR2(30),
CONSTRAINT CUST_CID_PK PRIMARY KEY (CID));

INSERT INTO CUSTOMER VALUES (101,'BLACK','JACK', 40, 'ERIE');
INSERT INTO CUSTOMER VALUES (102,'GREEN','MARY', 25, 'CARY');
INSERT INTO CUSTOMER VALUES (103,'JONES','DAVEY', 30, 'HEMET');
INSERT INTO CUSTOMER VALUES (104,'MARTIN','STEVE', 35, 'HEMET');
INSERT INTO CUSTOMER VALUES (105,'SIMON','SAINT', 22, 'ERIE');
INSERT INTO CUSTOMER VALUES (106,'VERNON','MIKE', 60, 'CARY');

CREATE TABLE RENTCOST (
MAKE VARCHAR(15) NOT NULL,
COST NUMBER(2),
CONSTRAINT RENTCOST_MAKE_PK PRIMARY KEY (MAKE));

INSERT INTO RENTCOST VALUES ('FORD', 30);
INSERT INTO RENTCOST VALUES ('GM', 40);
INSERT INTO RENTCOST VALUES ('NISSAN', 30);
INSERT INTO RENTCOST VALUES ('TOYOTA', 20);
INSERT INTO RENTCOST VALUES ('VOLVO', 50);

CREATE TABLE CITYADJ (
CITY VARCHAR2(30) NOT NULL,
FACTOR NUMBER (2, 1),
CONSTRAINT CITYADJ_CITY_PK PRIMARY KEY (CITY));

INSERT INTO CITYADJ VALUES ('CARY', 1);
INSERT INTO CITYADJ VALUES ('ERIE', 1.1);
INSERT INTO CITYADJ VALUES ('RENO', 0.9);
INSERT INTO CITYADJ VALUES ('TAMPA', 0.8);

CREATE TABLE RENTAL (
RID NUMBER (4) NOT NULL,
CID NUMBER (3) NOT NULL,
MAKE VARCHAR2 (15) NOT NULL,
DATE_OUT DATE NOT NULL,
DATE_RETURN DATE,
PICKUP VARCHAR2 (30) NOT NULL,
RETURN VARCHAR2 (30),
COMMENTS LONG,
CONSTRAINT RENTAL_RID_PK PRIMARY KEY (RID),
CONSTRAINT RENTAL_CID_FK FOREIGN KEY (CID) REFERENCES CUSTOMER (CID),
CONSTRAINT RENTAL_MAKE_FK FOREIGN KEY (MAKE) REFERENCES RENTCOST (MAKE),
CONSTRAINT RENTAL_RETURN_FK FOREIGN KEY (RETURN) REFERENCES CITYADJ (CITY));

INSERT INTO RENTAL
VALUES (1, 101, 'FORD', '10-OCT-1994', '11-OCT-1994', 'CARY', 'CARY', NULL);
INSERT INTO RENTAL
VALUES (2, 101, 'GM', '01-NOV-1995', '04-NOV-1995', 'TAMPA', 'CARY', NULL);
INSERT INTO RENTAL
VALUES (3, 101, 'FORD', '01-JAN-1995', '03-JAN-1995', 'ERIE', 'ERIE', NULL);
INSERT INTO RENTAL
VALUES (4, 102, 'NISSAN', '07-JUL-1994', '09-JUL-1994', 'TAMPA', 'TAMPA', NULL);
INSERT INTO RENTAL
VALUES (5, 103, 'FORD', '01-JUL-1995', '05-JUL-1995', 'CARY', 'ERIE', NULL);
INSERT INTO RENTAL
VALUES (6, 103, 'GM', '01-AUG-1995', '03-AUG-1995', 'ERIE', 'ERIE', NULL);
INSERT INTO RENTAL
VALUES (7, 104, 'FORD', '01-AUG-1994', '04-AUG-1994', 'CARY', 'ERIE', NULL);
INSERT INTO RENTAL
VALUES (8, 105, 'GM', '01-SEP-1995', '02-SEP-1995', 'ERIE', 'CARY', NULL);
INSERT INTO RENTAL
VALUES (9, 106, 'TOYOTA', '02-SEP-1995', NULL, 'RENO', 'RENO', NULL);