Skip to Content
Oracle SQL*Plus Pocket Reference, 3rd Edition
book

Oracle SQL*Plus Pocket Reference, 3rd Edition

by Jonathan Gennick
November 2004
Intermediate to advanced
152 pages
2h 50m
English
O'Reilly Media, Inc.
Content preview from Oracle SQL*Plus Pocket Reference, 3rd Edition

Inserting Data

Use the INSERT statement to add new rows to a table. In Oracle9i Database and higher, you have the ability to perform direct path and multitable inserts. For the examples in this section, I’ve added a column to the COURSE table shown previously in the section on Table Joins (Oracle9i and Higher):

ALTER TABLE COURSE ADD (
   course_hours NUMBER DEFAULT 4);

Inserting One Row

To insert one row into a table, specify the list of columns for which you wish to insert a value and use the VALUES clause to specify values for the columns in your list:

INSERT INTO COURSE (course_name, period, course_hours)
VALUES ('French I', 5, DEFAULT);

The DEFAULT keyword is new in Oracle9i Database and is used in this query to explicitly request the default value for the course_hours column. You can use the NULL keyword, available in all releases of Oracle, to explicitly insert a null into a column.

You can omit the list of columns if you provide a value for each column in your table, and if you provide those values in the same order in which the columns are listed when you DESCRIBE the table:

INSERT INTO COURSE
VALUES ('French I', 5, DEFAULT);

I don’t recommend this shortcut unless you are just typing in a one-off query interactively. It’s safer to specify the column names.

Inserting the Results of a Query

Use the INSERT...SELECT...FROM syntax to insert the results of a query into a table. For example, the following INSERT statement creates a new row in the COURSE table for any currently undefined courses ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Oracle SQL*Plus Pocket Reference

Oracle SQL*Plus Pocket Reference

Jonathan Gennick

Publisher Resources

ISBN: 9781491926680Errata Page