лабораторная работа 8

Download лабораторная работа 8

Post on 06-Aug-2015

232 views

Category:

Education

0 download

Embed Size (px)

TRANSCRIPT

  1. 1. 8 SQL: Copyright Avdeyev V.A. 2008
  2. 2. 8 : SQL SQL ORACLE : 8Copyright Avdeyev V.A. 2008
  3. 3. ? , , . , . . , . DML , , , . 8Copyright Avdeyev V.A. 2008
  4. 4. CREATE VIEW CREATE VIEW Kazan AS SELECT * FROM Salespeople WHERE city = , . , , , , , . Select * FROM Kazan CREATE VIEW Salesp AS SELECT snum, sname, city FROM Salespeople 8Copyright Avdeyev V.A. 2008
  5. 5. DML, . UPDATE Salesown SET city = ' WHERE snum = 1004; 8Copyright Avdeyev V.A. 2008
  6. 6. : ; , . CREATE VIEW Salesp (N,Name,City) AS SELECT snum, sname, city FROM Salespeople , . 8Copyright Avdeyev V.A. 2008
  7. 7. , GROUP BY, CREATE VIEW Totalforday AS SELECT odate, COUNT(DISTINCT cnum), COUNT(DISTINCT snum), COUNT(onum), AVG(amt), SUM(amt) FROM Orders GROUP BY odate; SELECT * FROM Totalforday; 8Copyright Avdeyev V.A. 2008
  8. 8. , . SQL , , . CREATE VIEW Nameorders AS SELECT onum, amt, a.snum, sname, cname FROM Orders a, Customers b, Salespeople c WHERE a.cnum = b.cnum AND a.snum = c.snum; SELECT * FROM Nameorders WHERE sname = ..'; 8Copyright Avdeyev V.A. 2008
  9. 9. , . CREATE VIEW Elitesalesforce AS SELECT b.odate, a.snum, a.sname, FROM Salespeople a, Orders b WHERE a.snum = b.snum AND b.amt = (SELECT MAX (amt) FROM Orders c WHERE c.odate = b.odate); , , . CREATE VIEW Bonus AS SELECT DISTINCT snum, sname FROM Elitesalesforce a WHERE 10 5 ORDER BY nameSUBSTR . , , SUBSTR (_, __, _)SELECT SUBSTR(Project, 1, 2) n, SUBSTR(Project, 4, 3) dep FROM test_3 8Copyright Avdeyev V.A. 2008
  10. 17. (3/3) INSTR , INSTR(_, __, __) SELECT INSTR(Project,-,1) FROM test_3 SELECT SUBSTR(Project,1,INSTR(Project,-,1)) FROM test_3LTRIM RTRIM LTRIM , RTRIM . LTRIM(_), RTRIM(_) SELECT LTRIM(Project) FROM test_3 8Copyright Avdeyev V.A. 2008
  11. 18. (1/2) INSERT INTO test_2 VALUES ('Tanya Ivanova',11.55, SYSDATE);SYSDATE TRUNC TRUNC ? . 8Copyright Avdeyev V.A. 2008
  12. 19. (2/2) ADD_MONTHS , , ( ). ADD_MONTHS(_', _)LAST_DAY , LAST_DAY()MONTH_BETWEEN , MONTHS_BETWEEN(_, _) 8Copyright Avdeyev V.A. 2008
  13. 20. (1/4) (data conversion) , , .: , . . 8Copyright Avdeyev V.A. 2008
  14. 21. (2/4) TO_CHAR , _R(_, _)SELECT SELECT SELECT SELECTTO_CHAR(SYSDATE,'MM-DD-YYYY HH24:MI:SS') NOW FROM test_2; TO_CHAR(SYSDATE, 'MONTH DDTH') FROM test_2; TO_CHAR(SYSDATE, 'MONTH DDSP') FROM test_2; TO_CHAR(SYSDATE, 'MONTH DDSPTH') FROM test_2; 8Copyright Avdeyev V.A. 2008
  15. 22. (3/4) TO_CHAR , _R(_, _) 8Copyright Avdeyev V.A. 2008
  16. 23. (4/4) _D (/ ) /. , , . _D(_, _) 8Copyright Avdeyev V.A. 2008
  17. 24. (1/2) DECODE , "" "". : "", "", "", "D". "", "", "" "D" DECODE(__, __1, __ 1, __2, __2, __, __, [___ __]) 8Copyright Avdeyev V.A. 2008
  18. 25. (2/2) NVL null-, NVL(_, __ll) __ll - , : (.. ), . NVL . . 8Copyright Avdeyev V.A. 2008
  19. 26. SQL- . , , . , , . SELECT * FROM test_2; -- . , , "/*", "*/". . 8Copyright Avdeyev V.A. 2008
  20. 27. , . : , , . , . , 8Copyright Avdeyev V.A. 2008