Home > database >  SQL database field type problem (CHAR and VARCHAR2)
SQL database field type problem (CHAR and VARCHAR2)

Time:09-21

Hello, everyone:

Learning knowledge database now, encounter a problem, please help answer: create an emp forms, ename type is set to "ename CHAR (10)" and insert the data after the ename type is set to "ename VARCHAR2 (12)", after the setup, ename field length calculation, the value of 12 is that cannot be modified after inserting data types, or can't literally change between CHAR and VARCHAR2?

1, a form to emp:
The CREATE TABLE emp (
Empno NUMBER (4),
ename CHAR (10),
Job VARCHAR (20),
MGR NUMBER (4),
Hiredate DATE,
Sal NUMBER (4),
Comm NUMBER (4)
)

2, change the field type and length
The ALTER TABLE emp
The MODIFY (
Ename VARCHAR2 (12)
)

3, the query field length
SELECT
Ename, LENGTH (ename)
The FROM emp

4, the query result:



CodePudding user response:

Usually change type, size, are the beginning the scheduled

CodePudding user response:

With a blank filling is obviously help you... Change your varchar2 (10) to varchar2 (12) look at it?

CodePudding user response:

Before you change the field type, ename fields inside put a value of the original cost plus' space value, namely "SMITH", such after you change the fields to varchar2, the value of it is still "SMITH", so the length of 10, if you want to restore the original value, then you need to do the trim and then change the field type operation,

CodePudding user response:

Char is fixed-length string type, after writing data automatically with Spaces to fill full, varchar2 is longer string, only the actual writing of data, char into a varchar2, Spaces and take in the past,
  • Related