刘贤同学写的一个例子,很不错,所以就收藏一下:)
sql 代码- create or replace
- PROCEDURE p_insert_t
- (v_x in NUMBER)
- IS
- temp_id number;
- BEGIN
- FOR i IN 1..v_x LOOP
- select SEQ_B_USER_ID.nextval into temp_id from dual;
- insert into buser (id, username, nickname, status, createdtime) values(temp_id, to_char(temp_id), to_char(temp_id), 0, sysdate);
- END LOOP;
- END;
- --execute
创建sequence的方法(备忘):
sql 代码- CREATE SEQUENCE SEQ_B_USER_ID INCREMENT BY 1 START WITH 1;
复制一个表的结构:
sql 代码- create table test as select * from bookmarkcategory where 1=2;
随机数:
sql 代码- select dbms_random.value(1,20) from dual;
游标的使用例子:
sql 代码- SET SERVERIUTPUT ON
- DECLARE
- CURSOR c_emp IS select title from bookmarkcategory where username='130';
- r_emp c_emp%ROWTYPE;
- BEGIN
- OPEN c_emp;
- -- LOOP
- FETCH c_emp INTO r_emp;
- --EXIT WHEN c_emp%NOTFOUND;
- --DBMS_OUT.PUT.PUT_LINE('Salary of Employee is'|| r_emp.title);
- --END LOOP;
- update bookmarkcategory set title = r_emp.title where id=121;
- CLOSE c_emp;
- END;