You are on page 1of 8

SQL> create table employee(id number primary key,name varchar2(7),dept varchar2( 10),salary number); Table created.

SQL> insert into employee values(&id,'&name','&dept',&salary); Enter value for id: 1 Enter value for name: praju Enter value for dept: comp Enter value for salary: 50000 old 1: insert into employee values(&id,'&name','&dept',&salary) new 1: insert into employee values(1,'praju','comp',50000) 1 row created. SQL> / Enter value for Enter value for Enter value for Enter value for old 1: insert new 1: insert 1 row created. SQL> / Enter value for id: 3 Enter value for name: kshitija Enter value for dept: entc Enter value for salary: 60000 old 1: insert into employee values(&id,'&name','&dept',&salary) new 1: insert into employee values(3,'kshitija','entc',60000) insert into employee values(3,'kshitija','entc',60000) * ERROR at line 1: ORA-12899: value too large for column "SYSTEM"."EMPLOYEE"."NAME" (actual: 8, maximum: 7) SQL> insert into employee values(&id,'&name','&dept',&salary); Enter value for id: 3 Enter value for name: kshiti Enter value for dept: entc Enter value for salary: 60000 old 1: insert into employee values(&id,'&name','&dept',&salary) new 1: insert into employee values(3,'kshiti','entc',60000) 1 row created. SQL> / Enter value for Enter value for Enter value for Enter value for old 1: insert new 1: insert 1 row created. id: 4 name: snehal dept: civil salary: 55000 into employee values(&id,'&name','&dept',&salary) into employee values(4,'snehal','civil',55000) id: 2 name: sakshi dept: mech salary: 45000 into employee values(&id,'&name','&dept',&salary) into employee values(2,'sakshi','mech',45000)

SQL> select * from employee; ID ---------1 2 3 4 NAME ------praju sakshi kshiti snehal DEPT SALARY ---------- ---------comp 50000 mech 45000 entc 60000 civil 55000

SQL> create or replace view vemployee(id,name,dept) as select id,name,dept from employee; View created. SQL> select * from vemployee; ID ---------1 2 3 4 NAME ------praju sakshi kshiti snehal DEPT ---------comp mech entc civil

SQL> insert into employee values(&id,'&name','&dept',&salary); Enter value for id: 5 Enter value for name: gauri Enter value for dept: it Enter value for salary: 40000 old 1: insert into employee values(&id,'&name','&dept',&salary) new 1: insert into employee values(5,'gauri','it',40000) 1 row created. SQL> select * from vemployee; ID ---------1 2 3 4 5 NAME ------praju sakshi kshiti snehal gauri DEPT ---------comp mech entc civil it

SQL> create index iemp1 on employee(name); Index created. SQL> select * from employee; ID ---------1 2 3 4 5 NAME ------praju sakshi kshiti snehal gauri DEPT SALARY ---------- ---------comp 50000 mech 45000 entc 60000 civil 55000 it 40000

SQL> select id,name from employee where iemp1=2; select id,name from employee where iemp1=2 *

ERROR at line 1: ORA-00904: "IEMP1": invalid identifier SQL> update employee set id=iemp1; update employee set id=iemp1 * ERROR at line 1: ORA-00904: "IEMP1": invalid identifier SQL> create sequence seq_empl start with 6 increment by 1; Sequence created. SQL> update employee set id=seq_emp1.nextval; update employee set id=seq_emp1.nextval * ERROR at line 1: ORA-02289: sequence does not exist SQL> select * from employee; ID ---------1 2 3 4 5 NAME ------praju sakshi kshiti snehal gauri DEPT SALARY ---------- ---------comp 50000 mech 45000 entc 60000 civil 55000 it 40000

SQL> update employee set id=seq_empl.nextval; 5 rows updated. SQL> select * from employee; ID ---------6 7 8 9 10 NAME ------praju sakshi kshiti snehal gauri DEPT SALARY ---------- ---------comp 50000 mech 45000 entc 60000 civil 55000 it 40000

SQL> create synonym emp for employee; Synonym created. SQL> select * from emp; ID ---------6 7 8 9 10 NAME ------praju sakshi kshiti snehal gauri DEPT SALARY ---------- ---------comp 50000 mech 45000 entc 60000 civil 55000 it 40000

SQL> update employee set dept=comp where name=gauri; update employee set dept=comp where name=gauri * ERROR at line 1: ORA-00904: "GAURI": invalid identifier SQL> update employee set dept=comp where name='gauri'; update employee set dept=comp where name='gauri' * ERROR at line 1: ORA-00904: "COMP": invalid identifier SQL> update employee set dept='comp' where name='gauri'; 1 row updated. SQL> select * from employee; ID ---------6 7 8 9 10 NAME ------praju sakshi kshiti snehal gauri DEPT SALARY ---------- ---------comp 50000 mech 45000 entc 60000 civil 55000 comp 40000

SQL> delete from employee where name='gauri'; 1 row deleted. SQL> select * from employee; ID ---------6 7 8 9 NAME ------praju sakshi kshiti snehal DEPT SALARY ---------- ---------comp 50000 mech 45000 entc 60000 civil 55000

SQL> delete from employee; 4 rows deleted. SQL> select * from employee; no rows selected SQL> desc employee; Name Null? ----------------------------------------- -------ID NOT NULL NAME DEPT SALARY Type ---------------------------NUMBER VARCHAR2(7) VARCHAR2(10) NUMBER

SQL> insert into employee values(&id,'&name','&dept',&salary); Enter value for id: 1 Enter value for name: raj

Enter Enter old new

value for value for 1: insert 1: insert

dept: hr salary: 20 into employee values(&id,'&name','&dept',&salary) into employee values(1,'raj','hr',20)

1 row created. SQL> / Enter value for Enter value for Enter value for Enter value for old 1: insert new 1: insert 1 row created. SQL> / Enter value for Enter value for Enter value for Enter value for old 1: insert new 1: insert 1 row created. SQL> / Enter value for Enter value for Enter value for Enter value for old 1: insert new 1: insert 1 row created. SQL> SQL> select * from employee; ID ---------1 2 7 9 NAME ------raj rohan ram raju DEPT SALARY ---------- ---------hr 20 test 50 cod 3 hr 36 id: 9 name: raju dept: hr salary: 36 into employee values(&id,'&name','&dept',&salary) into employee values(9,'raju','hr',36) id: 7 name: ram dept: cod salary: 3 into employee values(&id,'&name','&dept',&salary) into employee values(7,'ram','cod',3) id: 2 name: rohan dept: test salary: 50 into employee values(&id,'&name','&dept',&salary) into employee values(2,'rohan','test',50)

SQL> select min(salary) from employee; MIN(SALARY) ----------3 SQL> select max(salary),avg(salary),sum(salary) from employee; MAX(SALARY) AVG(SALARY) SUM(SALARY) ----------- ----------- ----------50 27.25 109 SQL> create table stud(roll_no number,name1 varchar2(6),dept varchar2(6));

create table stud(roll_no number,name1 varchar2(6),dept varchar2(6)) * ERROR at line 1: ORA-00955: name is already used by an existing object SQL> create table stuud(roll_no number,name1 varchar2(6),dept varchar2(6)); Table created. SQL> insert into stuud values(&roll_no,'&name1','&dept'); Enter value for roll_no: 1 Enter value for name1: asd Enter value for dept: hr old 1: insert into stuud values(&roll_no,'&name1','&dept') new 1: insert into stuud values(1,'asd','hr') 1 row created. SQL> / Enter value for Enter value for Enter value for old 1: insert new 1: insert 1 row created. SQL> / Enter value for Enter value for Enter value for old 1: insert new 1: insert 1 row created. SQL> / Enter value for Enter value for Enter value for old 1: insert new 1: insert 1 row created. SQL> select * from stuud; ROLL_NO ---------1 2 5 7 NAME1 -----asd rohan ghj dgf DEPT -----hr test kkl iop roll_no: 7 name1: dgf dept: iop into stuud values(&roll_no,'&name1','&dept') into stuud values(7,'dgf','iop') roll_no: 5 name1: ghj dept: kkl into stuud values(&roll_no,'&name1','&dept') into stuud values(5,'ghj','kkl') roll_no: 2 name1: rohan dept: test into stuud values(&roll_no,'&name1','&dept') into stuud values(2,'rohan','test')

SQL> select dept from employee union all select dept from stuud; DEPT ---------hr

test cod hr hr test kkl iop 8 rows selected. SQL> select id,name,dept from employee union all select roll_no,name1,dept from stuud; ID ---------1 2 7 9 1 2 5 7 NAME ------raj rohan ram raju asd rohan ghj dgf DEPT ---------hr test cod hr hr test kkl iop

8 rows selected. SQL> select id,name,dept from employee union select roll_no,name1,dept from stuu d; ID ---------1 1 2 5 7 7 9 NAME ------asd raj rohan ghj dgf ram raju DEPT ---------hr hr test kkl iop cod hr

7 rows selected. SQL> select id,name,dept from employee intersect select roll_no,name1,dept from stuud; ID NAME DEPT ---------- ------- ---------2 rohan test SQL> SQL> select id,name,dept from employee minus select roll_no,name1,dept from stuu d; ID ---------1 7 9 NAME ------raj ram raju DEPT ---------hr cod hr

SQL> select id,name,dept,salary from employee order by salary;

ID ---------7 1 9 2

NAME ------ram raj raju rohan

DEPT SALARY ---------- ---------cod 3 hr 20 hr 36 test 50

SQL> select id,name,dept,salary from employee order by salary desc; ID ---------2 9 1 7 NAME ------rohan raju raj ram DEPT SALARY ---------- ---------test 50 hr 36 hr 20 cod 3

SQL> select id,name,dept,avg(salary) from employee group by dept; select id,name,dept,avg(salary) from employee group by dept * ERROR at line 1: ORA-00979: not a GROUP BY expression SQL> select dept,avg(salary) from employee group by dept; DEPT AVG(SALARY) ---------- ----------hr 28 test 50 cod 3 SQL> select dept,avg(salary) from employee group by dept having avg(salary)>25; DEPT AVG(SALARY) ---------- ----------hr 28 test 50 SQL> select dept,avg(salary),count(*) from employee group by dept; DEPT AVG(SALARY) COUNT(*) ---------- ----------- ---------hr 28 2 test 50 1 cod 3 1