使用 ALTER TABLE 语句追加, 修改, 或删除列的语法
1 SQL> desc testtable; 2 Name Type Nullable Default Comments 3 -------- ------------ -------- ------- -------- 4 EMPNO NUMBER(4) Y 5 ENAME VARCHAR2(10) Y 6 JOB VARCHAR2(9) Y 7 MGR NUMBER(4) Y 8 HIREDATE DATE Y 9 SAL NUMBER(7,2) Y 10 COMM NUMBER(7,2) Y 11 DEPTNO NUMBER(2) Y 12 13 SQL>--增加列 14 SQL> alter table testtable 15 2 add photo blob 16 3 ; 17 Table altered 18 19 SQL> desc testtable; 20 Name Type Nullable Default Comments 21 -------- ------------ -------- ------- -------- 22 EMPNO NUMBER(4) Y 23 ENAME VARCHAR2(10) Y 24 JOB VARCHAR2(9) Y 25 MGR NUMBER(4) Y 26 HIREDATE DATE Y 27 SAL NUMBER(7,2) Y 28 COMM NUMBER(7,2) Y 29 DEPTNO NUMBER(2) Y 30 PHOTO BLOB Y 31 32 SQL>--修改列类型 33 SQL> alter table testtable 34 2 modify deptno number(3); 35 Table altered 36 37 SQL> desc testtable; 38 Name Type Nullable Default Comments 39 -------- ------------ -------- ------- -------- 40 EMPNO NUMBER(4) Y 41 ENAME VARCHAR2(10) Y 42 JOB VARCHAR2(9) Y 43 MGR NUMBER(4) Y 44 HIREDATE DATE Y 45 SAL NUMBER(7,2) Y 46 COMM NUMBER(7,2) Y 47 DEPTNO NUMBER(3) Y 48 PHOTO BLOB Y 49 50 SQL>--删除列 51 SQL> alter table testtable 52 2 drop column photo; 53 Table altered 54 55 SQL> desc testtable; 56 Name Type Nullable Default Comments 57 -------- ------------ -------- ------- -------- 58 EMPNO NUMBER(4) Y 59 ENAME VARCHAR2(10) Y 60 JOB VARCHAR2(9) Y 61 MGR NUMBER(4) Y 62 HIREDATE DATE Y 63 SAL NUMBER(7,2) Y 64 COMM NUMBER(7,2) Y 65 DEPTNO NUMBER(3) Y 66 67 SQL>--修改列名 68 SQL> alter table testtable 69 2 rename column 70 3 deptno to dno; 71 Table altered 72 73 SQL> desc testtable; 74 Name Type Nullable Default Comments 75 -------- ------------ -------- ------- -------- 76 EMPNO NUMBER(4) Y 77 ENAME VARCHAR2(10) Y 78 JOB VARCHAR2(9) Y 79 MGR NUMBER(4) Y 80 HIREDATE DATE Y 81 SAL NUMBER(7,2) Y 82 COMM NUMBER(7,2) Y 83 DNO NUMBER(3) Y
时间: 2024-11-08 21:01:28