0% found this document useful (0 votes)
19 views5 pages

Sep 4

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views5 pages

Sep 4

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 5

drop table test;

create table test as select * from employees;

create view v1 as select * from test;


select count(*) from test;
select count(*) from v1;
desc test
desc v1
insert into v1 select* from v1;
select count(*) from test;
select count(*) from v1;
delete from test;
select count(*) from test;
select count(*) from v1;
drop table test;
desc v1
SQL> select object_name , status from user_objects where object_type='VIEW' and
object_name like '%V1%';
==================================================================
insert into v1 select * from test
Q: how to see view definition?
desc user_views
==================================================================
[12:02] Sumedha saran (Guest)
drop table test; 

create table test as select * from departments;

desc v1;

select count (*) from test;   create or replace view v1 as select * from test;

desc v1;

select count (*) from v1;   drop table test; 

create table test as select * from employees;

desc v1;   create or replace view v1 as select * from test;

desc v1;

select count (*) from v1;

-----------------------

drop table test1; create table test1 as select


employee_id,last_name,salary,department_id from employees; desc test1

select count(*) from test1--- 107 rows create or replace view v1 as select


employee_id,last_name,salary from test1 with read only ; update v1 set salary=999;
--error

=============================================================================
drop table test;
create table test as select * from employees;

create view v1 as select * from test;


select count(*) from test;
select count(*) from v1;
desc test
desc v1
insert into v1 select* from v1;
select count(*) from test;
select count(*) from v1;
delete from test;
select count(*) from test;
select count(*) from v1;
drop table test;
desc v1
SQL> select object_name , status from user_objects where object_type='VIEW' and
object_name like '%V1%';

OBJECT_NAME
--------------------------------------------------------------------------------
STATUS
-------
V1
INVALID

select object_name,object_type from user_objects where object_type


in('TABLE','VIEW');
select view_name from user_views;

Q: how to see view definition?


desc user_views
select text from user_views where view_name='V1';

drop table test;


create table test as select * from departments;
desc v1;
select count (*) from test;

create or replace view v1 as select * from test;


desc v1;
select count (*) from v1;

drop table test;


create table test as select * from employees;
desc v1;

create or replace view v1 as select * from test;


desc v1;
select count (*) from v1;
===============================================================================
drop table test;
drop view v1;
create table test(id number, dept number );
insert into test values(101,10);
insert into test values(101,90);
insert into test values(101,70);
create view v1 as select * from test where dept in(10,90) with check option;
select * from test;
select * from v1;
insert into v1 values(103,90);
insert into v1 values(103,20);

drop table test ;


drop view v1;
create table test(id number, did number not null,sal number(10));
insert insert test values(101,10,20000);
select * from test;
create view v1 as selecy id,sal form test;
desc v1
select * from v1;
insert into v1 values(102,9000);---error
=======================================================================
Q: types of view:

--simple

--complex

simple view is made from a single table and dml operations can be performed through
view.

complex view is made from single or multiple table and dml operations cant be
performed through view directly

example:

given

after this you can follow that example 

this view is made from single table 

but cant perform insert operation thorugh view ...why?


========================================================================
---complex view from multiple table
create or replace view v1 as select id,name,dname
from base natural join child;---complex view (cannot perform dml operations
directly)
sol: instead of trigger

---more example complex view from single table

create view v1 as select employee_id,salary+100 sal from employees;--complex view

create view v1 as select distinct department_id from employees;--complex view

create view v1 as
select * from employees where salary> (select salary from employees where
last_name='x');--complex view
====================================================================
Q: what is force view?
you want to create a view before your table
drop view v1;
drop table test;
desc test
create view v1 as select * from test;--error
create force view v1 as select * from test;--should create with compilation error
desc v1 --invalid
select obejct_name,status from user_objects
where object_type='VIEW' and object_name like '%V1%';
create table test as select * from employees;
desc v1 --valid
=========================================================================
if we use force keyword we can also create empty view. and then we can update the
views with data. Without force we cannot create empty view. Is it correct mam?

this is step by step�

we can create empty view but it cant be used until you create the related table

in case its your project requirement so being a programmer u have option to create
a force view later when table will be created , it would automatically associate
with it�

single row function :

charcater, number , date,general , conversion

Q: database inbuilt functions

Q: single row vs group functions


=======================================================================
1. Character function:
case manipulation : upper, lower,initcap
character manipulation:concat,length,lpad,rpad,substr,instr,trim,replace

select last_name,salary from employees where last_name='smith';--no result bcos of


case unmatched
select last_name,salary from employees where lower(last_name)='smith';--valid
select last_name,salary from employees where lower(last_name)='SMITH';--invalid
select last_name,salary from employees where upper(last_name)='SMITH';--valid
select last_name,salary from employees where initcap(last_name)='Smith';--valid

select lower(last_name),upper(last_name),initcap(last_name) from employees;

substr: extract the string with the given range:


select substr('hello everyone',1,5) from dual;--hello
select substr('hello everyone',2,8) from dual;--ello eve
select substr('hello everyone',8) from employees;--veryone
===================================================================
instr--- tell the position of character�

select instr('helloclass','e') from dual; --2

select instr('helloclass','s') from dual; --9�select concat('hi', last_name) from


employees;

select concat('hi', last_name,first_name) from employees;--invalid�

select length(first_name) from employees;

select length('hello this is demo') from dual;


Q: lpad/rpad--- used for alignment (right or left side)

select 'The salary of '||last_name||'is ' ||salary from employees;

select 'The salary of '||lpad(last_name,10,' ')||'is ' ||salary from employees;

select 'The salary of '||lpad(last_name,10,'*')||'is ' ||salary from employees;

select 'The salary of '||rpad(last_name,10,' ')||'is ' ||salary from employees;�

Trim function eliminates beginning and ending matched charcaters from the given
string.�select 'Hi'||' � This is demo class � '||'Goodday'from dual;�

result: Hi � This is demo class Goodday�select 'Hi'||trim(' ' from ' � This is demo
class � ')||'Goodday'from dual��result: HiThis is demo classGoodday�note:�

trim is used to eliminate the given character from begin and end of the
string��select 'Hi'||trim('s' from 'ss � ss � This is demo class � sssss
s')||'Goodday'from dual�

select 'Hi'||trim('s' from 'ss ��ss ��This is demo class ��sssss s')||'Goodday'
from dual

select 'Hi'||trim('s' from 'ssss s �This is demo classssssss')||'Goodday' from dual

You might also like