I understand that this is quite late, and that I do not have such a fine-tuning. However, what I did with Oracle (11gR2) on SQL Server (2008R2 and earlier) was to read INFORMATION_SCHEMA.COLUMNS through the database link, and then dynamically generate the row for EXECUTE IMMEDIATE in PL / SQL.
DECLARE TYPE associative_array IS TABLE OF VARCHAR2(100) INDEX BY VARCHAR2(50); data_type_tranforms associative_array; dynamicSQL varchar2(32767); column_list varchar2(32767) := ''; expressions varchar2(32767) := ''; FUNCTION apply_transform(column_name VARCHAR2, data_type VARCHAR2) RETURN VARCHAR2 AS transformed VARCHAR2(1000); BEGIN IF data_type_transforms.exists(data_type) THEN transformed := replace(data_type_transforms(data_type),'$$',column_name); ELSE transformed := column_name; END IF; RETURN transformed; END apply_transform; FUNCTION strip_last_character(input VARCHAR2) RETURN VARCHAR2 AS BEGIN RETURN SUBSTR(input, 1, LENGTH(input) - 1); END strip_last_character; BEGIN data_type_transforms('LONG') := 'to_lob($$)'; FOR col IN ( SELECT column_name ,data_type FROM information_schema.columns@DBLINK WHERE table_name = 'TABLE_TO_COPY' ORDER BY ordinal_position ) LOOP column_list := column_list || col.column_name ||','; expressions := expressions || apply_transform(col.column_name, col.data_type) ||','; END LOOP; dynamicSQL := 'INSERT INTO table_to_copy ('|| strip_last_character(column_list)|| ') SELECT '|| strip_last_character(expressions)|| ' FROM table_to_copy@DBLINK '; EXECUTE IMMEDIATE dynamicSQL; END;
I save a series of templates in an array of PL / SQL indexes with an index that is a data type, and the value is an expression of the type 'to_date(''$$'',''YYYYMMDD'')'
, from which the $$
characters are replaced with the column_name name. If you need to completely remove the data type, which I often do, I just put an empty string in the data type array.
source share