|
| 1 | +prompt create library using libtoddog.so |
| 2 | + |
| 3 | +CREATE OR REPLACE LIBRARY libtoddog AS '${ORACLE_HOME}/lib/libtoddog.so'; |
| 4 | +/ |
| 5 | +prompt create function f_metrictoddog |
| 6 | + |
| 7 | +CREATE OR REPLACE FUNCTION f_metrictoddog ( |
| 8 | + name IN VARCHAR2, |
| 9 | + metric IN BINARY_INTEGER, |
| 10 | + kind IN VARCHAR2, |
| 11 | + tag IN VARCHAR2) |
| 12 | +RETURN VARCHAR2 AS LANGUAGE C |
| 13 | +NAME "metrictoddog" |
| 14 | +LIBRARY libtoddog |
| 15 | +WITH CONTEXT |
| 16 | +PARAMETERS ( |
| 17 | +CONTEXT, |
| 18 | +name STRING, |
| 19 | +name INDICATOR short, |
| 20 | +metric INT, |
| 21 | +metric INDICATOR short, |
| 22 | +kind STRING, |
| 23 | +kind INDICATOR short, |
| 24 | +tag STRING, |
| 25 | +tag INDICATOR short, |
| 26 | +RETURN INDICATOR short, |
| 27 | +RETURN LENGTH short, |
| 28 | +RETURN STRING); |
| 29 | +/ |
| 30 | +show err |
| 31 | + |
| 32 | +CREATE OR REPLACE FUNCTION f_gaugetoddog( |
| 33 | + name IN VARCHAR2, |
| 34 | + metric IN number, |
| 35 | + tag IN VARCHAR2) |
| 36 | +RETURN VARCHAR2 IS |
| 37 | +BEGIN |
| 38 | + return f_metrictoddog(name,metric,'g',tag); |
| 39 | +END; |
| 40 | +/ |
| 41 | +show err |
| 42 | + |
| 43 | +CREATE OR REPLACE FUNCTION f_counttoddog( |
| 44 | + name IN VARCHAR2, |
| 45 | + metric IN number, |
| 46 | + tag IN VARCHAR2) |
| 47 | +RETURN VARCHAR2 IS |
| 48 | +BEGIN |
| 49 | + return f_metrictoddog(name,metric,'c',tag); |
| 50 | +END; |
| 51 | +/ |
| 52 | +show err |
| 53 | + |
| 54 | +prompt calling function from pl/sql block |
| 55 | +set serveroutput on |
| 56 | + |
| 57 | +declare |
| 58 | + name varchar2(50); |
| 59 | + metric int(10); |
| 60 | + tag varchar2(50); |
| 61 | + result varchar2(10); |
| 62 | + err_num NUMBER; |
| 63 | + err_msg VARCHAR2(100); |
| 64 | +begin |
| 65 | + name := 'sample.gauge'; |
| 66 | + metric := 15; |
| 67 | + tag := 'plsql'; |
| 68 | + result := f_gaugetoddog(name,metric,tag); |
| 69 | + dbms_output.put_line(result); |
| 70 | +EXCEPTION |
| 71 | + WHEN OTHERS THEN |
| 72 | + err_num := SQLCODE; |
| 73 | + err_msg := SUBSTR(SQLERRM, 1, 100); |
| 74 | + raise_application_error(err_num, err_msg); |
| 75 | +END; |
| 76 | +/ |
| 77 | +show err |
| 78 | + |
| 79 | +declare |
| 80 | + name varchar2(50); |
| 81 | + metric int(10); |
| 82 | + tag varchar2(50); |
| 83 | + result varchar2(10); |
| 84 | + err_num NUMBER; |
| 85 | + err_msg VARCHAR2(100); |
| 86 | +begin |
| 87 | + name := 'sample.count'; |
| 88 | + metric := 15; |
| 89 | + tag := 'plsql'; |
| 90 | + result := f_counttoddog(name,metric,tag); |
| 91 | + dbms_output.put_line(result); |
| 92 | +EXCEPTION |
| 93 | + WHEN OTHERS THEN |
| 94 | + err_num := SQLCODE; |
| 95 | + err_msg := SUBSTR(SQLERRM, 1, 100); |
| 96 | + raise_application_error(err_num, err_msg); |
| 97 | +END; |
| 98 | +/ |
| 99 | +show err |
| 100 | + |
| 101 | + |
| 102 | +exit |
0 commit comments