作者:Carre陈 | 来源:互联网 | 2023-09-24 12:01
有时候,我们想查看表,存储,触发器等对象的定语语句,有以下两种方法:
1. 查 all_source 表
2. 用 DBMS_METADATA 包。
一. 通过 all_source 表
先来确认下,通过all_source 表可以查看哪些类型的对象:
SQL> SELECT distinct type FROM ALL_SOURCE;
TYPE
------------
PROCEDURE
PACKAGE
PACKAGE BODY
LIBRARY
TYPE BODY
TRIGGER
FUNCTION
JAVA SOURCE
TYPE
从以上的结果我们可以看到,我们可以通过该表查询的对象.
查看存储过程定义语句:
SQL> SELECT text FROM ALL_SOURCE where TYPE='PROCEDURE' AND NAME ='ADDCUSTBUSS';
TEXT
--------------------------------------------------------------------------------
PROCEDURE addcustbuss (
acustid IN custbuss.custid%TYPE,
bussname IN custbuss.businessname%TYPE,
aopid IN custbuss.opid%TYPE,
acreatetime IN custbuss.createtime%TYPE,
aCustTel IN custbuss.CustTel%TYPE,--客户电话
aContact IN custbuss.Contact%TYPE,--联系人
aFeedback IN custbuss.Feedback%TYPE,--客户反馈
asid OUT custbuss.ID%TYPE,
RESULT OUT INTEGER
)
IS
BEGIN
RESULT := -1;
SELECT getarea || TO_CHAR (idseq.NEXTVAL, 'FM0999999999')
INTO asid
FROM DUAL;
INSERT INTO custbuss
(ID, custid, businessname, opid, createtime,CustTel,Contact,Feedback
)
VALUES (asid, acustid, bussname, aopid, acreatetime,aCustTel,aContact,aFeedback
);
RESULT := 0;
EXCEPTION
WHEN OTHERS
THEN
RESULT := -1;
END addcustbuss;
已选择32行。
SQL>
查看触发器 定义语句
SQL> SELECT text FROM ALL_SOURCE where TYPE='TRIGGER' AND NAME ='TRDB_TEAM';
TEXT
-----------------------------------------------------------------------------
TRIGGER "NEWCCS".trdb_team
BEFORE DELETE
ON team
REFERENCING NEW AS NEW OLD AS OLD
FOR EACH ROW
BEGIN
DELETE FROM team_teamgroup_map
WHERE teamid = :OLD.teamid;
END trdb_team;
已选择10行。
方法也比较简单,修改TYPE 和 NAME 就可以。 注意要大写。