Tuesday, August 1, 2017
Simple Oracle PL SQL Logging utility
Simple Oracle PL SQL Logging utility
Below several ddl statements for creating a logtable and a package with methods for calling.
One thing about plsql is that dbms_output.put_line is a long string to enter each time.
With code below the calls j.l and j.p can be used.
- j.l for logging to a table
- j.p to do a dbms_output.put_line
whenever sqlerror continue
drop table logtab;
drop sequence logtab_seq;
whenever sqlerror exit rollback
create sequence logtab_seq
/
CREATE TABLE LOGTAB ( ID NUMBER NOT NULL
, GEBRUIKER VARCHAR2(200) DEFAULT USER NOT NULL
, CREATIE DATE DEFAULT SYSDATE NOT NULL
, TEXT1 VARCHAR2(4000)
, TEXT2 VARCHAR2(4000)
, NUMMER1 NUMBER
, NUMMER2 NUMBER
, DATUM1 DATE
, DATUM2 DATE
, CONSTRAINT LOGTAB_PK PRIMARY KEY(ID) )
/
create or replace trigger LOGTAB_BIR BEFORE INSERT ON LOGTAB FOR EACH ROW
Begin
:NEW.ID := LOGTAB_SEQ.NEXTVAL;
end logtab_bir;
/
create or replace package j
as
--
procedure l ( p_text1 in varchar2 default null
, p_text2 in varchar2 default null
, p_nummer1 in number default null
, p_nummer2 in number default null
, p_datum1 in date default null
, p_datum2 in date default null );
--
procedure p ( p_instr in varchar2 );
--
end j;
/
create or replace public synonym j for admjvo.j;
grant execute on j to public;
is
--
procedure l ( p_text1 in varchar2 default null
, p_text2 in varchar2 default null
, p_nummer1 in number default null
, p_nummer2 in number default null
, p_datum1 in date default null
, p_datum2 in date default null )
is
pragma autonomous_transaction;
l_TEXT1 VARCHAR2(4000);
begin
l_text1 := substr(p_text1,1,4000);
insert into logtab ( text1, text2, nummer1, nummer2, datum1, datum2 ) values ( l_text1, p_text2, p_nummer1, p_nummer2, p_datum1, p_datum2 );
commit;
end l;
--
procedure p ( p_instr in varchar2 )
is
begin
dbms_output.put_line(p_instr);
end p;
--
end j;
/
prompt compileren
@@ compile.sql
show errors
download file now
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.