1. Add data to the table (Insert statement):
Syntax to add:
INSERT into table_name (column1,column2,column3,......) VALUES (Value1,value2,value3,...)
The fields after table_name can be omitted, except that each field of values must match the defined field.
(1). First create a table:
Sql> Create TableUserInfo (2Id Number(6,0), 3Usernamevarchar2( -), 4Userpwdvarchar2( -), 5Emailvarchar2( -), 6regdate date)7; The table was created. SQL> descUserInfo; is the name empty? type----------------------------------------- -------- ----------------------------Id Number(6) USERNAMEVARCHAR2( -) UserpwdVARCHAR2( -) EMAILVARCHAR2( -) regdate Datesql>
(2), add values to all the fields in the table:
Sql> Select * fromUserInfo; ID USERNAME userpwd---------- -------------------- --------------------EMAIL regdate------------------------------ -------------- 1Xxx123456Ltwuyanlong@163. com --September- theSQL>
Note: sysdate is the function that gets the current time;
(3), add a value to the specified field in the table:
Sql> Insert intoUserInfo (ID,USERNAME,USERPWD)Values(2,'yyy','456123'); created1line. SQL> SelectUsername,userpwd fromUserInfo; USERNAME userpwd-------------------- --------------------Xxx123456yyy456123SQL>
(4), add a default value to the table:
Sql>SQL> Create TableUserinfo1 (2Id Number(6,0), 3RegDate Datedefaultsysdate); The table was created. SQL> Insert intoUserinfo12(ID)Values(1); created1line. SQL> Select * fromUserifo1;Select * fromUserifo1*Section1line error: ORA-00942: The table or view does not exist in SQL> Select * fromUserinfo1; ID RegDate---------- -------------- 1 --September- theSQL>
Adding a default value to a table is using the name of the defaults keyword;
5. Add a default value after modifying the table:
Sql> Alter TableUserInfo2Modify Emaildefault 'No'; The table has changed. SQL> Insert intoUserInfo (ID)Values(3); created1line. SQL> SelectId,email fromUserInfo; ID EMAIL---------- ------------------------------ 1Ltwuyanlong@163. com2 3No SQL>
Where default values are not applicable:
Sql> Insert intoUserInfo (ID, email)Values(4,'[email protected]'); created1line. SQL> SelectId,email fromUserInfo; ID EMAIL---------- ------------------------------ 1Ltwuyanlong@163. com2 3No4 631464569@163. Comsql>
Oracle Learning-----Data in the action table