存储过程(sp)的应用 博客分类: 数据库 Oracle
程序员文章站
2024-03-23 18:46:22
...
存储赋权
存储逻辑处理有返加值
存储有异常处理
create or replace procedure proc_grant(OWNER VARCHAR2,OWNERAPP VARCHAR2,OWNERREAD VARCHAR2)
AS
V_OBJECT VARCHAR(128);
CURSOR BRANCH01 IS SELECT OBJECT_NAME FROM USER_OBJECTS T WHERE OBJECT_TYPE IN('TABLE','VIEW');
CURSOR BRANCH02 IS SELECT OBJECT_NAME FROM USER_OBJECTS T WHERE OBJECT_TYPE IN('FUNCTION','FROCEDURE','PACKAGE');
CURSOR BRANCH03 IS SELECT OBJECT_NAME FROM USER_OBJECTS T WHERE OBJECT_TYPE IN('SEQUENCE');
BEGIN
V_OBJCET :='';
OPEN BRANCH01;
LOOP
FETCH CUR_BRANCH01
INTO V_OBJECT;
EXIT WHEN CUR_BRANCH01%NOTFOUND;
IF LENGTH(TRIM(OWNERAPP))>0
THEN
EXECUTE IMMEDIATE 'GRANT SELECT,INSERT,DELETE,UPDATE ON '||V_OBJECT||' TO '||OWNERAPP;
EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM '||OWNERAPP||'.'||V_OBJECT||' FOR '||OWNER||'.'||V_OBJECT;
END IF;
END LOOP;
CLOSE BRANCH01
EXCEPTION
WHEN NO_DATA_FOUND THEN
DBMS_OUTPUT.PUT_LINE(SQLCODE || SQLERRM);
WHEN OTHERS THEN
INSERT INTO LOG(ECODE,EMESSAGE,EINFO) VALUES(V_ERRCODE,V_ERRMSG,V_INFORMATION);
COMMIT;
RETURN
END proc_grant;
例2:
Connection conn=ConUtil.getConnectio n();
CallableStatement proc;
int res=0;
proc=conn.prepareCall("{call proc1(?)}");
proc.registerOutParameter(1,Types.NUMBERIC);
proc.execute();
res=proc.getInt(1);
con.close();
存储逻辑处理有返加值
存储有异常处理
create or replace procedure proc_grant(OWNER VARCHAR2,OWNERAPP VARCHAR2,OWNERREAD VARCHAR2)
AS
V_OBJECT VARCHAR(128);
CURSOR BRANCH01 IS SELECT OBJECT_NAME FROM USER_OBJECTS T WHERE OBJECT_TYPE IN('TABLE','VIEW');
CURSOR BRANCH02 IS SELECT OBJECT_NAME FROM USER_OBJECTS T WHERE OBJECT_TYPE IN('FUNCTION','FROCEDURE','PACKAGE');
CURSOR BRANCH03 IS SELECT OBJECT_NAME FROM USER_OBJECTS T WHERE OBJECT_TYPE IN('SEQUENCE');
BEGIN
V_OBJCET :='';
OPEN BRANCH01;
LOOP
FETCH CUR_BRANCH01
INTO V_OBJECT;
EXIT WHEN CUR_BRANCH01%NOTFOUND;
IF LENGTH(TRIM(OWNERAPP))>0
THEN
EXECUTE IMMEDIATE 'GRANT SELECT,INSERT,DELETE,UPDATE ON '||V_OBJECT||' TO '||OWNERAPP;
EXECUTE IMMEDIATE 'CREATE OR REPLACE SYNONYM '||OWNERAPP||'.'||V_OBJECT||' FOR '||OWNER||'.'||V_OBJECT;
END IF;
END LOOP;
CLOSE BRANCH01
EXCEPTION
WHEN NO_DATA_FOUND THEN
DBMS_OUTPUT.PUT_LINE(SQLCODE || SQLERRM);
WHEN OTHERS THEN
INSERT INTO LOG(ECODE,EMESSAGE,EINFO) VALUES(V_ERRCODE,V_ERRMSG,V_INFORMATION);
COMMIT;
RETURN
END proc_grant;
例2:
Connection conn=ConUtil.getConnectio n();
CallableStatement proc;
int res=0;
proc=conn.prepareCall("{call proc1(?)}");
proc.registerOutParameter(1,Types.NUMBERIC);
proc.execute();
res=proc.getInt(1);
con.close();
推荐阅读
-
关系数据库的末日是否已经来临 博客分类: 数据库 数据结构网络应用应用服务器CouchDB项目管理
-
存储过程(sp)的应用 博客分类: 数据库 Oracle
-
存储过程(sp)的应用 博客分类: 数据库 Oracle
-
游标中嵌套有其他查询时要注意的问题 博客分类: Mysql MySQL游标存储过程
-
数据库集群技术 博客分类: 杂乱无章-技术 数据结构数据挖掘Oracle应用服务器企业应用
-
oracle中CLOB类型的存取 博客分类: 数据库 cloboracleEMPTY_CLOB()for update
-
ORACLE for update和for update nowait的区别 博客分类: Oracle 数据库oraclefor updatefor update nowait
-
Oracle修改表数据的小技巧 博客分类: Oracle oracle数据库for updaterowid
-
ORACLE存储过程,循环语法和游标(转) 博客分类: Oracle
-
概括数据库应用系统的性能优化 博客分类: mysql