📄 bootstrap.sql
字号:
char4 := char4 + ASCII('A'); ELSE IF char4 BETWEEN 26 AND 51 THEN char4 := char4 + ASCII('a') - 26; ELSE IF char4 BETWEEN 52 AND 63 THEN IF char4 = 62 THEN char4 := 43; ELSE char4 := char4 + ASCII('0') - 52; END IF; END IF; END IF; END IF; IF char4 = 59 THEN char4 := 47; END IF; IF zeros > 0 THEN char4 := 61; IF zeros > 1 THEN char3 := 61; IF zeros > 2 THEN char2 := 61; END IF; END IF; END IF; --Add these four characters to the string RETURN CHR(char1) || CHR(char2) || CHR(char3) || CHR(char4);END ${replPrefix}base64_helper;-- EOC (end of command: needed as a separator for our script parser) -- ---------------------------------------------------------------------------- -- ${replPrefix}base64_enc_raw converts a RAW msg to a base64 encoded string. -- This is needed for ORACLE versions previous to Oracle9. -- content will be encoded to base64. -- name: the name of content to be encoded. -- ---------------------------------------------------------------------------- CREATE OR REPLACE FUNCTION ${replPrefix}base64_enc_raw(msg RAW, res IN OUT NOCOPY CLOB) RETURN INTEGER AS numBuilder INTEGER; char1 SMALLINT; char2 SMALLINT; char3 SMALLINT; char4 SMALLINT; i INTEGER; len INTEGER;-- divisible by 3 (to avoid '=' characters at end of chunks) source RAW(32766); zeros SMALLINT; ch CHAR(10); str VARCHAR(${charWidthSmall});BEGIN source := msg; WHILE utl_raw.length(source) > 0 LOOP i := 1; numBuilder := 0; zeros := 0; WHILE i <= 3 LOOP IF i > utl_raw.length(source) THEN numBuilder := numBuilder*256; zeros := zeros + 1; ELSE ch := utl_raw.cast_to_varchar2(utl_raw.substr(source, i, 1)); numBuilder := numBuilder*256 + ASCII(ch); END IF; i := i + 1; END LOOP; if utl_raw.length(source) > 3 THEN source := utl_raw.substr(source, 4, utl_raw.length(source)-3); ELSE source := ''; END IF; str := ${replPrefix}base64_helper(zeros, numBuilder); len := LENGTH(str); dbms_lob.writeappend(res, len, str); END LOOP; RETURN 0;END ${replPrefix}base64_enc_raw;-- EOC (end of command: needed as a separator for our script parser) CREATE OR REPLACE FUNCTION ${replPrefix}base64_enc_raw_t(msg RAW) RETURN CLOB AS tmp CLOB; fake INTEGER;BEGIN tmp := EMPTY_CLOB; dbms_lob.createtemporary(tmp, TRUE); dbms_lob.open(tmp, dbms_lob.lob_readwrite); fake := ${replPrefix}base64_enc_raw(msg, tmp); dbms_lob.close(tmp); RETURN tmp;END ${replPrefix}base64_enc_raw_t;-- EOC (end of command: needed as a separator for our script parser) -- ---------------------------------------------------------------------------- -- ${replPrefix}test_blob is only needed for testing since there are problems -- in passing LOB objects to the arguments of a method in ORACLE 8.1.6 in a -- portable fashion. -- since it seems there is no portable way in JDBC to create LOB objects to be -- passed to functions. A Blob object is valid for the duration of the -- transaction in which is was created. -- ---------------------------------------------------------------------------- CREATE OR REPLACE FUNCTION ${replPrefix}test_blob(method VARCHAR2, msg RAW, other VARCHAR2, nmax INTEGER) RETURN CLOB AS i INTEGER; len INTEGER; tmp BLOB; res CLOB; fake INTEGER;BEGIN ${replPrefix}debug('TEST BLOB INVOKED'); tmp := EMPTY_BLOB; len := utl_raw.length(msg); dbms_lob.createtemporary(tmp, TRUE); dbms_lob.open(tmp, dbms_lob.lob_readwrite); FOR i IN 1 .. nmax LOOP dbms_lob.writeappend(tmp, len, msg); END LOOP; -- dbms_lob.close(tmp); res := EMPTY_CLOB; dbms_lob.createtemporary(res, TRUE); dbms_lob.open(res, dbms_lob.lob_readwrite); IF method = 'BASE64_ENC_BLOB' THEN fake := ${replPrefix}base64_enc_blob(tmp, res); dbms_lob.close(tmp); RETURN res; END IF; IF method = 'COL2XML_BASE64' THEN fake := ${replPrefix}col2xml_base64(other, tmp, res); dbms_lob.close(tmp); RETURN res; END IF; dbms_lob.close(tmp); -- on other just return 'TEST' as a blob len := LENGTH('TEST'); dbms_lob.writeappend(res, len, 'TEST'); dbms_lob.close(res); RETURN res;END ${replPrefix}test_blob;-- EOC (end of command: needed as a separator for our script parser) -- ---------------------------------------------------------------------------- -- ${replPrefix}test_clob is only needed for testing since there are problems -- in passing LOB objects to the arguments of a method in ORACLE 8.1.6 in a -- portable fashion. -- since it seems there is no portable way in JDBC to create LOB objects to be -- passed to functions. A Blob object is valid for the duration of the -- transaction in which is was created. -- ---------------------------------------------------------------------------- CREATE OR REPLACE FUNCTION ${replPrefix}test_clob(method VARCHAR2, msg VARCHAR2, other VARCHAR2, nmax INTEGER) RETURN CLOB AS i INTEGER; len INTEGER; tmp CLOB; res CLOB; needsProt INTEGER; answer VARCHAR(${charWidth}); fake INTEGER;BEGIN ${replPrefix}debug('TEST CLOB INVOKED'); tmp := EMPTY_CLOB; len := LENGTH(msg); answer := 'TEST'; dbms_lob.createtemporary(tmp, TRUE); dbms_lob.open(tmp, dbms_lob.lob_readwrite); res := EMPTY_CLOB; dbms_lob.createtemporary(res, TRUE); dbms_lob.open(res, dbms_lob.lob_readwrite); FOR i IN 1 .. nmax LOOP dbms_lob.writeappend(tmp, len, msg); END LOOP; dbms_lob.close(tmp); IF method = 'BASE64_ENC_CLOB' THEN fake := ${replPrefix}base64_enc_clob(tmp, res); RETURN res; END IF; IF method = 'COL2XML_CDATA' THEN fake := ${replPrefix}col2xml_cdata(other, tmp, res); RETURN res; END IF; IF method = 'COL2XML' THEN fake := ${replPrefix}col2xml(other, tmp, res); RETURN res; END IF; IF method = 'NEEDS_PROT' THEN needsProt := ${replPrefix}needs_prot(tmp); answer := TO_CHAR(needsProt); -- overwrites 'TEST' END IF; IF method = 'FILL_BLOB_CHAR' THEN fake := ${replPrefix}fill_blob_char(msg, other, res); RETURN res; END IF; IF method = 'FILL_BLOB_CHAR2' THEN fake := ${replPrefix}fill_blob_char(msg, other, res); fake := ${replPrefix}fill_blob_char(msg, other, res); RETURN res; END IF; -- on other just return 'TEST' as a blob len := LENGTH(answer); dbms_lob.writeappend(res, len, answer); dbms_lob.close(res); RETURN res;END ${replPrefix}test_clob;-- EOC (end of command: needed as a separator for our script parser) -- ---------------------------------------------------------------------------- -- ${replPrefix}base64_enc_vch converts a VARCHAR2 msg to a base64 encoded -- string. This is needed for ORACLE versions previous to Oracle9. -- content will be encoded to base64. -- name: the name of content to be encoded. -- ---------------------------------------------------------------------------- CREATE OR REPLACE FUNCTION ${replPrefix}base64_enc_vch(msg VARCHAR2, res IN OUT NOCOPY CLOB) RETURN INTEGER AS numBuilder INTEGER; char1 SMALLINT; char2 SMALLINT; char3 SMALLINT; char4 SMALLINT; i INTEGER;-- divisible by 3 (to avoid '=' characters at end of chunks) source VARCHAR2(32766); zeros SMALLINT; ch CHAR(2); str VARCHAR(${charWidthSmall}); fake INTEGER;BEGIN source := msg; WHILE LENGTHB(source) > 0 LOOP i := 1; numBuilder := 0; zeros := 0; WHILE i <= 3 LOOP IF i > LENGTHB(source) THEN numBuilder := numBuilder*256; zeros := zeros + 1; ELSE ch := SUBSTRB(source, i, 1); numBuilder := numBuilder*256 + ASCII(ch); END IF; i := i + 1; END LOOP; if LENGTHB(source) > 3 THEN source := SUBSTRB(source, 4, LENGTHB(source)-3); ELSE source := ''; END IF; str := ${replPrefix}base64_helper(zeros, numBuilder); dbms_lob.writeappend(res, length(str), str); END LOOP; RETURN 0;END ${replPrefix}base64_enc_vch;-- EOC (end of command: needed as a separator for our script parser) CREATE OR REPLACE FUNCTION ${replPrefix}base64_enc_vch_t(msg VARCHAR2) RETURN CLOB AS tmp CLOB; fake INTEGER;BEGIN tmp := EMPTY_CLOB; dbms_lob.createtemporary(tmp, TRUE); dbms_lob.open(tmp, dbms_lob.lob_readwrite); fake := ${replPrefix}base64_enc_vch(msg, tmp); dbms_lob.close(tmp); RETURN tmp;END ${replPrefix}base64_enc_vch_t;-- EOC (end of command: needed as a separator for our script parser) -- ---------------------------------------------------------------------------- -- ${replPrefix}base64_enc_blob converts a BLOB msg to a base64 encoded string. -- This is needed for ORACLE versions previous to Oracle9. -- content will be encoded to base64. -- name: the name of content to be encoded. -- ---------------------------------------------------------------------------- CREATE OR REPLACE FUNCTION ${replPrefix}base64_enc_blob(msg BLOB, res IN OUT NOCOPY CLOB) RETURN INTEGER AS len INTEGER; offset INTEGER; outRaw RAW(32766); increment INTEGER; fake INTEGER;BEGIN offset := 1; increment := 32766; len := dbms_lob.getlength(msg); WHILE offset < len LOOP dbms_lob.read(msg, increment, offset, outRaw); offset := offset + increment; -- the next line would be used for oracle from version 9 up. -- res := res || utl_raw.cast_to_varchar2(utl_encode.base64_encode(tmp)); fake := ${replPrefix}base64_enc_raw(outRaw, res); END LOOP; RETURN 0;END ${replPrefix}base64_enc_blob;-- EOC (end of command: needed as a separator for our script parser) -- ---------------------------------------------------------------------------- -- ${replPrefix}base64_enc_clob converts a CLOB msg to a base64 encoded string. -- This is needed for ORACLE versions previous to Oracle9. -- content will be encoded to base64. -- name: the name of content to be encoded.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -