Quote:
tonkuma in the above example you used a virtual data. means not exist in table, what we say this concept???
If I want to create the same above thing but with two values means in pair , how to do it???
|
Although, I couldn't understand well second sentence,
I hope that following example may give you some ideas.
Tested on
Database server = DB2/NT 9.7.2
CREATE TABLE and INSERT data:
Code:
------------------------------ Commands Entered ------------------------------
CREATE TABLE nitingautam.t1
( ssn_id INTEGER
);
------------------------------------------------------------------------------
DB20000I The SQL command completed successfully.
------------------------------ Commands Entered ------------------------------
INSERT INTO nitingautam.t1
VALUES 123456;
------------------------------------------------------------------------------
DB20000I The SQL command completed successfully.
------------------------------ Commands Entered ------------------------------
SELECT * FROM nitingautam.t1;
------------------------------------------------------------------------------
SSN_ID
-----------
123456
1 record(s) selected.
ALTER and REORG TABLE:
Code:
------------------------------ Commands Entered ------------------------------
ALTER TABLE nitingautam.t1
ALTER COLUMN ssn_id
SET DATA TYPE VARCHAR(9);
------------------------------------------------------------------------------
DB20000I The SQL command completed successfully.
------------------------------ Commands Entered ------------------------------
REORG TABLE nitingautam.t1;
------------------------------------------------------------------------------
DB20000I The REORG command completed successfully.
INSERT new data:
Code:
------------------------------ Commands Entered ------------------------------
INSERT INTO nitingautam.t1
VALUES '001234567';
------------------------------------------------------------------------------
DB20000I The SQL command completed successfully.
------------------------------ Commands Entered ------------------------------
SELECT * FROM nitingautam.t1;
------------------------------------------------------------------------------
SSN_ID
---------
123456
001234567
2 record(s) selected.
UPDATE old data:
Code:
------------------------------ Commands Entered ------------------------------
UPDATE nitingautam.t1
SET ssn_id = RIGHT('00000000' || ssn_id , 9)
WHERE LENGTH( RTRIM(ssn_id) ) < 9
;
------------------------------------------------------------------------------
DB20000I The SQL command completed successfully.
------------------------------ Commands Entered ------------------------------
SELECT * FROM nitingautam.t1;
------------------------------------------------------------------------------
SSN_ID
---------
000123456
001234567
2 record(s) selected.