Oracle Basic Commands for Beginners

Oracle Basic Commands for Beginners.

To practice oracle basic commands, first install Oracle database on home computer/laptop. Follow the below link.

Now start practicing below commands by using SQL Plus

Connecting to SQL PLUS:

Type SQL plus in search bar and follow the below commands.

1)
Command to connect to oracle database as super user

Enter user-name: /as sysdba

 

2)

create user and grant

SQL> create user Thomas identified by Thomas123;

User created.

 

SQL> grant connect,resource to Thomas;

Grant succeeded.

 

SQL> grant unlimited tablespace to Thomas;

Grant succeeded.

And click on exit

 

3)
Command to connect a normal user

Method 1:

Enter user-name: Thomas/Thomas123@orcl

Connected to:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 – Production
Version 19.3.0.0.0

SQL> show user
USER is “Thomas”

or u can connect as given below

 

Method 2:

Enter user-name: Thomas@orcl
Enter password:
Last Successful login time: Thu Nov 09 2023 13:50:35 +05:30Connected to:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 – Production
Version 19.3.0.0.0

 

4)
creating table

SQL> create table names1(first_name varchar2(20), last_name varchar2(20));

Table created.

 

To know the structure of the table,

SQL> describe names
Name Null? Type
—————————————– ——– —————————-
NAME VARCHAR2(20)
LAST_NAME VARCHAR2(20)

 

To display all the tables information in the current user,

SQL> select * from tab;

TNAME
——————————————————————————–
TABTYPE CLUSTERID
————- ———-
NAMES
TABLE

 

To insert the data into the table,

SQL> insert into names values (‘kyte’,’T’);

1 row created.

 

To view the data in the table,

SQL> select * from names;

NAME LAST_NAME
——————– ——————–
kyte        T

 

 

5)
Creating table and inserting data

To connect to Normal user,

Enter user-name: Thomas@orcl
Enter password:Connected to:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 – Production
Version 19.3.0.0.0

 

SQL> create table names(first_name varchar2(20), last_name varchar2(20));

Table created.

 

SQL> insert into names values (‘virat’,’kohli’);

1 row created.

 

To get the prompt while inserting data we use “&” symbol before the coloumn name,

SQL> insert into names values (‘&first_name’,’&last_name’);
Enter value for first_name: Hardik
Enter value for last_name: Pandiya
old 1: insert into names values (‘&first_name’,’&last_name’)
new 1: insert into names values (‘Hardik’,’Pandiya’)1 row created.

 

SQL> insert into names values (‘&first_name’,’&last_name’)
2 ;
Enter value for first_name: shubman
Enter value for last_name: gill
old 1: insert into names values (‘&first_name’,’&last_name’)
new 1: insert into names values (‘shubman’,’gill’)1 row created.

 

To repeat previous command we use “Forward Slash (/)”,

SQL> /
Enter value for first_name: ishan
Enter value for last_name: kishan
old 1: insert into names values (‘&first_name’,’&last_name’)
new 1: insert into names values (‘ishan’,’kishan’)1 row created.

 

SQL> /
Enter value for first_name: rohit
Enter value for last_name: sharma
old 1: insert into names values (‘&first_name’,’&last_name’)
new 1: insert into names values (‘rohit’,’sharma’)1 row created.

 

SQL> /
Enter value for first_name: shreyas
Enter value for last_name: iyer
old 1: insert into names values (‘&first_name’,’&last_name’)
new 1: insert into names values (‘shreyas’,’iyer’)1 row created.

 

To view all the names:

SQL> select * from names;

FIRST_NAME LAST_NAME
——————– ——————–
virat kohli
Hardik Pandiya
shubman gill
ishan kishan
rohit sharma
shreyas iyer

6 rows selected.

 

 

See Also: