0% found this document useful (0 votes)
16 views

Constraints Queries

no

Uploaded by

shekhar.dev1998
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)
16 views

Constraints Queries

no

Uploaded by

shekhar.dev1998
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/ 3

constraints queries:-------------------------

_____________________________________________
ccreate table customer(cust_id number(10)primary key,
cust_name varchar2(10) not null,
mobile_no number(10)unique check (length(mobile_no)=10),
age number(4)check(age>18),
city_id number(4)REFERENCES city(city_id));
create table city(city_id number(4)primary key,city_name varchar2(10));
insert into city values(10,'HYDERABAD');
insert into customer values(123,'Shekhar',9603632051,20,10);
desc customer;
desc city;
select * from all_constraints where owner='SYSTEM' and table_name = 'customer';
select a.owner,a.constraint_name,a.constraint_type,b.table_name,b.column_name
from all_constraints a,all_cons_columns b where a.constraint_name=b.constraint_name
and a.owner='SYSTEM', and a.table_name='customer';
delete from customer where cust_id=123;
rollback;
select * from customer;
SELECT *
FROM all_constraints
WHERE owner = 'SYSTEM' AND table_name = 'customer';
select * from all_tables where owner='SYSTEM';
drop table city;
drop table customer;

select :-------
select* from HR.employees;
select employee_id,first_name,email,hire_date,salary,department_id from
HR.employees;
--common alias
select employee_id associate_id,first_name,email,hire_date,salary,department_id
from HR.employees;
select employee_id as associate_id,first_name,email,hire_date,salary,department_id
from HR.employees;
--concatinatio of column // nested - function
select employee_id
associate_id,first_name,last_name,concat(first_name,last_name)full_name,email,hire_
date,salary,department_id from HR.employees;
-- space betweeen two columns use below query
select employee_id associate_id,first_name,last_name,concat(concat(first_name,'
'),last_name)full_name,email,hire_date,salary,department_id from HR.employees;
--another way to concation without using concation key word use ||
select employee_id associate_id,first_name,last_name,first_name||' '||last_name
full_name,email,hire_date,salary,department_id from HR.employees;
--column calculation
select employee_id,first_name,email,hire_date,salary*12
annual_salary,department_id from HR.employees;
select employee_id,first_name,email,hire_date,salary+10000
new_salary,department_id from HR.employees;
-- to know departments
select* from HR.employees;
select distinct department_id from HR.employees;
select department_id from HR.employees;
select count(distinct department_id )from HR.employees;
--where clause
select * from HR.employees where salary>10000;
select * from HR.employees where salary<=20000 and salary>=10000;
select * from HR.employees where salary not between 10000 and 20000;
select * from HR.employees where salary between 20000 and 15000;
-- know numeric values column
select * from HR.employees where department_id = 60;
select * from HR.employees where department_id in (60,20);
select * from HR.employees where department_id not in (60,20);
--character column also
select * from HR.employees where job_id in ('it_prog','ad-vp');
-- nested condition
select * from HR.employees where department_id=60 and salary>1000;
select * from HR.employees where department_id=60 or salary<20000;
---nested function
select* from HR.employees where department_id =60 or (department_id=80 and
salary>10000);
-- where cluse in row
select * from HR.employees where rownum<=5;
select rownum,rowid from HR.employees;
select rownum,rowid,e.*from HR.employees e;
select * from HR.employees where commission_pct is null;
select * from HR.employees where commission_pct is not null;
select count (*) from HR.employees where commission_pct is null;
select count (*) from HR.employees where commission_pct is not null;
--date queries
--i want to separate year from hire_date below query did
select
employee_id,hire_date,to_char(hire_date,'yyyy'),to_char(hire_date,'mm'),to_char(hir
e_date,'month'),to_char(hire_date,'DD'),to_char(hire_date,'DAY')from HR.employees;

--- i want to know how many members join in year i have to use where clause
select * from hr.employees where to_char(hire_date,'yyyy')='2005';
-- dummy table
select * from dual;
select sysdate from dual;
select systimestamp from dual;

--pattern matching
-- i dont know exact value of column we can go for pattern matching
--use like key word Like(%%);
Like'%%';
select * from HR.Employees WHERE first_name like'A%';
select * from HR.Employees WHERE first_name like'%A';
select * from HR.Employees WHERE first_name like'%an';
select * from HR.Employees WHERE first_name like's%n';
select * from HR.Employees WHERE first_name like'----';
select * from HR.Employees WHERE first_name like'a----';
select * from HR.Employees WHERE salary like'--500';

---Order by
select * from HR.employees order by first_name;
select * from HR.employees order by first_name desc ;
select * from HR.employees order by salary desc ;
select * from HR.employees order by 8 desc,6;

--dual
select * from dual;
select current_date from dual;
select sysdate from dual;
select systimestamp from dual;
select sysdate from dual;
In oracle we hav three types of functions
1.Single Row Functions
2.Aggregent Functions
3.Analytical Functions

You might also like