以文本方式查看主题
-
曙海教育集团论坛
(http://sun4.cn/bbs/index.asp)
--
Oracle数据库
(http://sun4.cn/bbs/list.asp?boardid=65)
----
Oracle上机试验报告
(http://sun4.cn/bbs/dispbbs.asp?boardid=65&id=2498)
-- 作者:wangxinxin
-- 发布时间:2010-12-11 10:58:44
-- Oracle上机试验报告
以下内容含脚本,或可能导致页面不正常的代码
环境<font face="宋体 ">:</font><font face="Times New="New" Roman="Roman" ">SQLPlus</font><font face="宋体 ">下</font> <table class="t_table" cellspacing="0"> <tbody> <tr> <td width="609"><font size="3">SQL> select * from v$version;</font> <font size="3">BANNER</font> <font size="3">----------------------------------------------------------------</font> <font size="3">Oracle9i Release 9.2.0.1.0 - Production</font> <font size="3">PL/SQL Release 9.2.0.1.0 - Production</font> <font size="3">CORE 9.2.0.1.0 Production</font> <font size="3">TNS for 32-bit Windows: Version 9.2.0.1.0 - Production</font> <font size="3">NLSRTL Version 9.2.0.1.0 - Production</font> </td></tr></tbody></table><font face="Times New="New" Roman="Roman" "></font> <strong><font face="宋体 ">问题一:</font></strong> <strong><font face="宋体 ">问题名称</font></strong><font face="宋体 ">:输入字符</font><font face="Times New="New" Roman="Roman" ">&</font><font face="宋体 ">的问题</font> <strong><font face="宋体 ">问题描述</font></strong><font face="宋体 ">:在</font><font face="Times New="New" Roman="Roman" ">INSERT INTO DEPARTMENT VALUES(\'4\',\'Math & Science\',\'444\');</font><font face="宋体 ">插入该条记录的时候发现</font><font face="Times New="New" Roman="Roman" ">&</font><font face="宋体 ">及后面的字符被忽略掉了,不能正确插入(</font><font face="Times New="New" Roman="Roman" ">department</font><font face="宋体 ">表已建立,且记录符合约束)。</font> <strong><font face="宋体 ">问题分析</font></strong><font face="宋体 ">:在</font><font face="Times New="New" Roman="Roman" ">Oracle9i</font><font face="宋体 ">中</font><font face="Times New="New" Roman="Roman" ">&</font><font face="宋体 ">是有特殊含义的字符,默认状态其功能为指出一个变量,故不能正确插入,若想输入必须禁用此功能或者绕过此功能。</font> <strong><font face="宋体 ">问题<span class="t_tag" onclick="tagshow(event)" href="tag.php?name=%BD%E2%BE%F6">解决</span></font></strong><font face="宋体 ">:经过检索资料以及实验发现有四种方法可以解决该问题。</font> <font face="Times New="New" Roman="Roman" "></font> <strong><font face="宋体 ">解决方法</font><font face="Times New="New" Roman="Roman" ">1</font></strong><font face="宋体 ">:在</font><font face="Times New="New" Roman="Roman" ">SQLPlus</font><font face="宋体 ">中使用</font><font face="Times New="New" Roman="Roman" ">set scan off</font><font face="宋体 ">命令关闭输入检测</font> <table class="t_table" cellspacing="0"> <tbody> <tr> <td width="595"><font size="3"> SQL>set scan off</font> <font size="3">SQL>INSERT INTO DEPARTMENT VALUES(\'4\',\'Math & Science\',\'444\');</font> <font size="3"><font face="宋体 ">已创建</font> 1 <font face="宋体 ">行。</font></font> <font size="3">SQL> select * from department;</font> <font size="3"> </font><font size="3">DEPTID DEPTNAME FACULTYID</font> <font size="3">---------- -------------------- ----------</font> <font size="3"> 4 Math & Science 444</font> </td></tr></tbody></table><font face="Times New="New" Roman="Roman" "> </font> <strong><font face="宋体 ">解决方法</font><font face="Times New="New" Roman="Roman" ">2</font></strong><font face="宋体 ">:在</font><font face="Times New="New" Roman="Roman" ">SQLPlus</font><font face="宋体 ">中利用</font><font face="Times New="New" Roman="Roman" ">set define off</font><font face="宋体 ">命令关闭定义在符号</font><font face="Times New="New" Roman="Roman" ">&</font><font face="宋体 ">上的功能</font> <table class="t_table" cellspacing="0"> <tbody> <tr> <td width="595"><font size="3">SQL> set scan on</font> <font size="3">SQL> truncate table department;</font> <font size="3"><font face="宋体 ">表已截掉。</font></font> <font size="3">SQL> set define off</font> <font size="3">SQL>INSERT INTO DEPARTMENT VALUES(\'4\',\'Math & Science\',\'444\');</font> <font size="3"><font face="宋体 ">已创建</font> 1 <font face="宋体 ">行。</font></font> <font size="3">SQL> select * from department;</font> <font size="3"> </font> <font size="3">DEPTID DEPTNAME FACULTYID</font> <font size="3">---------- -------------------- ----------</font> <font size="3"> 4 Math & Science 444</font> </td></tr></tbody></table><font face="Times New="New" Roman="Roman" "></font> <font face="Times New="New" Roman="Roman" "> </font><strong><font face="宋体 ">解决方法</font><font face="Times New="New" Roman="Roman" ">3</font></strong><font face="宋体 ">:利用变量输入来绕过</font><font face="Times New="New" Roman="Roman" ">&</font><font face="宋体 ">功能</font> <table class="t_table" cellspacing="0"> <tbody> <tr> <td width="595"><font size="3">SQL> set define on</font> <font size="3">SQL> truncate table department;</font> <font size="3"><font face="宋体 ">表已截掉。</font></font> <font size="3">SQL>INSERT INTO DEPARTMENT VALUES(\'4\',&MAJOR,\'444\');</font> <font size="3"><font face="宋体 ">输入</font> major <font face="宋体 ">的值</font>: \'Math & Science\'</font> <font size="3"><font face="宋体 ">原值</font>1: INSERT INTO DEPARTMENT VALUES(\'4\',&MAJOR,\'444\')</font> <font size="3"><font face="宋体 ">新值</font>1: INSERT INTO DEPARTMENT VALUES(\'4\',\'Math & Science\',\'444\')</font> <font size="3"><font face="宋体 ">已创建</font> 1 <font face="宋体 ">行。</font></font> <font size="3">SQL> select * from department;</font><font size="3"> DEPTID DEPTNAME FACULTYID</font> <font size="3">---------- -------------------- ----------</font><font size="3"> 4 Math & Science 444</font> </td></tr></tbody></table><font face="Times New="New" Roman="Roman" "></font> <strong><font face="宋体 ">解决方法</font><font face="Times New="New" Roman="Roman" ">4</font></strong><font face="宋体 ">:用</font><font face="Times New="New" Roman="Roman" ">chr</font><font face="宋体 ">函数来替换</font><font face="Times New="New" Roman="Roman" ">\'&\'</font><font face="宋体 ">字符</font> <table class="t_table" cellspacing="0"> <tbody> <tr> <td width="595"><font size="3">SQL> truncate table department;</font> <font size="3"><font face="宋体 ">表已截掉。</font></font> <font size="3">SQL> select ascii(\'&\') from dual;</font> <font size="3">ASCII(\'&\')</font> <font size="3">----------</font> <font size="3"> 38</font> <p align="left"><font size="3">SQL>INSERT INTO DEPARTMENT VALUES(\'4\',\'Math \'||chr(38)||\' Science\',\'444\');</font> <font size="3"><font face="宋体 ">已创建</font> 1 <font face="宋体 ">行。</font></font> <font size="3">SQL> select * from department;</font><font size="3"> DEPTID DEPTNAME FACULTYID</font> <font size="3">---------- -------------------- ----------</font> <font size="3"> 4 Math & Science 444</font> </td></tr></tbody></table><font face="Times New="New" Roman="Roman" "></font><strong><font face="宋体 ">问题总结</font></strong><font face="宋体 ">:在上述问题的解决方法中方法</font><font face="Times New="New" Roman="Roman" ">1</font><font face="宋体 ">与方法</font><font face="Times New="New" Roman="Roman" ">2</font><font face="宋体 ">属于</font><font face="Times New="New" Roman="Roman" ">SQLPlus</font><font face="宋体 ">命令类型,且只能用于</font><font face="Times New="New" Roman="Roman" ">SQLPlus</font><font face="宋体 ">环境中,通用性不够。方法</font><font face="Times New="New" Roman="Roman" ">3</font><font face="宋体 ">需要人机交互,不适合<span class="t_tag" onclick="tagshow(event)" href="tag.php?name=%CF%B5%CD%B3">系统</span>的大规模的记录。方法</font><font face="Times New="New" Roman="Roman" ">4</font><font face="宋体 ">是函数法,通用性与批处理能力都不错,只是在可读性方面差点。</font> <font face="Times New="New" Roman="Roman" "></font> <font face="Times New="New" Roman="Roman" "></font> <font face="Times New="New" Roman="Roman" "> B06060314</font> <font face="Times New="New" Roman="Roman" "> </font><font face="宋体 ">davelv</font>
说明:
上面显示的是代码内容。您可以先检查过代码没问题,或修改之后再运行.