Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
INTEGRAL
For Base Integral Database
Prepared by
DXC Technology
The document contains proprietary and confidential information and is provided on the basis
that such information will be confidential. This work is copyright. No part may be reproduced
or transmitted in any form or by any means, electronic, mechanical, photocopying, recording
or otherwise or stored in any retrieval system of any nature, without prior written permission
of DXC Technology.
The information in this document is believed to be accurate in all respects. The company and
its divisions and subsidiaries cannot, however, assume responsibility for any consequences
resulting from the use of this information. The information contained herein is subject to
changes; revisions or new editions may be issued to incorporate such changes.
DXC Technology
1 Depot Close
#03-01Tower A
Singapore 109841
DXC Technology is created by the merger of CSC and the Enterprise Services business of
Hewlett Packard Enterprise. Both CSC and HPE Enterprise Services were known for
evolving to keep pace with the ever-changing world of technology – and for offering clients a
fresh perspective built on a rich heritage of innovation and industry-leading services.
2. PURPOSE .......................................................................................................................... 6
3.2 REMOVE THE BLANK LINE DURING SCRIPT FOR “CREATE TABLE” OR “CREATE VIEW”. .......................... 7
3.4 USE “UTF-8” ENCODING FORMAT INSTEAD “UNICODE BIG ENDIAN” WHEN USING MUTLI-LANGUAGE
DATA, AND MAKE THE FIRST LINE IS BLANK LINE. ........................................................................................... 8
3.7 RESET THE SEQUENCE CURRENT VALUE TO INSERT NEW DATA WHEN MET ERROR: ORA-00001 . ....... 9
5.2 DDL STATEMENT, PLEASE ADD COMMENTS AT THE SAME TIME .......................................................... 12
5.2.1 DDL for “CREATE A NEW TABLE” ................................................................................... 12
5.2.2 DDL for “DROP TABLE” .................................................................................................... 13
5.2.3 DDL for “ADD NEW COLUMN TO TABLE” ..................................................................... 14
5.2.4 DDL for “MODIFY EXISTING COLUMN” ........................................................................ 14
5.2.5 DDL for “DROP EXISTING COLUMN”............................................................................. 15
5.2.6 DDL for “RENAME A COLUMN in an existing table” ....................................................... 16
5.2.7 DDL for “ADD NEW INDEX” ............................................................................................. 16
5.3 VIEW STATEMENT. ............................................................................................................................. 17
2. Purpose
The purpose of this document is to define the DB RULES for Integral database script
which is submitted by developers.
DECLARE
cnt number(2,1) :=0;
BEGIN
SELECT count(*) into cnt FROM USER_TAB_COLUMNS where table_name
= 'PREQPF' and column_name ='ZTXINVDT' ;
IF ( cnt > 0 ) THEN
EXECUTE IMMEDIATE (' ALTER TABLE PREQPF MODIFY ZTXINVDT
NUMBER(8) ');
END IF;
END;
/
3.2 Remove the blank line during script for “create table” or
“create view”.
For example:
The above script will fail because the blank line during “create table”.
And this script will success in MSSQL !
Note:
Commit is not needed for DDL script since the database will commit
automatically.
For auto-exec script(using sqlplus to execute), “Unicode big endian” could not
be recognized and show ERRORS like this:
SQL> SP2-0042: unknown command "þÿ" - rest of line ignored.
After this error, all the following script will be not be executed!
GENAREA RAW(2000)
1. So please make sure you data size for GENAREA of ITEMPF is less than
2000.
Usually you could just remove the last 2000 characters directly when you
convert the MSSQL data to ORACLE data.
For example:
Just change the data:
'20202020E8A2ABE4BF9DE4BABAE79BAEE5898DE698AFE590A6E59CA8
E6B2BBE79697E4B8ADEFBC8CE69C8DE88DAFE4B8ADEFBC8CE69C89
E5A484E696B9E68896E88085E585B6E5AE83E79A84EFBC8CE698AFE59
0A6E59CA8E7AD89E5BE85E4BBBBE4BD95E8AF8AE79697203F20202020
20202020202020202020202020202020202020202020202020202020202020
2020202020202020202020202020202020202020‘
To
2. Decrease your single line less than 2499 for your sql script when you met
the following errors:
SP2-0027: Input is too long (> 2499 characters) - line ignored
For example:
ALTER TABLE ACAGPF1 ADD JOBNM CHAR(10)
The above script will not execute.
Sometimes, when you insert new data to table, there are errors like this:
ORA-00001: unique constraint (VM1DTA.PK_BUPAPF) violated
The error happens because the imported dump file is generated when many
developers access data, this will make the table data(mainly
UNIQUE_NUMBER column value) is not synchronous with sequence current
value.
Otherwise the object will be created in system default schema:dbo and this
will make the database confused and sometime it will cause errors.
For example:
SET QUOTED_IDENTIFIER ON
GO
IF EXISTS (SELECT 1 FROM VM1DTA.CLBADDB WHERE
BANKACCKEY='123456789')
UPDATE VM1DTA.CLBADDB set BANKACCKEY = '58' WHERE
BANKACCKEY = '123456789'
GO
Version 0.4: 20 April 2018
Document ID: Integral DB Script Rule_Updated.doc Page 10
SET QUOTED_IDENTIFIER OFF
GO
Please do not use “” to specify the object name or column name, use [] or just
blank is enough, otherwise your script will not execute correctly.
-------------------------------------TABLE -------------------------------------
-- -- -- -- -- -- -- -- CREATE A NEW TABLE -- -- -- -- -- -- -- --
DECLARE
cnt number(2,1);
begin
SELECT count(*) into cnt FROM user_tables where table_name = '<table_name>' ;
IF ( cnt > 0 ) THEN
EXECUTE IMMediate ('CREATE TABLE table_name
( { <column_definition> } ,...n
)'
);
EXECUTE IMMEDIATE ('COMMENT ON TABLE table_name IS ''………''');
-- -- -- -- -- -- -- -- ---Example
DECLARE
cnt number(2,1) :=0;
BEGIN
SELECT count(*) into cnt FROM user_tables where table_name = 'ACAGPF1' ;
IF ( cnt = 0 ) THEN
EXECUTE IMMediate (
' CREATE TABLE VM1DTA.ACAGPF1
( UNIQUE_NUMBER NUMBER(18,0),
CONSTRAINT PK_ACAGPF1 PRIMARY KEY (UNIQUE_NUMBER)
)'
);
EXECUTE IMMEDIATE ('COMMENT ON TABLE ACAGPF1 IS ''test''');
EXECUTE IMMEDIATE ('COMMENT ON COLUMN VM1DTA.ACAGPF1.
UNIQUE_NUMBER IS ''Contract Number''');
END IF;
END;
/
--DROP TABLE
DECLARE
cnt number(2,1);
begin
SELECT count(*) into cnt FROM user_tables where table_name = 'table_name' ;
IF ( cnt > 0 ) THEN
EXECUTE IMMEDIATE ('DROP TABLE table_name ');
end if ;
end;
/
--EXAMPLE
DECLARE
cnt number(2,1) :=0;
BEGIN
SELECT count(*) into cnt FROM USER_TAB_COLUMNS where table_name =
'ACAGPF1' and column_name ='JOBNM' ;
IF ( cnt > 0 ) THEN
EXECUTE IMMEDIATE (' ALTER TABLE ACAGPF1 MODIFY JOBNM CHAR(20) ');
END IF;
END;
/
-- Example
CREATE OR REPLACE FORCE VIEW "VM1DTA"."ACAGRNL"
("UNIQUE_NUMBER", "RLDGCOY", "SACSCODE", "RLDGPFX", "RLDGACCT",
"ORIGCURR", "SACSTYP", "SACSCURBAL", "RDOCNUM", "GLSIGN", "JOBNM",
"USRPRF", "DATIME") AS
SELECT
UNIQUE_NUMBER,RLDGCOY,SACSCODE,RLDGPFX,RLDGACCT,ORIGCURR,SA
CSTYP,SACSCURBAL,RDOCNUM,GLSIGN,JOBNM,USRPRF,DATIME
FROM ACAGPF;
END;
/
DECLARE
cnt number(2,1) :=0;
BEGIN
SELECT count(*) into cnt FROM user_sequences WHERE sequence_name =
'SCHEMA.SEQUENCE_NAME';
IF ( cnt > 0 ) THEN
EXECUTE IMMEDIATE (' DROP SEQUENCE sequence_name');
END IF;
END;
/
Then, choose the following download(32 bit or 64 bit) according to your env:
5.8.1.1 Oracle Database 12c Release 2 Client (12.2.0.1.0) for Microsoft
Windows (x64)
winx64_12201_client.zip (64-bit) (1,180,923,073 bytes)
INSERT INTO
[VM1DTA].[HELPPF]([HELPPFX],[HELPCOY],[HELPLANG],[HELPTYPE],[HELPPROG],[HELPI
TEM],[HELPSEQ],[TRANID],[VALIDFLAG],[HELPLINE],[USRPRF],[JOBNM],[DATIME])
VALUES ('HP','','E','S','SQ956', '','1','','1','This screen is used to create/ maintain
','UNDERWR1','UNDERWR1',CURRENT_TIMESTAMP )
GO
IF NOT EXISTS ( SELECT * FROM sys.tables where name = '<table_name>' and type
= 'U'
and schema_id = (select schema_id from sys.schemas where
name='<schema_name>'))
BEGIN
CREATE TABLE [ database_name . [ schema_name ] . | schema_name . ]
table_name
( { <column_definition> } [ ,...n ]
)
[;];
EXEC sys.sp_addextendedproperty @name=N'MS_Description',
@value=N'<table_comment>' , @level0type=N'SCHEMA',@level0name=N'dbo',
@level1type=N'TABLE',@level1name=N'<table_name>';
EXEC sys.sp_addextendedproperty @name=N'MS_Description',
@value=N'<comment>' , @level0type=N'SCHEMA',@level0name=N'dbo',
@level1type=N'TABLE',@level1name=N'<table_name>',
@level2type=N'COLUMN',@level2name=N'<column_name>';
…
END
GO
--Example
IF NOT EXISTS ( SELECT * FROM sys.tables where name = 'MGCLPF1' and type =
'U' and schema_id = (select schema_id from sys.schemas where name='VM1DTA'))
BEGIN
CREATE TABLE [VM1DTA].[MGCLPF1](
[UNIQUE_NUMBER] [bigint] IDENTITY(1,1) NOT NULL,
[CLMCOY] [nchar](1) NULL
);
--DROP TABLE
IF EXISTS ( SELECT * FROM sys.tables where name = '<table_name>' and type = 'U'
and schema_id = (select schema_id from sys.schemas where
name='<schema_name>'))
DROP TABLE [ database_name . [ schema_name ] . | schema_name . ] table_name
GO
--Example
IF EXISTS ( SELECT * FROM sys.tables where name = 'MGCLPF1' and type = 'U' and
schema_id = (select schema_id from sys.schemas where name='VM1DTA'))
DROP TABLE [VM1DTA].[MGCLPF1]
*/
Example:
--Modify column
IF EXISTS (SELECT * FROM sys.columns WHERE name = 'GCDPNTNO' and
object_id in (SELECT object_id FROM sys.tables WHERE name ='MGCLPF1'))
ALTER TABLE [VM1DTA].[MGCLPF1] ALTER COLUMN GCDPNTNO
varchar(50) null
GO
GO
Example:
--Drop column
Version 0.4: 20 April 2018
Document ID: Integral DB Script Rule_Updated.doc Page 23
IF EXISTS (SELECT * FROM sys.columns WHERE name = 'GCDPNTNO' and
object_id in (SELECT object_id FROM sys.tables WHERE name ='MGCLPF1'))
ALTER TABLE [VM1DTA].[MGCLPF1] DROP COLUMN GCDPNTNO
GO
*/
Example:
IF EXISTS ( SELECT t.* FROM sys.triggers t inner join sys.objects o on o.object_id
= t.parent_id where o.name ='MGCLPF1' and t.name ='TR_AUDIT_AGPLPF1')
Example:
IF EXISTS ( SELECT * FROM sys.objects WHERE name = 'ZADRPF_Update1' and
type = 'P' )
DROP Procedure [VM1DTA].[ZADRPF_Update1]
GO
--Example
IF EXISTS ( SELECT * FROM sys.objects WHERE name =
'UDF_PROCESSDATE1' and type = 'FN' )
DROP FUNCTION [VM1DTA].[UDF_PROCESSDATE1]
GO
CREATE FUNCTION [VM1DTA].[UDF_PROCESSDATE1] (@LASTCHANGE
varchar(14))
RETURNS datetime
AS
BEGIN
RETURN getdate()
END
GO
6.7 INDEX Statement.
IF EXISTS ( SELECT * FROM sys.indexes i inner join sys.objects o on i.object_id =
o.object_id WHERE i.name = '<Index_name>' and o.name = '<table_name>' )
DROP INDEX [<index_name>] ON [<schema_name>].[<table_name>]
GO
<CREATE INDEX ...>
GO
Example
IF EXISTS ( SELECT o.* FROM sys.indexes i inner join sys.objects o on i.object_id
= o.object_id WHERE i.name = 'GRX21' and o.name = 'GRX2PF1' )
DROP INDEX [GRX21] ON [VM1DTA].[GRX2PF1]
GO