当前位置:网站首页>Kingbasees plug-in DBMS of Jincang database_ UTILITY

Kingbasees plug-in DBMS of Jincang database_ UTILITY

2022-06-25 11:07:00 Thousands of sails pass by the side of the sunken boat_



1. DBMS_UTILITY System package overview


DBMS_UTILITY The system package provides some subroutines with general functions .
DBMS_UTILITY The system package does not support PG Pattern .



2. DBMS_UTILITY System package subprogram


DBMS_UTILITY The subroutines and brief introduction contained in the system package are shown in the following table :
surface 1  DBMS_UTILITY Package subprogram

Subroutines brief introduction
FORMAT_CALL_STACK function
Returns the current call stack .
FORMAT_ERROR_STACK function
Returns the current error stack .
FORMAT_ERROR_BACKTRACE function
Returns the current error backtracking information .
GET_TIME function
Return a timestamp .



2.1. FORMAT_CALL_STACK function
This function can return the current call stack information , Include the address of the calling object , The line number of the call and the name of the call object , It can be used in functions 、 Stored procedure or trigger, etc PL/SQL In the object , Used to help debug PL/SQL Program .
grammar :

DBMS_UTILITY.FORMAT_CALL_STACK() RETURN TEXT;
DBMS_UTILITY.FORMAT_CALL_STACK(FORMAT TEXT) RETURN TEXT;
Note

At present, the address of the calling object is the address of the function or procedure oid value , If it is a built-in function or procedure, it is the corresponding package oid value .

Instructions :

FORMAT: Specify the display mode of the call stack information , There were 'o', 'p', 's' Three models . The default usage mode is 'p' Pattern , Output 8 Bit effective length decimal number output object address information .
  • among 'o' Parameters will be '%8x%8d%s' Format print object address , Call line number , Object name , As the sample 2 Shown .
  • among 'p' Parameters will be '%8d%8d%s' Format print object address , Call line number , Object name , As the sample 3 Shown .
  • among 's' Parameters will be '%d,%d,%s' Format print object address , Call line number , Object name , As the sample 4 Shown .

Example :

\set SQLTERM /
CREATE OR REPLACE FUNCTION checkCallStack() RETURNS TEXT AS
  stack TEXT;
BEGIN
  SELECT dbms_utility.format_call_stack() INTO stack ;
  RETURN stack;
END;
/
\set SQLTERM ;

call checkCallStack();

                           checkcallstack
--------------------------------------------------------------------
----- PL/SQL Call Stack -----                                     +
   object   line    object                                         +
   handle   number  name                                           +
    14575      30   package body sys.dbms_utility.format_call_stack+
    16387       4   function public.checkcallstack
(1 row)


2.2. FORMAT_ERROR_STACK function
This function is used to return the error stack of the current program when an exception occurs , If there is no exception in the program , Then return to NULL.
grammar :

DBMS_UTILITY.FORMAT_ERROR_STACK() RETURN TEXT;


2.3. FORMAT_ERROR_BACKTRACE function
This function is used to return the error backtrace stack when the current program has an exception , If there is no exception in the program , Then return to NULL.
grammar :

DBMS_UTILITY.FORMAT_ERROR_BACKTRACE() RETURN TEXT;

Example :

\set SQLTERM /
CREATE OR REPLACE PROCEDURE p01() AS
  i INT := 0;
BEGIN
  i = i/0;
END;
/
\set SQLTERM ;

\set SQLTERM /
CREATE OR REPLACE PROCEDURE p02() AS
  detail TEXT;
  stack TEXT;
BEGIN
  p01();
EXCEPTION
  WHEN DIVISION_BY_ZERO THEN
    detail = dbms_utility.format_error_stack();
    stack = dbms_utility.format_error_backtrace();
    DBMS_OUTPUT.PUT_LINE('FORMAT_ERROR_STACK IS:');
    DBMS_OUTPUT.PUT_LINE(detail);
    DBMS_OUTPUT.PUT_LINE('FORMAT_ERROR_BACKTRACE IS:');
    DBMS_OUTPUT.PUT_LINE(stack);
END;
/
\set SQLTERM ;

CALL p02();

FORMAT_ERROR_STACK IS:
division by zero
at "public.p01", line 4
FORMAT_ERROR_BACKTRACE IS:
at "public.p01", line 4
at "public.p02", line 5


2.4. GET_TIME function
This function is used to return a timestamp , This timestamp is not a standard system timestamp , The unit is centisecond ( One hundredth of a second ). Usually in PL/SQL Program starts The function is called once at the end of and , Then subtract the previous number from the latter number , To determine the execution time of the current program .
grammar :

DBMS_UTILITY.GET_TIME() RETURN NUMBER;

Instructions :

The return value of the function is in -2147483648 To 2147483647 Between , The specific value depends on the machine and system . When the function is called , Applications You need to consider the sign of the return value . for example , Both calls are negative numbers , Or the first call is negative , The second call is a positive number .

Example :

\set SQLTERM /
CREATE OR REPLACE PROCEDURE TestGetTime() AS
  t1  PLS_INTEGER;
  t2  PLS_INTEGER;
BEGIN
  t1 := dbms_utility.get_time();
  perform pg_sleep(3);
  t2 := dbms_utility.get_time();

  RAISE NOTICE 'sleeped: % sec.', (t2 - t1) / 100;
END;
/
\set SQLTERM ;

call TestGetTime();

NOTICE:  sleeped: 3 sec.


 

原网站

版权声明
本文为[Thousands of sails pass by the side of the sunken boat_]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/176/202206251044549957.html