Professional Documents
Culture Documents
Table created.
1 row created.
1 row created.
1 row created.
Page | 1
SQL> alter table student add(pincode number(10));
Table altered.
Table renamed.
Page | 2
Table truncated.
no rows selected
Table dropped.
ERROR at line 1:
Page | 3
PRATICAL-2
Table created.
1 row created.
1 row created.
Page | 4
1 row created.
1 row created.
1 row created.
retrieving records from table student who are coming from eluru
Page | 5
---------- -------------------- ---------- ---------- --------------------
display the srollno and sname from student who are from class ‘bsc’
SROLLNO SNAME
---------- --------------------
11 ramakrishna
12 rama
13 pavan
14 vijay
15 murali
display the srollno from student who are from address ‘eluru’
SROLLNO
----------
12
13
Page | 6
display the details of student whose marks >= 300
display the srollno and sname from student whose marks < 300
SROLLNO SNAME
---------- --------------------
11 ramakrishna
15 murali
5 rows updated.
Page | 7
11 ramakrishna 200 bsc poranki
1 row updated.
5 rows updated.
Page | 8
SROLLNO SNAME MARKS CLASS ADDRESS
1 row deleted.
Table renamed.
Page | 9
SQL> select * from std;
SROLLNO NUMBER(10)
SNAME VARCHAR2(20)
MARKS NUMBER(3)
CLASS VARCHAR2(10)
ADDRESS VARCHAR2(20)
Table altered.
Page | 10
SROLLNO NUMBER(20)
SNAME VARCHAR2(20)
MARKS NUMBER(3)
CLASS VARCHAR2(10)
ADDRESS VARCHAR2(20)
PRATICAL-3
Check Constraints have the specific condition for each row of the table.
NOT NULL - Ensures that a column cannot have a NULL value .NOT accept NULL
values.
UNIQUE - Ensures that all values in a column are different
PRIMARY KEY - A combination of a NOT NULL and UNIQUE. Uniquely identifies each
row in a table
FOREIGN KEY - Prevents actions that would destroy links between tables
CHECK - Ensures that the values in a column satisfies a specific condition
DEFAULT - Sets a default value for a column if no value is specified
CREATE INDEX - Used to create and retrieve data from the database very quickly
However, you can have many UNIQUE constraints per table, but only one PRIMARY
KEY constraint per table.
Relation
Page | 11
CREATE TABLE supplier
( supplier_id numeric(10) not null,
supplier_name varchar2(50) not null,
contact_name varchar2(50),
CONSTRAINT supplier_pk PRIMARY KEY (supplier_id)
);
ALIASES
This Oracle tutorial explains how to use Oracle ALIASES (temporary names for columns or tables)
with syntax and examples.
Page | 12
Using an ALTER TABLE statement
The syntax for creating a check constraint in an ALTER TABLE statement in Oracle is:
ALTER TABLE table_name
ADD CONSTRAINT constraint_name CHECK (column_name condition) [DISABLE];
create a table with tablename customers with following fields and constraints
1)customer number must start with c and should not repeat and should not be null
Page | 13
check(address in('poranki','patamata','mogulrajpuram')),
Table created.
CNAME VARCHAR2(20)
DEPOSIT NUMBER(10)
ERROR at line 1:
Page | 14
SQL> insert into customers values('101','rajesh',50000,'poranki');
ERROR at line 1:
1 row created.
ERROR at line 1:
1 row created.
ERROR at line 1:
Page | 15
SQL> insert into customers values('','rakesh',60000,'');
ERROR at line 1:
1 row created.
1 row created.
SELECT statement is used to retrieve records from one or more tables in an Oracle database
The Oracle WHERE clause is used to filter the results from a SELECT, INSERT, UPDATE,
or DELETE statement.
Syntax
WHERE conditions;
Page | 16
Examples:
SELECT *
FROM customers
WHERE last_name = 'Anderson';
SELECT *
FROM suppliers
WHERE state = 'California'
AND supplier_id <= 750;
SELECT supplier_id
FROM suppliers
WHERE supplier_name = 'Apple'
OR supplier_name = 'Microsoft';
GROUP BY Clause
The Oracle GROUP BY clause is used in a SELECT statement to collect data across multiple records and
group the results by one or more columns.
SELECT expression1, expression2, ... expression_n,
aggregate_function (aggregate_expression)
FROM tables
WHERE conditions
GROUP BY expression1, expression2, ... expression_n;
Page | 17
SELECT item, SUM(sale) AS "Total sales"
FROM salesdepartment
GROUP BY item;
PRATICAL-4
Table created.
Page | 18
1 row created.
1 row created.
1 row created.
1 row created.
Page | 19
103 govardhan bca 950
retrieve all information of the students whose names ends with character ‘a’
retrieve all information of the students whose names starts with character ‘a’
Page | 20
---------- -------------------- ---------- ----------
retrieve all information of the students whose names includes with character ‘a’
Page | 21
retrieve all information of the students according to their highest marks
SNO
----------
103
102
101
104
retrieve all information of the students who are not from bca and bba
Page | 22
104 krishna bzc 700
retrieve all information of the students where sno between 101 and 104
SQL> select * from student where sno between 101 and 104;
retrieve all information of the students where sno not between 103 and 104
SQL> select * from student where sno not between 103 and 104;
Page | 23
retrieve all information of the students who are from bzc and bsc classes
2 rows updated.
Page | 24
SQL> select * from student20;
PRATICAL-6
alary number(6));
Table created.
Page | 25
1 row created.
1 row created.
1 row created.
1 row created.
1 rajesh 3 25000
2 rakesh 4 30000
3 ramesh 5 45000
Page | 26
4 ravi 2 50000
SUM(SALARY)
-----------
150000
MAX(SALARY)
-----------
50000
MIN(SALARY)
-----------
25000
AVG(SALARY)
-----------
37500
Page | 27
SQL> select count(*) from emp100;
COUNT(*)
----------
PRATICAL-7
LOWER
----
dbms
Page | 28
SQL> select upper('dbms') from dual;
UPPER
----
DBMS
INIT
----
Dbms
SUBST
-----
tabas
LENGTH('DATABASE')
------------------
Page | 29
LTRIM
------
tabase
RTRIM
------
databa
LPAD('DATA’)
----------
******data
RPAD('DATA’)
----------
data******
Page | 30
PRATICAL-8
ABS(-10)
----------
Page | 31
10
POWER(2,3)
----------
ROUND(9.83456,2)
----------------
9.83
SQRT(9)
----------
PRATICAL-9
SYSDATE
---------
Page | 32
28-JUL-18
ADD_MONTH
---------
28-NOV-18
LAST_DAY
---------
31-JUL-18
MONTHS_BETWEEN('02-MAY-17','02-JAN-17')
---------------------------------------
NEXT_DAY
---------
01-AUG-18
Page | 33
PRATICAL-10
Page | 34
SQL> create table customer(cno number(10) primary key,cname varchar2(20),deposit number(10),address
varchar2(20));
Table created.
CNAME VARCHAR2(20)
DEPOSIT NUMBER(10)
ADDRESS VARCHAR2(20)
View created.
CNAME VARCHAR2(20)
Page | 35
SQL> insert into cust1 values(11,'rajesh');
1 row created.
1 row created.
CNO CNAME
---------- --------------------
11 rajesh
12 ramesh
1 row updated.
SQL> create view cust2 as select cno,cname from customer with read only;
View created.
Page | 36
SQL> insert into cust2 values(14,'rakesh');
ERROR at line 1:
PRATICAL-11
SQL> create table emp(eno number(10) primary key ,ename varchar2(10),salary number(6),deptno
number(10));
Page | 38
SQL> SELECT * FROM DEPT;
DEPTNO LOCATION
---------- --------------------
10 amaravathi
20 chennai
30 hyd
40 delhi
50 mumbai
Page | 39
103 balu 10000 20 20 chennai
50 mumbai
40 delhi
50 mumbai
40 delhi
Page | 41
Page | 42
What is DCL?
DCL (Data Control Language) includes commands like GRANT and REVOKE, which are
useful to give "rights & permissions." Other permission controls parameters of the database
system.
Grant
Page | 43
Revoke
Grant:
This command is use to give user access privileges to a database.
Syntax:
For example:
Revoke:
It is useful to back permissions from the user.
Syntax:
For example:
Page | 44
Page | 45
Page | 46