Thursday, 4 May 2017

HOW TO WRITE INSERT STATEMENT IN ORACLE SQL


INSERT:  Insert the records into the table.
We have two methods of inserts
a.       Value Method
b.       Address Method
a. Value Method: In this method, we are going to insert the values into the row by one by one.
SYNTAX: insert into <table_name) values (value1, value2, value3 …. Valuen);
EX:
Insert Values:
1
Visu
100
2
Vasu
200

                                i.            insert into student values (1, ’VISU’, 100);
                               ii.            insert into student values (2, ’VASU’, 200);
Output: For checking the output we are going to write the select statement. (select * from student;)
NO
NAME
MARKS
1
Visu
100
2
Vasu
200
     To insert a new record again you have to type entire insert command, if there are a lot of records this will be difficult. This will be avoided by using address method.
b. ADDRESS METHOD: This will prompt you for the values.
SYNTAX: insert into <table_name) values (&col1, &col2, &col3 …. &coln);
EX: Insert Values in the prompt:
3
Manoj
300
4
Aisu
400
5
Mohan
500
6
Manvi
600
7
Namu
500
8
Susu
300
 insert into student values (&no, '&name', &marks);
Output:  Prompt will pop up as
NO:
NAME:
MARKS:
In that pop up’s we are going to enter the values. After entering the values the table looks like this, for checking the output we are going to write the select statement. (select * from student;)
NO
NAME
MARKS
1
Visu
100
2
Vasu
200
3
Manoj
300
4
Aisu
400
5
Mohan
500
6
Manvi
600
7
Namu
500
8
Susu
300

c. INSERTING DATA INTO SPECIFIED COLUMNS USING VALUE METHOD:
Syntax: Insert into <table_name)(col1, col2, col3 … Coln) values (value1, value2, value3 …. Valuen);
Ex:  Insert Values:
9
Thanu
200
10
AJ
100

        i.            SQL> insert into student (no, name, marks) values (9, ’Thanu’,200);
       ii.            SQL> insert into student (no, name, marks) values (10, ’AJ’,100);
Output: For checking the output we are going to write select statement. (select * from student;)

NO
NAME
MARKS
1
Visu
100
2
Vasu
200
3
Manoj
300
4
Aisu
400
5
Mohan
500
6
Manvi
600
7
Namu
500
8
Susu
300
9
Thanu
200
10
AJ
100

d. INSERTING DATA INTO SPECIFIED COLUMNS USING ADDRESS METHOD: This will prompt you for the values.
Syntax: Insert into <table_name)(col1, col2, col3 … coln) values (&col1, &col2 ….&coln);                                                                              Insert Values:
11
MK
12
MD

EX: SQL> insert into student (no, name) values (&no, '&name');
NO:
NAME:
In that pop up’s we are going to enter the values. After entering the values the table looks like this, for checking the output we are going to write the select statement. (select * from student;)

NO
NAME
MARKS
1
Visu
100
2
Vasu
200
3
Manoj
300
4
Aisu
400
5
Mohan
500
6
Manvi
600
7
Namu
500
8
Susu
300
9
Thanu
200
10
AJ
100
11
MK
(null)
12
MD
(null)

No comments:

Post a Comment