Presentation is loading. Please wait.

Presentation is loading. Please wait.

SQLPLUS: Oracle SQL Interface

Similar presentations


Presentation on theme: "SQLPLUS: Oracle SQL Interface"— Presentation transcript:

1 SQLPLUS: Oracle SQL Interface

2 Oracle SQL*Plus Interactive user environment Documentation
Can run SQL statements PL/SQL statements Other SQL*plus commands Allows simple command editing Documentation Help command in sqlplus

3 Change Password SQL> alter user username identified by newpassword;
Username is oracle username Newpassword is the password you want ; is necessary to terminate SQL statement

4 SQL*Plus SQL*plus understands only Oracle SQL
An SQL statement must end a semicolon ; a / on a line by itself blank line SQL statement can be typed in or loaded from a file get filename An SQL statement can be executed from the command buffer (run) or from an sql file SQL statement in buffer can be written to a file save filename

5 Common SQL*Plus Commands
Display schema describe table_name Run Unix commands !command Run editor on .sql file edit filename Customize environment echo on pause on pagesize 30 Show command in buffer list

6 Company Database Employee, department, dept_locations, dependent, works_on and project tables User sys.tablename to refer to tables Example: retrieve all employee information Select * from sys.employee Use the following to find details of tables SQL> describe sys.employee;

7 Company Queries Q1: Find the number of employees
SQL> select count(*) 2 from sys.employee; COUNT(*) 40

8 Company Queries Q2: Find the highest salary SQL> select max(salary)
2 from sys.employee; MAX(SALARY) 96000

9 Company Queries Q3: Find the number of departments
SQL> select distinct dno 2 from sys.employee; DNO 1 6 5 4 8 7 6 rows selected.

10 Company Queries Q4: Find the name of employee with the highest salary
SQL> select fname, minit, lname 2 from sys.employee 3 where salary = (select max(salary) from sys.employee); FNAME M LNAME Bob B Bender

11 Company Queries Q5: Find the number of employees working in each department. SQL> select dno, count(*) 2 from sys.employee 3 group by dno; DNO COUNT(*) 6 rows selected.

12 Company Queries Q6: Find the number of female employees
select count(*) from sys.employee where sex = ‘F';

13 Company Queries Q7: Find the maximum salary of female employees
select max(salary) from sys.employee where sex = ‘F’;

14 Company Queries Q8: Find the maximum salary of male and female employees select sex, max(salary) from sys.employee group by sex;

15 Company Queries Q9: Find the first name, last name of employees who work for department 5 select fname,lname from sys.employee where dno=5;

16 Company Queries Q10: Find the first name, last name of employees who work for research department select fname,lname from sys.employee, sys.department where dno = dnumber and dname = 'Research';

17 Company Queries Q11: Find the number of employees who work for research department select count(*) from sys.employee, sys.department where dno = dnumber and dname = 'Research';

18 Company Queries Q12: Find the number of employees who do not work for research department select count(*) from sys.employee, sys.department where dno = dnumber and dname != 'Research';

19 Company Queries Q13: Find the total salary of employees who work for research department select sum(salary) from sys.employee, sys.department where dno = dnumber and dname = 'Research';

20 Company Queries Q14: Find the department name and total salary of employees for each department select dname, sum(salary) from sys.employee, sys.department where dno = dnumber group by dname;

21 Company Queries Q15: Find the names of departments that have more than 3 employees select dname from sys.employee, sys.department where dno = dnumber group by dname having count(*) >3;

22 Company Queries Q16: Find the names of employees who do not have supervisors select fname, lname from sys.employee where superssn IS NULL;

23 Company Queries Q17: Find the names of employees who have no dependents select fname, lname from sys.employee where not exists (select * from sys.dependent where ssn=essn);

24 Company Queries Q18: Count the number of distinct salary values in the database select count (distinct salary) from sys.employee;


Download ppt "SQLPLUS: Oracle SQL Interface"

Similar presentations


Ads by Google