Tuesday, July 5, 2016

Oracle SQL Command Line Tricks for Beginners

This is Oracle SQL Command Line Tricks for beginners. Simply do the following:

1. First Open "Run SQL Command Line"
2. Type conn username/password
 For example: conn SYSTEM/vijaya
or simply you can type: conn
Then, it will ask for username. It will show "Enter user-name:", type "vijaya"
Then, it will ask for password. Enter your password: Vijaya
Voila! You're connected.

Type:
select * from student
It will display "2" because you didn't enter semicolon after sql query. enter semicolon.

Then, you will see the table data from student.

If you don't have any table, you can simply create a database using:
create table student(
id int not null,
name varchar(20) not null,
marks int,
primary key (id)
);

To insert new data, you can simply do the following:
insert into student values (1, 'Vijaya', 80);

Or, you can insert by doing:

insert into student values (&id, '&name', &marks);
then, it will display:
Enter value for id: (enter your id) eg. 2
Enter value for name: (enter your name) eg. Hari
Enter value for marks: (enter your marks) eg. 78
Hit Enter,
then it will display:
1 row created.

If you want to commit your changes, type: commit; and hit enter.
then, you will see "commit complete" message.

If you want to insert multiple rows into the table, you can simply type forward slash "/" and hit enter.
It will repeat the same message again:
Enter value for id: (enter your id)
Enter value for name: (enter your name)
Enter value for marks: (enter your marks)
Hit Enter.

This is tested on Windows 10, Oracle XE 11g.

No comments:

Post a Comment