savepoint

<!-- [if gte mso 9]><xml><w:WordDocument><w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel><w:DisplayHorizontalDrawingGridEvery>0</w:DisplayHorizontalDrawingGridEvery><w:DisplayVerticalDrawingGridEvery>2</w:DisplayVerticalDrawingGridEvery><w:DocumentKind>DocumentNotSpecified</w:DocumentKind><w:DrawingGridVerticalSpacing>7.8</w:DrawingGridVerticalSpacing><w:View>Normal</w:View><w:Compatibility></w:Compatibility><w:Zoom>0</w:Zoom></w:WordDocument></xml><![endif]-->

ConnectedtoOracleDatabase10gEnterpriseEditionRelease10.2.0.1.0

Connectedasscott

--输出 0 9 9 个数字

SQL>setserveroutputon

SQL>begin

2dbms_output.enable;

3forctrin0..9loop

4dbms_output.put(ctr||'');

5endloop;

6dbms_output.put_line('loopexited');

7end;

8/

0123456789loopexited

PL/SQLproceduresuccessfullycompleted

--循环打印 ASCII

SQL>setserveroutputonsize10240

SQL>declare

2inumber;

3jnumber;

4knumber;

5begin

6foriin2..15loop

7forjin1..16loop

8k:=i*16+j;

9dbms_output.put((to_char(k,'000'))||':'||chr(k)||'');

10ifkmod8=0then

11dbms_output.put_line('');

12endif;

13endloop;

14endloop;

15end;

16/

033:!034:"035:#036:$037:%038:&039:'040:(

041:)042:*043:+044:,045:-046:.047:/048:0

049:1050:2051:3052:4053:5054:6055:7056:8

057:9058::059:;060:<061:=062:>063:?064:@

065:A066:B067:C068:D069:E070:F071:G072:H

073:I074:J075:K076:L077:M078:N079:O080:P

081:Q082:R083:S084:T085:U086:V087:W088:X

089:Y090:Z091:[092:/093:]094:^095:_096:`

097:a098:b099:c100:d101:e102:f103:g104:h

105:i106:j107:k108:l109:m110:n111:o112:p

113:q114:r115:s116:t117:u118:v119:w120:x

121:y122:z123:{124:|125:}126:~127:128:€

129:130:131:132:133:134:135:136:

137:138:139:140:141:142:143:144:

145:146:147:148:149:150:151:152:

153:154:155:156:157:158:159:160:

161:162:163:164:165:166:167:168:

169:170:171:172:173:174:175:176:

177:178:179:180:181:182:183:184:

185:186:187:188:189:190:191:192:

193:194:195:196:197:198:199:200:

201:202:203:204:205:206:207:208:

209:210:211:212:213:214:215:216:

217:218:219:220:221:222:223:224:

225:226:227:228:229:230:231:232:

233:234:235:236:237:238:239:240:

241:242:243:244:245:246:247:248:

249:250:251:252:253:254:255:256:

PL/SQLproceduresuccessfullycompleted

SQL>select*fromemp;

EMPNOENAMEJOBMGRHIREDATESALCOMMDEPTNO

----------------------------------------------------------------

7369SMITHCLERK79021980-12-17800.0020

7499ALLENSALESMAN76981981-2-201600.00300.0030

7521WARDSALESMAN76981981-2-221250.00500.0030

7566JONESMANAGER78391981-4-22975.0020

7654MARTINSALESMAN76981981-9-281250.001400.0030

7698BLAKEMANAGER78391981-5-12850.0030

7782CLARKMANAGER78391981-6-92450.0010

7788SCOTTANALYST75661987-4-193000.0020

7839KINGPRESIDENT1981-11-175000.0010

7844TURNERSALESMAN76981981-9-81500.000.0030

7876ADAMSCLERK77881987-5-231100.0020

7900JAMESCLERK76981981-12-3950.0030

7902FORDANALYST75661981-12-33000.0020

7934MILLERCLERK77821982-1-231300.0010

14rowsselected

ConnectedtoOracleDatabase10gEnterpriseEditionRelease10.2.0.1.0

Connectedasscott

SQL>select*fromemp;

EMPNOENAMEJOBMGRHIREDATESALCOMMDEPTNO

----------------------------------------------------------------

7369SMITHCLERK79021980-12-17800.0020

7499ALLENSALESMAN76981981-2-201600.00300.0030

7521WARDSALESMAN76981981-2-221250.00500.0030

7566JONESMANAGER78391981-4-22975.0020

7654MARTINSALESMAN76981981-9-281250.001400.0030

7698BLAKEMANAGER78391981-5-12850.0030

7782CLARKMANAGER78391981-6-92450.0010

7788SCOTTANALYST75661987-4-193000.0020

7839KINGPRESIDENT1981-11-175000.0010

7844TURNERSALESMAN76981981-9-81500.000.0030

7876ADAMSCLERK77881987-5-231100.0020

7900JAMESCLERK76981981-12-3950.0030

7902FORDANALYST75661981-12-33000.0020

7934MILLERCLERK77821982-1-231300.0010

14rowsselected

--显示表结构

SQL>descemp;

NameTypeNullableDefaultComments

-------------------------------------------

EMPNONUMBER(4)

ENAMEVARCHAR2(10)Y

JOBVARCHAR2(9)Y

MGRNUMBER(4)Y

HIREDATEDATEY

SALNUMBER(7,2)Y

COMMNUMBER(7,2)Y

DEPTNONUMBER(2)Y

SQL>createtablekkk(idnumber(4),namevarchar2(10),deptnumber(5));

Tablecreated

SQL>select*fromkkk;

IDNAMEDEPT

---------------------

--批量导入数据

SQL>insertintokkk(id,name,dept)selectempno,ename,deptnofromempwheredeptno=10;

3rowsinserted

SQL>select*fromkkk;

IDNAMEDEPT

---------------------

7782CLARK10

7839KING10

7934MILLER10

SQL>droptablekkk;

Tabledropped

SQL>select*fromkkk;

select*fromkkk

ORA-00942:表或视图不存在

SQL>select*fromempwhereename='SCOTT';

EMPNOENAMEJOBMGRHIREDATESALCOMMDEPTNO

----------------------------------------------------------------

7788SCOTTANALYST75661987-4-193000.0020

SQL>updateempset(job

2;

updateempset(job

ORA-00907:缺失右括号

SQL>updateempset(job,sal,comm)=(selectjob,sal,commfromempwhereename='SMITH')whereename='SCOTT';

1rowupdated

SQL>rollback;

Rollbackcomplete

SQL>select*fromemp;

EMPNOENAMEJOBMGRHIREDATESALCOMMDEPTNO

----------------------------------------------------------------

7369SMITHCLERK79021980-12-17800.0020

7499ALLENSALESMAN76981981-2-201600.00300.0030

7521WARDSALESMAN76981981-2-221250.00500.0030

7566JONESMANAGER78391981-4-22975.0020

7654MARTINSALESMAN76981981-9-281250.001400.0030

7698BLAKEMANAGER78391981-5-12850.0030

7782CLARKMANAGER78391981-6-92450.0010

7788SCOTTANALYST75661987-4-193000.0020

7839KINGPRESIDENT1981-11-175000.0010

7844TURNERSALESMAN76981981-9-81500.000.0030

7876ADAMSCLERK77881987-5-231100.0020

7900JAMESCLERK76981981-12-3950.0030

7902FORDANALYST75661981-12-33000.0020

7934MILLERCLERK77821982-1-231300.0010

14rowsselected

SQL>commit;

Commitcomplete

SQL>savepointa;

Savepointcreated

SQL>deletefromemp;

14rowsdeleted

SQL>rollbacka;

rollbacka

ORA-02181:无效的ROLLBACWORK选项

--全部回滚

SQL>rollback;

Rollbackcomplete

SQL>select*fromemp;

EMPNOENAMEJOBMGRHIREDATESALCOMMDEPTNO

----------------------------------------------------------------

7369SMITHCLERK79021980-12-17800.0020

7499ALLENSALESMAN76981981-2-201600.00300.0030

7521WARDSALESMAN76981981-2-221250.00500.0030

7566JONESMANAGER78391981-4-22975.0020

7654MARTINSALESMAN76981981-9-281250.001400.0030

7698BLAKEMANAGER78391981-5-12850.0030

7782CLARKMANAGER78391981-6-92450.0010

7788SCOTTANALYST75661987-4-193000.0020

7839KINGPRESIDENT1981-11-175000.0010

7844TURNERSALESMAN76981981-9-81500.000.0030

7876ADAMSCLERK77881987-5-231100.0020

7900JAMESCLERK76981981-12-3950.0030

7902FORDANALYST75661981-12-33000.0020

7934MILLERCLERK77821982-1-231300.0010

14rowsselected

--创建保存点

SQL>savepointa;

Savepointcreated

SQL>delect*fromempwhereename='SMITH';

delect*fromempwhereename='SMITH'

ORA-00900:无效SQL语句

SQL>delete*fromempwhereename='SMITH';

delete*fromempwhereename='SMITH'

ORA-00903:表名无效

SQL>deletefromempwhereename='SMITH';

1rowdeleted

SQL>select*fromempwhereename='SMITH';

EMPNOENAMEJOBMGRHIREDATESALCOMMDEPTNO

----------------------------------------------------------------

SQL>selectcount(*)fromemp;

COUNT(*)

----------

13

--回滚到保存带你 a

SQL>rollbacktoa;

Rollbackcomplete

SQL>select*fromempwhereename='SMITH';

EMPNOENAMEJOBMGRHIREDATESALCOMMDEPTNO

----------------------------------------------------------------

7369SMITHCLERK79021980-12-17800.0020

--the end--

你可能感兴趣的:(SavePoint)