数据库学习14-回顾

数据字典
information_schema(mysql)
--oracle
SELECT * FROM tab$;
SELECT * FROM user_objects;
SELECT * FROM dba_roles;
SELECT * FROM all_tab_cols;

连接查询
联表查询
SELECT ... FROM tab1,tab2,tab3 ...
  WHERE tab1.con = tab2.conn
     AND-- tab1.com = tab3.cnn 
        tab2.ccn = tab3.conn...;
        
SELECT ... FROM tab3 JOIN         
 (SELECT ... FROM tab1 [INNER] JOIN tab2 
   ON tab1.con = tab2.conn) aa
   ON tab3.conn = aa.con;
   
SELECT ... FROM tab1,tab2 
  WHERE tab1.conn(+) = tab2.con;   
  
SELECT ... FROM tab1 LEFT [OUTER] JOIN tab2 
  ON tab1.con = tab2.conn;    
SELECT ... FROM tab1 RIGHT [OUTER] JOIN tab2 
  ON tab1.con = tab2.conn; 
  
SELECT * FROM emp x,emp y
  WHERE x.mgr = y.empno;
  
--递归查询  
SELECT LEVEL,t.* FROM emp t 
  START WITH empno=7839
  CONNECT BY PRIOR empno=mgr
   ORDER BY LEVEL;

表空间


触发器,函数和过程,游标 视图,索引,导入导出
create index 索引名 on emp(empno) reverse;
create bitmap index 索引名 on emp(job);
--游标
DECLARE
  CURSOR cur IS
   SELECT * FROM emp;
   
  e emp%ROWTYPE; 
BEGIN
  OPEN cur;
  FETCH cur INTO e; --iterator.next();
  dbms_output.put_line(e.ename);
  FETCH cur INTO e; 
  dbms_output.put_line(e.ename);
  FETCH cur INTO e; 
  dbms_output.put_line(e.ename);
  FETCH cur INTO e; 
  dbms_output.put_line(e.ename);
  FETCH cur INTO e; 
  dbms_output.put_line(e.ename);
  FETCH cur INTO e; 
  dbms_output.put_line(e.ename);
  FETCH cur INTO e; 
  dbms_output.put_line(e.ename);
  FETCH cur INTO e; 
  dbms_output.put_line(e.ename);
  FETCH cur INTO e; 
  dbms_output.put_line(e.ename);
  FETCH cur INTO e; 
  dbms_output.put_line(e.ename);
  FETCH cur INTO e; 
  dbms_output.put_line(e.ename);
  FETCH cur INTO e; 
  dbms_output.put_line(e.ename);
  FETCH cur INTO e; 
  dbms_output.put_line(e.ename);
  FETCH cur INTO e; 
  dbms_output.put_line(e.ename);
  FETCH cur INTO e; 
  dbms_output.put_line(e.ename);
  
  CLOSE cur;
END;   

DECLARE
  CURSOR cur IS
   SELECT * FROM emp;
   
  e emp%ROWTYPE; 
BEGIN
  OPEN cur;
  /*
  LOOP
    FETCH cur INTO e; 
    EXIT WHEN cur%NOTFOUND;
    dbms_output.put_line(e.ename);
  END LOOP;
  */
  FETCH cur INTO e;
  WHILE cur%FOUND LOOP
    dbms_output.put_line(e.ename);
    FETCH cur INTO e; 
  END LOOP;
  CLOSE cur;
END;

DECLARE
  CURSOR cur IS
   SELECT ename FROM emp;
BEGIN
  FOR ee IN cur LOOP
    dbms_output.put_line(ee.ename); 
  END LOOP;
END;

DECLARE
  CURSOR cur IS
   SELECT ename FROM emp;
  e VARCHAR2(10);
BEGIN   
  OPEN cur;

  LOOP
    FETCH cur INTO e; 
    EXIT WHEN cur%NOTFOUND;
    dbms_output.put_line(e);
  END LOOP; 
END;

--过程
CREATE OR REPLACE PROCEDURE pro_cur(n OUT NUMBER)
 IS
  CURSOR cur IS
   SELECT ename FROM emp;
  e VARCHAR2(10);
BEGIN   
  dbms_output.put_line('参数:'||n);
  OPEN cur;

  LOOP
    FETCH cur INTO e; 
    EXIT WHEN cur%NOTFOUND;
    dbms_output.put_line(e);
  END LOOP; 
END;

SELECT * FROM user_objects 
  WHERE object_type = 'PROCEDURE';

ORACLE中回滚和重做的细节。。。

java中使用存储过程和方法,批量删除

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值