ORACLE常用语法

--定义一个对象类型的变量
CREATE OR REPLACE PROCEDURE TEST_1 IS
  TYPE N_OBJECT IS RECORD(
    n_no    number,
    v_name  varchar2(20),
    v_phone varchar2(20));
  n_o N_OBJECT;
BEGIN
  n_o.n_no    := 10;
  n_o.v_name  := 'jack';
  n_o.v_phone := '15910906597';
  dbms_output.put_line(n_o.n_no || ',' || n_o.v_name || ',' || n_o.v_phone);
END;

--LOOP循环用法
CREATE OR REPLACE PROCEDURE TEST_2 IS
  n_number number:=1;
BEGIN
  LOOP
    dbms_output.put_line(n_number);
    n_number := n_number + 1;
    EXIT WHEN n_number = 10;
  END LOOP;
END;

--FOR循环用法
CREATE OR REPLACE PROCEDURE TEST_3 IS
BEGIN
  FOR n_f IN 1..10 LOOP
  DBMS_OUTPUT.put_line(n_f);
  END LOOP;
END;

--游标用法
CREATE OR REPLACE PROCEDURE TEST_4 IS
  CURSOR c_cur is
    SELECT DNAME FROM DEPT;
  v_dname varchar2(100);
BEGIN
  OPEN c_cur;
  LOOP
    FETCH c_cur
      into v_dname;
    DBMS_OUTPUT.put_line(v_dname);
    EXIT WHEN c_cur%NOTFOUND;
  END LOOP;
  CLOSE c_cur;
END;

你可能感兴趣的:(oracle,sql,C++,c,C#)