fix sqlplus alternative quoting

This commit is contained in:
Ottmar Gobrecht 2020-11-16 09:48:43 +01:00
parent 68f98e08ae
commit 460b3ef5ef
5 changed files with 1171 additions and 1123 deletions

View File

@ -87,7 +87,7 @@ SIGNATURE
```sql
PACKAGE PLEX AUTHID current_user IS
c_plex_name CONSTANT VARCHAR2(30 CHAR) := 'PLEX - PL/SQL Export Utilities';
c_plex_version CONSTANT VARCHAR2(10 CHAR) := '2.2.0.5';
c_plex_version CONSTANT VARCHAR2(10 CHAR) := '2.2.0.6';
c_plex_url CONSTANT VARCHAR2(40 CHAR) := 'https://github.com/ogobrecht/plex';
c_plex_license CONSTANT VARCHAR2(10 CHAR) := 'MIT';
c_plex_license_url CONSTANT VARCHAR2(60 CHAR) := 'https://github.com/ogobrecht/plex/blob/master/LICENSE.txt';

View File

@ -47,7 +47,7 @@ END;
prompt Compile package plex (spec)
CREATE OR REPLACE PACKAGE PLEX AUTHID current_user IS
c_plex_name CONSTANT VARCHAR2(30 CHAR) := 'PLEX - PL/SQL Export Utilities';
c_plex_version CONSTANT VARCHAR2(10 CHAR) := '2.2.0.5';
c_plex_version CONSTANT VARCHAR2(10 CHAR) := '2.2.0.6';
c_plex_url CONSTANT VARCHAR2(40 CHAR) := 'https://github.com/ogobrecht/plex';
c_plex_license CONSTANT VARCHAR2(10 CHAR) := 'MIT';
c_plex_license_url CONSTANT VARCHAR2(60 CHAR) := 'https://github.com/ogobrecht/plex/blob/master/LICENSE.txt';
@ -1631,39 +1631,50 @@ IS
----------------------------------------
FUNCTION quote_string (p_string VARCHAR2) RETURN VARCHAR2 IS
v_string varchar2(5000 char);
BEGIN
if instr(p_string, '''') = 0 then
return '''' || p_string || '''';
v_string := '''' || p_string || '''';
--
elsif instr(p_string, '^''') = 0 then
return 'q''^' || p_string || '^''';
v_string := 'q''^' || p_string || '^''';
--
elsif instr(p_string, '`''') = 0 then
return 'q''`' || p_string || '`''';
v_string := 'q''`' || p_string || '`''';
--
elsif instr(p_string, '#''') = 0 then
return 'q''#' || p_string || '#''';
v_string := 'q''#' || p_string || '#''';
--
elsif instr(p_string, '|''') = 0 then
return 'q''|' || p_string || '|''';
v_string := 'q''|' || p_string || '|''';
--
elsif instr(p_string, '!''') = 0 then
return 'q''!' || p_string || '!''';
v_string := 'q''!' || p_string || '!''';
--
elsif instr(p_string, '}''') = 0 then
return 'q''{' || p_string || '}''';
v_string := 'q''{' || p_string || '}''';
--
elsif instr(p_string, ']''') = 0 then
return 'q''[' || p_string || ']''';
v_string := 'q''[' || p_string || ']''';
--
elsif instr(p_string, '>''') = 0 then
return 'q''<' || p_string || '>''';
v_string := 'q''<' || p_string || '>''';
--
elsif instr(p_string, ')''') = 0 then
return 'q''(' || p_string || ')''';
v_string := 'q''(' || p_string || ')''';
else
return '''' || replace(p_string, '''', '''''') || '''';
v_string := '''' || replace(p_string, '''', '''''') || '''';
end if;
-- SQL*Plus specific:
-- SQL Failed With ORA-1756 In Sqlplus But Works In SQL Developer
-- (Doc ID 2377701.1, https://support.oracle.com/epmos/faces/DocumentDisplay?id=2377701.1)
if instr(v_string, ';'||chr(10)) = 0 then
return v_string;
else
return ('replace(' || replace(v_string, ';'||chr(10), ';!'||chr(10)) || ','';!''||chr(10),'';''||chr(10))');
end if;
END quote_string;
----------------------------------------
@ -1831,13 +1842,18 @@ IS
----------------------------------------
-- SQL*Plus specific:
-- SQL Failed With ORA-1756 In Sqlplus But Works In SQL Developer
-- (Doc ID 2377701.1, https://support.oracle.com/epmos/faces/DocumentDisplay?id=2377701.1)
PROCEDURE create_header IS
BEGIN
util_clob_append('-- Script generated by PLEX version ' || c_plex_version || ' - more infos here: ' || c_plex_url || c_crlf);
util_clob_append('-- Performance Hacks by Connor McDonald: https://connor-mcdonald.com/2019/05/17/hacking-together-faster-inserts/' || c_crlf);
util_clob_append('-- For strange line end replacements a big thank to SQL*Plus: https://support.oracle.com/epmos/faces/DocumentDisplay?id=2377701.1 (SQL Failed With ORA-1756 In Sqlplus But Works In SQL Developer)' || c_crlf);
util_clob_append('prompt Insert into ' || p_table_name || c_crlf);
util_clob_append('timing start inserts' || c_crlf);
util_clob_append('set define off feedback off' || c_crlf);
util_clob_append('set define off feedback off sqlblanklines on' || c_crlf);
util_clob_append('alter session set cursor_sharing = force;' || c_crlf);
util_clob_append(q'^alter session set nls_numeric_characters = '.,';^' || c_crlf);
util_clob_append(q'^alter session set nls_date_format = 'yyyy-mm-dd hh24:mi:ss';^' || c_crlf);

View File

@ -990,39 +990,50 @@ IS
----------------------------------------
FUNCTION quote_string (p_string VARCHAR2) RETURN VARCHAR2 IS
v_string varchar2(5000 char);
BEGIN
if instr(p_string, '''') = 0 then
return '''' || p_string || '''';
v_string := '''' || p_string || '''';
--
elsif instr(p_string, '^''') = 0 then
return 'q''^' || p_string || '^''';
v_string := 'q''^' || p_string || '^''';
--
elsif instr(p_string, '`''') = 0 then
return 'q''`' || p_string || '`''';
v_string := 'q''`' || p_string || '`''';
--
elsif instr(p_string, '#''') = 0 then
return 'q''#' || p_string || '#''';
v_string := 'q''#' || p_string || '#''';
--
elsif instr(p_string, '|''') = 0 then
return 'q''|' || p_string || '|''';
v_string := 'q''|' || p_string || '|''';
--
elsif instr(p_string, '!''') = 0 then
return 'q''!' || p_string || '!''';
v_string := 'q''!' || p_string || '!''';
--
elsif instr(p_string, '}''') = 0 then
return 'q''{' || p_string || '}''';
v_string := 'q''{' || p_string || '}''';
--
elsif instr(p_string, ']''') = 0 then
return 'q''[' || p_string || ']''';
v_string := 'q''[' || p_string || ']''';
--
elsif instr(p_string, '>''') = 0 then
return 'q''<' || p_string || '>''';
v_string := 'q''<' || p_string || '>''';
--
elsif instr(p_string, ')''') = 0 then
return 'q''(' || p_string || ')''';
v_string := 'q''(' || p_string || ')''';
else
return '''' || replace(p_string, '''', '''''') || '''';
v_string := '''' || replace(p_string, '''', '''''') || '''';
end if;
-- SQL*Plus specific:
-- SQL Failed With ORA-1756 In Sqlplus But Works In SQL Developer
-- (Doc ID 2377701.1, https://support.oracle.com/epmos/faces/DocumentDisplay?id=2377701.1)
if instr(v_string, ';'||chr(10)) = 0 then
return v_string;
else
return ('replace(' || replace(v_string, ';'||chr(10), ';!'||chr(10)) || ','';!''||chr(10),'';''||chr(10))');
end if;
END quote_string;
----------------------------------------
@ -1190,13 +1201,18 @@ IS
----------------------------------------
-- SQL*Plus specific:
-- SQL Failed With ORA-1756 In Sqlplus But Works In SQL Developer
-- (Doc ID 2377701.1, https://support.oracle.com/epmos/faces/DocumentDisplay?id=2377701.1)
PROCEDURE create_header IS
BEGIN
util_clob_append('-- Script generated by PLEX version ' || c_plex_version || ' - more infos here: ' || c_plex_url || c_crlf);
util_clob_append('-- Performance Hacks by Connor McDonald: https://connor-mcdonald.com/2019/05/17/hacking-together-faster-inserts/' || c_crlf);
util_clob_append('-- For strange line end replacements a big thank to SQL*Plus: https://support.oracle.com/epmos/faces/DocumentDisplay?id=2377701.1 (SQL Failed With ORA-1756 In Sqlplus But Works In SQL Developer)' || c_crlf);
util_clob_append('prompt Insert into ' || p_table_name || c_crlf);
util_clob_append('timing start inserts' || c_crlf);
util_clob_append('set define off feedback off' || c_crlf);
util_clob_append('set define off feedback off sqlblanklines on' || c_crlf);
util_clob_append('alter session set cursor_sharing = force;' || c_crlf);
util_clob_append(q'^alter session set nls_numeric_characters = '.,';^' || c_crlf);
util_clob_append(q'^alter session set nls_date_format = 'yyyy-mm-dd hh24:mi:ss';^' || c_crlf);

View File

@ -1,6 +1,6 @@
CREATE OR REPLACE PACKAGE PLEX AUTHID current_user IS
c_plex_name CONSTANT VARCHAR2(30 CHAR) := 'PLEX - PL/SQL Export Utilities';
c_plex_version CONSTANT VARCHAR2(10 CHAR) := '2.2.0.5';
c_plex_version CONSTANT VARCHAR2(10 CHAR) := '2.2.0.6';
c_plex_url CONSTANT VARCHAR2(40 CHAR) := 'https://github.com/ogobrecht/plex';
c_plex_license CONSTANT VARCHAR2(10 CHAR) := 'MIT';
c_plex_license_url CONSTANT VARCHAR2(60 CHAR) := 'https://github.com/ogobrecht/plex/blob/master/LICENSE.txt';

File diff suppressed because it is too large Load Diff