You could use following approach:
- Scan every table in a database for string fields
- For every string field create additional one using unicode character set
- Copy data between fields
- Drop original field
- Rename temporary field
下面是数据转换守则的一个实例:
EXECUTE BLOCK
AS
DECLARE VARIABLE fn CHAR(31) CHARACTER SET UNICODE_FSS;
DECLARE VARIABLE rn CHAR(31) CHARACTER SET UNICODE_FSS;
DECLARE VARIABLE cl INTEGER;
BEGIN
FOR
SELECT
r.rdb$field_name,
r.rdb$relation_name,
f.rdb$character_length
FROM
rdb$relation_fields r JOIN rdb$fields f
ON f.rdb$field_name = r.rdb$field_source
WHERE
f.rdb$character_set_id >= 10
AND f.rdb$character_length > 0
AND f.rdb$field_sub_type IS NULL
INTO :fn, :rn, :cl
DO BEGIN
EXECUTE STATEMENT ALTER TABLE " || :rn ||
" ADD unique_temp_field_name VARCHAR( || :cl ||
) CHARACTER SET UNICODE_FSS
WITH AUTONOMOUS TRANSACTION;
EXECUTE STATEMENT UPDATE " || :rn ||
" SET unique_temp_field_name = " || :fn || "
WITH AUTONOMOUS TRANSACTION;
EXECUTE STATEMENT ALTER TABLE " || :rn || " DROP " || :fn || "
WITH AUTONOMOUS TRANSACTION;
EXECUTE STATEMENT ALTER TABLE " || :rn ||
" ALTER unique_temp_field_name TO ||
" || :fn || "
WITH AUTONOMOUS TRANSACTION;
END
END
For real world application this code should be modified in order to:
- Transfer fields constraints and defaults
- Drop and then restore PK, FK, indices which use field being converted
- Drop and the recreate any trigger or stored procedure which depends on a field being converted