Tuesday, November 3, 2009

CRITICAL SKILL 2.2 Use Basic insert and select Statements


Team Fly 


Page 36



All DML commands require reference to an object that will be manipulated. More often than not, the object being referenced is a table.



A conditional statement can be added to any select, update, or delete command. Absence of a conditional statement means that the command will be performed against every record in the object. A conditional statement is used when the DML command is intended to only act upon a group of records that meet a specific condition. The where clause will be discussed a little later in this chapter.



More optional DML statements will be described later in this chapter. For now, let's concentrate on understanding the fundamental structure of each DML statement starting with the insert and select statements.



CRITICAL SKILL 2.2
Use Basic insert and select Statements



Getting data into and out of a database are two of the most important features of a database. Oracle provides two basic features that help you do just that. To get data into the database, use the insert command; to get it back out, use the select command. You must master these commands, as they form the basic of most data access to your Oracle database. This section talks first about how to get data into your database, and then how to get data out.



insert



Using the state table created in the DDL example, the following is an illustration of using the insert statement in its simplest form:




SQL> insert into state values ('AZ','Arizona');
1 row created.


Each time you execute an insert command, you receive the message ''1 row created." Thus, you get immediate feedback that you are populating the given table with data. When you load data into a table, you may also specify the column to load it into. This ensures that there is no mistaking where you want the data to be placed. In the next example, the columns are specified after the insert command:




SQL> insert into state (state_cd, state_name) values ('NJ','New Jersey');
1 row created.
SQL> insert into state (state_cd, state_name) values ('CA','California');
1 row created.
SQL> insert into state (state_cd, state_name) values ('TX','Texas');


Team Fly 

No comments:

Post a Comment