Oracle儲存過程2

2021-07-03 14:21:53 字數 3847 閱讀 5624

---檢視所有使用者

select * from all_users;

select * from user_users;

---檢視使用者系統許可權

select * from dba_sys_privs;

select * from user_sys_privs;

---檢視使用者物件許可權

select * from all_tab_privs;

select * from user_tab_privs;

---檢視使用者所擁有的角色

select * from user_role_privs;

--檢視當前使用者的預設表空間

select username,default_tablespace from user_users;

在dos命令視窗中  c:\>sqlplus '/ as sysdba'

在登入的命令視窗中  grant debug any procedure, debug connect session to scott更改許可權

create or replace procedure aa

iscursor aa_cursor is select salary from employees;

v_sum_sal number(10);

begin

v_sum_sal := 0;

for c in aa_cursor loop

v_sum_sal := v_sum_sal + c.salary;

end loop;       

dbms_output.put_line('sum salary: ' || v_sum_sal);

end;

create or replace procedure aa

is--cursor aa_cursor is select salary from employees;

type a is table of employees.salary%type index by binary_integer;

aa a;

v_sum_sal number(10);

begin

v_sum_sal := 0;

--for c in aa_cursor loop

for c in 1..aa.count loop

--v_sum_sal := v_sum_sal + c.salary;

v_sum_sal := v_sum_sal + c;

end loop;       

dbms_output.put_line('sum salary: ' || v_sum_sal);

end;

create or replace procedure aa

is--cursor aa_cursor is select salary from employees;

type a is table of employees.salary%type index by binary_integer;

ab a;

v_sum_sal number(10);

begin

v_sum_sal := 0;

dbms_output.put_line('count: ' || ab.count);

--for c in aa_cursor loop

for c in 1..ab.count loop

--v_sum_sal := v_sum_sal + c.salary;

dbms_output.put_line('salary: ' || c);

v_sum_sal := v_sum_sal + c;

end loop;       

dbms_output.put_line('sum salary: ' || v_sum_sal);

end;

儲存過程(mysql)

delimiter $$

create 

/*[definer = ]*/

procedure `clouddb01`.`test` () 

/*language sql

| [not] deterministic

| | sql security

| comment 'string'*/

begin

end $$

delimiter ;

create or replace procedure sum_sal_procedure(dept_id number, v_sum_sal out number)

iscursor sal_cursor is select salary from employees where department_id = dept_id;

begin

v_sum_sal := 0;

for c in sal_cursor loop

--dbms_output.put_line(c.salary);

v_sum_sal := v_sum_sal + c.salary;

end loop;       

dbms_output.put_line('sum salary: ' || v_sum_sal);

end;

declare 

v_sum_sal number(10) := 0;

begin

sum_sal_procedure(80,v_sum_sal);--第二個引數用於輸出

dbms_output.put_line(v_sum_sal);

end;

create or replace procedure testpro(v_name in varchar2,

v_out out varchar2

) is

type emp_ssn_array is table of number index by binary_integer;

type namearr is table of varchar2(100) index by pls_integer; 

best_employees emp_ssn_array;

worst_employees emp_ssn_array;

v_n namearr;

v_t varchar2(32);                               

begin

select e.ename into v_t from emp e where e.empno='7369';

for i in 1 .. 2 loop

v_n(i) := v_t;

end loop;

--v_n(1) := v_t;

dbms_output.put_line(v_t||',v_n(1)='||v_n(1));

best_employees(1) := '123456';

best_employees(2) := '888888';

worst_employees(1) := '222222';

worst_employees(2) := '666666';

for i in 1..best_employees.count loop

dbms_output.put_line('i=:'||i||', best_employees='

||best_employees(i)|| ', worst_employees= ' ||worst_employees(i));

end loop;

dbms_output.put_line('v_name:'||v_name);

v_out := v_name;

end testpro;

oracle儲存過程 2

color red 1.判斷語句 color color blue create or replace procedure color test x in number is begin if x 0 then begin x 0 x end end if if x 0 then begin x 1...

學習Oracle 的儲存過程2

呵呵,繼續學習吧,好記性不如懶筆頭 是這麼說的不?現在用oracle資料庫的挺多的,但要想學好oracle資料庫也並不是一件太容易的事情呀,那就不斷學習,不斷總結吧,遇到什麼問題,記下來再想辦法解決它,那不就積少成多啦!先說一下儲存過程裡的引數吧,in 引數是常量,不能改值,不寫預設為in out引...

Oracle儲存過程呼叫儲存過程

oracle儲存過程呼叫有返回結果集的儲存過程一般用光標的方式,宣告乙個游標,把結果集放到游標裡面,然後迴圈游標 declare newcs sys refcursor cs1 number cs2 number cstype table rowtype table列的個數和newcs返回的個數一樣...