oracle developer les03 arabic

Upload: abu-faris-mostafa

Post on 14-Apr-2018

231 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/27/2019 ORACLE DEVELOPER les03 arabic

    1/14

    Mohamed_Suez ABU FARIS

    10G2011

    admin

    HIO SUEZ

    6/7/2011

  • 7/27/2019 ORACLE DEVELOPER les03 arabic

    2/14

    2

    -: I) (

    Practice 2

    1-The HR department wants a query

    1: ;DESC EMPLOYEES: HR )

    HR : 7.sqllab_01_0\save c: sIsqlpluscriptSAVE

    2- The HR department...

    2: DISTINCT

    3- The HR department has

    3: ),( .

    4-If you want an extra

    4: ),(

    5-The HR department needs your assistance

    :5

    12000.

    select Employee_id,last_name,job_id,hire_date asSTARTDATE

    from Employees;

    Select Distinct ob_idFrom employees;

    Select last_name||, ||job_id as EMPLOYEE AND TITLEFrom employees;

    Select employee_id||,||last_name||,||first_name||,||>>>>ETC

    select last_name,employee_idfrom employees

    wheresalary > 12000;

  • 7/27/2019 ORACLE DEVELOPER les03 arabic

    3/14

    3

    6-Create a report...

    6: ...

    7-The HR departments needs to find high-salary

    :7

    8-Create a report to display the last

    ... :8

    9-Display the last name and department number...

    50 20 : 9 .

    10-Modify lab_02_03.sql to display the last name and salary

    6: 3 .5 35020

    11-The HR department needs a report ...

    11: 1994 .

    select last_name,department_idfrom employees

    where employee_id =176;

    select last_name,salaryfrom employeeswhere salary not between 5000 and 12000;

    select last_name,job_id,hire_date

    from employees

    where last_name in( 'Matos' , 'Taylor');

    select last_name,department_id

    from employees

    where department_id in( 20,50)

    /where department_id =20 ordepartment_id=50

    order by last_name;

    select last_name,salary "Monthly Salary"

    from employeeswhere salary between 5000 and 12000

    and department_id in( 20,50) ;___

    Select last_name,hire_date

    From employees

    Where hire_date like'%94';

  • 7/27/2019 ORACLE DEVELOPER les03 arabic

    4/14

    4

    12- Create a report to display the last name and job title ...

    12: .

    )( :-13-Create a report to display the last name, salary

    :13 .

    14-Display all employee last names in which the third

    14: Where

    ._

    select last_name,job_id

    from employees

    where manager_id is null;

    Select last_name,salary,commission_pct

    From employees

    Where commission_pct is not null

    Order by salary desc,commission_pct desc

    select last_name

    from employees

    where last_name like '__a%'

  • 7/27/2019 ORACLE DEVELOPER les03 arabic

    5/14

    5

    Case-M

    Function

    LOWER('SQL CoLOWER: Converts mixed

    UPPER('SQL CoUPPER: Converts mixed

    INITCAP('SQLINITCAP: Converts t

    re

    .

    .

    SELECT'The job id for '||UP

    FROM employees;

    __anipulation FunctionsRes

    sql curse')case or uppercase character stri

    SQL Curse')case or lowercase character stri

    Sql Course')e first letter of each word to u

    aining letters to lowercase

    ER(last_name)||' is '||LOWER(job_id) A

    ult

    ursengs to lowercase

    URSEngs to uppercase

    urse

    percase and

    -

    -

    "EMPLOYEE DETAILS"

  • 7/27/2019 ORACLE DEVELOPER les03 arabic

    6/14

    6

    .

    ..INSTR

    Charact FunctionCONCAT('Hello', 'World')

    CONCAT: Joins values togeth

    SUBSTR('HelloWorld',1,5)SUBSTR: Extracts a string of

    LENGTH('HelloWorld')

    LENGTH: Shows the length o

    INSTR('HelloWorld', 'W')

    INSTR: Finds the numeric posLPAD(salary,10,'*')

    LPAD: Pads the character val

    RPAD(salary, 10, '*')

    RPAD: Pads the character val

    REPLACE('JACK and JUE','

    REPLACE : Replace string wi

    TRIM('H' FROM 'HelloWorl

    TRIM: Trims any character fr

    ,CONCAT , a

    ...

    r-Manipulation Functio ResultHelloWorld

    r (You are limited to sing two parameters wit

    Hellodetermined length

    10

    a string as a numeric value.

    6

    ition of a named character.*****24000

    e right- ustified.

    24000*****

    e left-justified.

    ','BL') BLACK and BL

    h another one

    ') elloWorld

    om the string.

    -

    -: ENGTH

    s

    h CONCAT)

    E

  • 7/27/2019 ORACLE DEVELOPER les03 arabic

    7/14

    7

    Number

    Function

    ROUND(45.926, 2)

    ROUND: Rounds value t

    TRUNC(45.926, 2)

    TRUNC: Truncates va

    MOD(1600, 300)

    MOD: Returns remai

    .

    .

    16003/=500

    SELECT ROUND(4

    FROM DUAL;

    SELECT TRUNC(45

    FROM DUAL

    unctionsResul

    45.93

    o specified decimal 45.92

    ue to specified decimal 100

    der of division

    ROUND

    TRUNC

    MOD .100

    .923,2), ROUND(45.923,0),ROUND(45

    .923,2),TRUNC (45.923),TRUNC (45.9

    -

    .923,-1)

    3,-1)

  • 7/27/2019 ORACLE DEVELOPER les03 arabic

    8/14

    8

    Wor

    -:DD-MON-RR HH:MM:

    Element Result

    YYYY Full year in numbersYEAR Year spelled out (in

    MM Two-digit value forMONTH Full name of the monMON Three-letter abbreviDY Three-letter abbreviDAY Full name of the dayDD Numeric day of the

    DUAL

    Arithmetic

    ) ...)

    SELECT last_name, hire_datFROM employees

    WHERE hire_date < '01-F

    SELECT SYSDATEFROM DUAL;

    Operation

    date + number

    date number

    date date

    date + number/24

    king with Dates ___

    SS

    (nglishonththtion of the monthtion of the day of the weekof the weekonth

    )(

    ith Dates __

    e

    B-88';

    esult Description

    ate Adds a number of days t

    ate Subtracts a number of d

    umber of days Subtracts one date from

    ate Adds a number of hours

    3 3

    SYSDATE

    o a date

    ays from a date

    another

    to a date

  • 7/27/2019 ORACLE DEVELOPER les03 arabic

    9/14

    9

    Date Functions ___

    .

    \

    Function Result MONTHS_BETWEEN Number of months between two

    dates

    MONTHS_BETWEEN ('01-SEP-95','11-JAN-94') 19.6774194

    ADD_MONTHS Add calendar months to date ADD_MONTHS('11-JAN-94',6) '11-JUL-94'

    NEXT_DAY Next day of the date specified NEXT_DAY ('01-SEP-95','FRIDAY') '08-SEP-95'

    LAST_DAY Last day of the month LAST_DAY ('01-FEB-95') '28-FEB-95'

    ROUND Round date ROUND(SYSDATE,'MONTH')

    ROUND(SYSDATE ,'YEAR')

    01-AUG-03

    01-JAN-04

    TRUNC Truncate date TRUNC(SYSDATE ,'MONTH')

    TRUNC(SYSDATE ,'YEAR')

    01-JUL-03

    01-JAN-03

    SELECTemployee_id, hire_date,MONTHS_BETWEEN (SYSDATE, hire_date) TENURE,

    ADD_MONTHS (hire_date, 6) REVIEW,NEXT_DAY (hire_date, 'FRIDAY'),

    LAST_DAY(hire_date)

    FROM employees

    HERE MONTHS_BETWEEN (SYSDATE, hire_date) < 36;

  • 7/27/2019 ORACLE DEVELOPER les03 arabic

    10/14

    10

    MAN

    Operator Meaning

    AND Returns TRUE ifconditions are tru

    OR Returns TRUE ifcondition is true

    NOT Returns TRUE ifis false

    SELECT employee_id, hiTRUNC(hire_date, 'MOFROM employees

    HERE hire_date LIK

    ...

    -:

    10000 .

    oth component

    ithercomponent .

    he following condition .

    re_date, ROUND(hire_date, 'MONTH')TH')

    '%97';

    -:

    .

    ,

  • 7/27/2019 ORACLE DEVELOPER les03 arabic

    11/14

    11

    .

    .

    Rules of

    MeaningOperatorArithmetic o1

    Concatenatio2Comparison3

    IS [NOT] N4

    [NOT] BET5Not equal to6

    NOT logical7AND logical8OR logical c9

    . 3

    ...recedence

    eratorsn operatoronditions

    LL, LIKE, [NOT] INEEN

    onditionondition

    ndition

    -:

    -:

    10000

  • 7/27/2019 ORACLE DEVELOPER les03 arabic

    12/14

    12

    -

    AD_( ))SA_REP ))AD_REPS

    ...

    ...

    : )EPS))SA_REP

    15 3

    :

    15000

    000

  • 7/27/2019 ORACLE DEVELOPER les03 arabic

    13/14

    13

    :-The HR department needs your assistance with creating some queries.

    1. Display the last name of all employees who have both an a and an e intheir last name.

    2. Display the last name, job, and salary for all employees whose job is salesrepresentative or stock clerk and whose salary is not equal to $2,500,$3,500, or $7,000.

    3. Modify lab_02_06.sql to display the last name, salary, and commission forall employees whose commission amount is 20%.

    4. Write a query to display the current date. Label the column Date .

    5. The HR department needs a report to display the employee number, last

    name, salary, and salary increased by 15.5% (expressed as a wholenumber) for each employee. Label the column New Salary.

    6. Modify your query lab_03_02.sql to add a column that subtracts the oldsalary from the new salary. Label the column Increase.

    7. Write a query that displays the last name (with the first letter uppercaseand all other letters lowercase) and the length of the last name for allemployees whose name starts with the letters J, A, or M. Give eachcolumn an appropriate label. Sort the results by the employees last

    names.8. The HR department wants to find the length of employment for each employee. Foreach employee, display the last name and calculate the number of months betweentoday and the date on which the employee was hired. Label the columnMONTHS_WORKED. Order your results by the number of months employed. Round

    the number of months up to the closest whole number.

  • 7/27/2019 ORACLE DEVELOPER les03 arabic

    14/14

    14

    9. Create a report that produces the following for each employee: earns monthly but wants . Label the column Dream Salaries.

    10. Create a query to display the last name and salary for all employees.Format the salary to be 15 characters long, left-padded with the $ symbol.Label the column SALARY.

    11. Create a query that displays the first eight characters of the employeeslast names and indicates the amounts of their salaries with asterisks. Eachasterisk signifies a thousand dollars. Sort the data in descending order of

    salary. Label the column EMPLOYEES_AND_THEIR_SALARIES.