Oracle-ing Myself – Lesson 7 Özeti

DROP TABLE emp2;
 
SELECT original_name,
     operation,
     droptime
FROM recyclebin;
 
flashback TABLE emp2 TO BEFORE DROP;
 
--external tables
--c:\deneme diye bir klasör olustur içine
--emp.dat diye dosya olustur virgülle ayrilmis
CREATE directory deneme AS 'C:\deneme';
 
GRANT READ WRITE ON directory deneme TO hr;
 
CREATE TABLE oldemp (fname CHAR(25), lname CHAR(25))
organization external (TYPE oracle_loader DEFAULT directory deneme 
access parameters (
records delimited BY newline 
nobadfile 
nologfile 
FIELDS TERMINATED BY ','
fname POSITION (1:20) CHAR,
lname POSITION (22:41) CHAR))
location ('emp.dat'))
parallel 5
reject LIMIT 200;
 
--type oracle_loader > sadece okuma islerinde kullaniyoruz
--type oracle_datapump > import export islerinde datapump kullancagiz
 
--meta data sorgulari
SELECT * FROM dictionary WHERE TABLE_NAME LIKE '%TABLE%';
SELECT * FROM dict;
 
SELECT * FROM user_tables;
SELECT * FROM user_objects;
SELECT * FROM user_views;
SELECT * FROM user_tab_columns;
 
SELECT * FROM all_tables;
 
SELECT * FROM dba_tables;
 
--performansla ilgili meta data gelir
SELECT * FROM v$database;
SELECT * FROM v$instance;
 
SELECT * FROM user_tab_comments;
 
comment ON TABLE employees IS 'Employee information';
 
UPDATE dept
SET manager_id = DEFAULT
WHERE departmen_id=10;
 
INSERT ALL 
  INTO sal_history VALUES(empid,hiredate,sal)
  INTO mgr_history VALUES(empid,mgr,sal)
  SELECT employee_id empid, hire_date hiredatei salary sal, manager_id mgr
  FROM employees
  WHERE employee_id > 200;  
 
INSERT ALL 
  WHEN hiredate < '01-JAN-95' THEN
    INTO emp_history VALUES(empid,hiredate,sal)      
  WHEN comm IS NOT NULL THEN
    INTO emp_sales VALUES(empid,comm,sal) 
SELECT employee_id empid, hire_date hiredatei salary sal, commission_pct comm
FROM employees;  
 
INSERT FIRST 
  WHEN hiredate < '01-JAN-95' THEN
    INTO emp_history VALUES(empid,hiredate,sal)      
  ELSE
    INTO emp_sales VALUES(empid,comm,sal) 
SELECT employee_id empid, hire_date hiredatei salary sal, commission_pct comm
FROM employees;
 
MERGE INTO emp a USING (employees) b
ON (a.employee_id == b.employee_id)
WHEN matched THEN UPDATE SET
a.first_name = b.first_name,
a.last_name = b.last_name,
......
DELETE WHERE (b.commission_pct IS NOT NULL)
WHEN NOT matched THEN
INSERT VALUES (b.employee_id,b.first_name,b.last_name....);
 
UPDATE emp3 SET salary = salary * 1.30
WHERE employee_id =107;
 
commit;
 
--salary alaninda yapilan degisiklikleri görebiliriz
SELECT salary FROM emp3
  version BETWEEN scn minvalue AND maxvalue
WHERE employee_id = 107;
 
--5 dakika öncesini göster
SELECT salary FROM emp3 AS OF TIMESTAMP sysdate-5/1440
WHERE employee_id =100;
 
ALTER SESSION SET time_zone = '-2:00';
 
ALTER system SET nls_date_format = 'DD-MON-YYYY HH24:MI:SS';
 
SELECT dbtimezone, sessiontimezone, CURRENT_DATE, 
          CURRENT_TIMESTAMP, localtimestamp 
FROM dual;
 
SELECT EXTRACT(YEAR FROM sysdate) FROM dual;
 
SELECT tz_offset('US/Eastern') FROM dual;
 
SELECT from_tz(TIMESTAMP '2000-07-12 08:00:00','Australia/North') FROM dual;
 
SELECT to_timestamp('2000-07-12 08:00:00','YYYY-MM-DD HH:MI:SS') FROM dual;
 
SELECT hire_date, to_yminterval('01-02'), to_dsinterval('100 10:00:00')
FROM employees;
 
UPDATE employees e
SET department_name = (SELECT department_name 
  FROM departments d
  WHERE d.department_id == e.department_id);
 
SELECT employee_id, last_name
FROM employees e
ORDER BY (SELECT department_name 
          FROM departments d
          WHERE e.department_id = d.department_id);
 
SELECT employee_id, last_name
FROM employees OUTER
WHERE EXISTS (SELECT 'X'
              FROM employees
              WHERE manager_id = OUTER.employee_id);
 
SELECT employee_id, last_name
FROM employees OUTER
WHERE NOT EXISTS (SELECT 'X'
              FROM employees
              WHERE manager_id = OUTER.employee_id);
 
UPDATE emp3 e
SET department_name = (SELECT department_name
                        FROM departments d
                        WHERE e.department_id = d.department_id);
 
DELETE FROM emp3 e
WHERE employee_id = (SELECT employee_id
                      FROM emp_history
                      WHERE employee_id = e.employee_id);
 
 
WITH summary AS
  (SELECT d.department_name dname,
     SUM(e.salary) total_dep
   FROM departments d,
     employees e
   WHERE e.department_id = d.department_id GROUP BY d.department_name)
  SELECT dname,
  total_dep
FROM summary
WHERE total_dep >
  (SELECT SUM(total_dep) *1 / 8
   FROM summary)
ORDER BY total_dep DESC
Be Sociable, Share!

    Category: Sql - Comments Off on Oracle-ing Myself – Lesson 7 Özeti

    Comments are closed.

    Back to top