???????????
???????????????????????????????????????
????substr( string?? start_position?? [ length ] )
????string????????
????start_position???????λ?????????е????λ??????1
????[ length ]??????????????????????substr???????????????
????????頓
???????
???????substr????????÷???
????????·??
???????????????????λ????????????????????
??????????????
??????????????????????????????ename?е?????????ename1?е???????????ename1?е???γ????????ename?е?????????????????????????ename1????γ???ename????γ?????????ename1???????????char??15?????????????Ч??????????7???????????????????ename1?е??7λ??????????????????ename?п?????????????????char??????????????????????????????в?λ???
?????????
?????????????????????????????????????????????е?????????????????????????????????????????????е????????????????????????????????е????????????????????????γ??????????????????????????ε??????????????????????????????????Ч?????????????????????е??????????substr??????????????
SQL> create table hyl as select * from emp where 1=2;
--????????
Table created
SQL> select * from hyl;
--???????????????????
EMPNO ENAME      JOB         MGR HIREDATE          SAL      COMM DEPTNO
----- ---------- --------- ----- ----------- --------- --------- ------
SQL> alter table hyl add(ename1 char(15));
--???????м????????ename1???????????????
Table altered
SQL> insert into hyl(ename1) select emp.ename as ename1 from emp;
--??emp???ename?????????????ε??????????????????hyl??ename1????????ename1??γ????15
14 rows inserted
SQL> select * from hyl;
--??????ename1?????????
EMPNO ENAME      JOB         MGR HIREDATE          SAL      COMM DEPTNO ENAME1
----- ---------- --------- ----- ----------- --------- --------- ------ ---------------
SMITH
ALLEN
WARD
JONES
MARTIN
BLAKE
CLARK
SCOTT
KING
TURNER
ADAMS
JAMES
FORD
MILLER
14 rows selected
SQL> select count(1) from hyl t where length(t.ename1)=15;
--?????£?ename1????γ???10??????????
COUNT(1)
----------
14
SQL> desc hyl;
--??hyl??????????????ename1???char??15????ename???varchar2??10??
Name     Type         Nullable Default Comments
-------- ------------ -------- ------- --------
EMPNO    NUMBER(4)    Y
ENAME    VARCHAR2(10) Y
JOB      VARCHAR2(9)  Y
MGR      NUMBER(4)    Y
HIREDATE DATE         Y
SAL      NUMBER(7??2)  Y
COMM     NUMBER(7??2)  Y
DEPTNO   NUMBER(2)    Y
ENAME1   CHAR(15)     Y
SQL> update hyl t set t.ename=t.ename1;
--????ename???ename1??????????????????????£????ename??γ????10??С??ename1??γ????15??????????????????
update hyl t set t.ename=t.ename1
ORA-12899: value too large for column "SCOTT"."HYL"."ENAME" (actual: 15?? maximum: 10)
SQL> update hyl t set t.ename=substr(t.ename1??1??7);
--???substr????????????ename1?е??7?????????????μ?ename????
14 rows updated
SQL> select * from hyl;
--??β?hyl???????ename?е????????????????enam1?????????
EMPNO ENAME      JOB         MGR HIREDATE          SAL      COMM DEPTNO ENAME1
----- ---------- --------- ----- ----------- --------- --------- ------ ---------------
SMITH                                                             SMITH
ALLEN                                                             ALLEN
WARD                                                              WARD
JONES                                                             JONES
MARTIN                                                            MARTIN
BLAKE                                                             BLAKE
CLARK                                                             CLARK
SCOTT                                                             SCOTT
KING                                                              KING
TURNER                                                            TURNER
ADAMS                                                             ADAMS
JAMES                                                             JAMES
FORD                                                              FORD
MILLER                                                            MILLER
14 rows selected
SQL> desc hyl;
--??β?hyl???????????????????ename1???????????char??15?????7??????????????????varchar2??10????ename???????
Name     Type         Nullable Default Comments
-------- ------------ -------- ------- --------
EMPNO    NUMBER(4)    Y
ENAME    VARCHAR2(10) Y
JOB      VARCHAR2(9)  Y
MGR      NUMBER(4)    Y
HIREDATE DATE         Y
SAL      NUMBER(7??2)  Y
COMM     NUMBER(7??2)  Y
DEPTNO   NUMBER(2)    Y
ENAME1   CHAR(15)     Y