Home > database >  Oracle using the alter column modify the correct data type
Oracle using the alter column modify the correct data type

Time:09-26

Why use the alter column modify data in the Oracle type error? How to solve?
Check information after the great god, because in the modify data type, if it is a small type changed to large type, not an error; If it is a large type changed to small type, should be removed first modify the value of the field of
Problem a: if, as described above, the type char or varchar data type size inconsistent?
Question 2: modify the value of the field use update statement clearly, but I just create a table, and there is no data in the table, should clear what field?
The command line is as follows:

SQL> The create table course2 (
2 cno char (2) primary key,
3 cname char (14) not null,
4 cpno char (2),
5 ccredit number (1) not null,
Six foreign references course2 (cno)
7);

The table is created,

SQL> Insert into course2 values (' 2 ', 'mathematics',', '2');
Insert into course2 values (' 2 ', 'mathematics',', '2')
*
Line 1 error:
ORA - 00947: there is not enough the value of the


SQL> Insert into course2 values (' 2 ', 'mathematics',' 2 ', '2');
Insert into course2 values (' 2 ', 'mathematics',' 2 ', '2')
*
Line 1 error:
ORA - 00947: there is not enough the value of the


SQL> The alter table course2 alter column sname varchar (14);
The alter table course2 alter column sname varchar (14)
*
Line 1 error:
ORA - 01735: invalid ALTER TABLE options


Thank you for great god reply carefully,



CodePudding user response:

Send the wrong plates, should go to the corresponding plate

CodePudding user response:

Because the problem to clear answer, just in a hurry to register new account... Not too will use...

CodePudding user response:

Add columns
The alter table t add,,,

Modify the column
The alter table t modify,,,

CodePudding user response:

Please see the following reply, and seriously think about their own problems:
 
1. Why use the alter column modify data in the Oracle type error? How to solve?
Modify fields syntax: alter table tablename modify (column datatype [default value] [null/not null],... .);

- 2. The problem a: if, as described above, char types do not match a varchar data type size?
Two char or varchar data type can be compatible, after all the error, because the length of the size, length is in a certain error,

- 3. Question 2: modify the value of the field use update statement clearly, but I just create a table, and there is no data in the table, should clear what field?
- the operation steps are as follows:
- (1) the first backup the original table
The create table course2_bak as select * from course2;

- (2) to empty the table data
Truncate table course2;

- (3) to modify the original table field
The alter table course2 modify column sname varchar2 (14);

- (4) reduction data
Insert into course2 select * from course2_bak;
commit;

- 4. Line 1: an error ORA - 00947: there is not enough the value of the
Course2 table a total of four fields, you didn't give 3 field assignment and must be an error,

CodePudding user response:

Look not to understand text

Behind the question whether code section error ORA - 00947? That's because you do not have enough field values in the values clause input, a total of five fields, you just input the three values, don't say only need three non-null value (primary key + quantity not null field), you must specify the field name in front, and behind in the front row in the values clause of each value and field one-to-one correspondence, this is the correct grammar, of course, the corresponding value should satisfy the constraints on the field, such as:
Insert into course2 (cno, cname, ccredit) values (' 2 ', 'maths', '2');

CodePudding user response:

You six fields into three values are certainly an error, the alter table course2 alter column sname varchar (14) this is the grammar of the MSSQL

CodePudding user response:

When inserting data has an error, because you have a problem to build table results,

You can have a look at the table you create definition, you will find that the magic of a list: "FOREIGN" CHAR (2 BYTE), and so would have been an error: not enough value,

The create table course2 (
Cno char (2) primary key,
Cname char (14) not null,
Cpno char (2),
Ccredit number (1) not null,
foreign references course2 (cno) this to specify what is your foreign key columns, and not just specify to refer to the same table primary key cno column
);

Should be xx column type foreign references course2 (cno)

There can be a comma in the middle
  • Related