Home > Database > Oracle > How to delete oracle field

How to delete oracle field

WBOY
Release: 2022-01-26 10:44:10
Original
53210 people have browsed it

In Oracle, you can use the "Alter Table" statement with the "Drop Column" keyword to delete fields. The syntax is "ALTER TABLE table name DROP COLUMN field name".

How to delete oracle field

The operating environment of this tutorial: Windows 10 system, Oracle 11g version, Dell G3 computer.

How to delete oracle fields

Syntax for adding fields: alter table tablename add (column datatype [default value][null/not null],….);

Modify Field syntax: alter table tablename modify (column datatype [default value][null/not null],….);

Delete field syntax: alter table tablename drop (column);

If you add, modify, or delete multiple columns, separate them with commas.

Example of using alter table to add, delete and modify a column.

Create table structure:

create table test1
(id varchar2(20) not null);
Copy after login

Add a field:

alter table test1
add (name varchar2(30) default ‘无名氏’ not null);
Copy after login

Use one SQL statement to add three fields at the same time:

alter table test1
add (name varchar2(30) default ‘无名氏’ not null,
age integer default 22 not null,
has_money number(9,2)
);
Copy after login

Modify a field

alter table test1
modify (name varchar2(16) default ‘unknown’);
Copy after login

Another: The more formal way of writing is:

-- Add/modify columns 
alter table TABLE_NAME rename column FIELD_NAME to NEW_FIELD_NAME;
Copy after login

Delete a field

alter table test1
drop column name;
Copy after login

Recommended tutorial: "Oracle Video Tutorial"

The above is the detailed content of How to delete oracle field. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template