《SQL 21日自学通(V3.0)(PDF格式)》第169章


10 你在使用 LOGIN。SQL 文件时有哪些限制 
它的限制就是你输入到其中的内容必须是 SQL 或 SQL*PLUS 的有效命令 
11 DECODE 函数与过程语言中的 LOOP 功能是等价的 对不对 
不对 它与 IF THEN 类似 
12 如果你将查询重新定向到一个已经存在的文件中 你的输出将追加到这个文件 对不 
对 
不对 新文件将会覆盖原文件的内容 
练习答案 
4 利用在今天开始时的 PRODUCTS 表 写一个查询选择其中的所有数据并对记录的个数 
进行汇总 要生成报表并且不得使用 SET FEEDBACK ON 命令 
pute sum of count(*) on report 
break on report 
565 
…………………………………………………………Page 566……………………………………………………………
SQL 21 日自学通(V1。0) 翻译人 笨猪 
select product_id; product_name; unit_cost; count(*) 
from products 
group by product_id; product_name; unit_cost; 
5 假如今天是 1998 年 5 月 12 日星期一 写一个查询产生下边的输出 
Today is Monday; May 12 1998 
答 
set heading off 
select to_char(sysdate;" 〃Today is 〃Day; Month dd yyyy") 
from dual; 
6 试一下下边的语句 
1 select * 
2 from orders 
3 where customer_id = "001" 
4* order by customer_id; 
不需要在缓冲区中重新输入这些语句 将 FROM 子句中的表改为 CUSTOMERS 
在 ORDER BY 子句中加入 DESC 
l2 
c/orders/customer 
现在你 DESC 加入到 ODRER BY 子句中 
l4 
append DESC 
第 21 天 常见的 SQL 错误及解决方法 
问题答案 
1。 A user calls and says; 〃I can"t sign on to the database。 But everything was working fine 
yesterday。 The error says invalid user/password。 Can you help me?〃 What steps should you take? 
At first you would think to yourself; yeah sure; you just forgot your password。 But this error can 
be returned if a front…end application cannot connect to the database。 However; if you know the 
database is up and functional; just change the password by using the ALTER USER mand and 
tell the user what the new password is。 
2。 Why should tables have storage clauses and a tablespace destination? 
In order for tables not to take the default settings for storage; you must include the storage clause。 
Otherwise medium to large tables will fill up and take extents; causing slower performance。 They 
also may run out of space; causing a halt to your work until the DBA can fix the space problem。 
Exercise Answers 
566 
…………………………………………………………Page 567……………………………………………………………
SQL 21 日自学通(V1。0) 翻译人 笨猪 
1。 Suppose you are logged on to the database as SYSTEM; and you wish to drop a table called 
HISTORY in your schema。 Your regular user ID is JSMITH。 What is the correct syntax to drop 
this table? 
Because you are signed on as SYSTEM; be sure to qualify the table by including the table owner。 
If you do not specify the table owner; you could accidentally drop a table called HISTORY in the 
SYSTEM schema; if it exists。 
SQL》 DROP TABLE JSMITH。HISTORY; 
2。 Correct the following error: 
INPUT: 
SQL》 select sysdate DATE 
2 from dual; 
OUTPUT: 
select sysdate DATE 
* 
ERROR at line 1: 
ORA…00923: FROM keyword not found where expected 
DATE is a reserved word in Oracle SQL。 If you want to name a column heading DATE; then you 
must use double quotation marks: 〃DATE〃。 
3。 一个用户打电话说 “ 我不能登录数据库了 昨天还能呢 你能帮帮我吗 你该如 
何做 
首先 你要问他是否忘记了密码 但是这个错误也可能是因为前端无法联接到数据库 
产生的 如果你可以确认数据据正常 那么你可以更改用户属性 并告诉他新的密码 
4。 为什么表在存储子句中有表空间项 
这是为了可以让表不使用默认的存储空间选项 否则如果表很大时 系统的性能就会 
变慢 也可能会导致运行超时 系统挂死直到 DBA 修正了这个错误 
练习答案 
3。 如果你以 SYSTEM 身份登录了数据库 你想删除你的计划中的一个名字叫HISTORY 
的表 如果你的用户 ID 是 JSMITH 那么正确的语法是怎样的 
因为你是以 SYSTEM 身份登录的 所以要确认表的所有者对表的限制 如果你不是指 
定的表的所有者 你也可以在 SYSTEM 计划中删除了这个表 
4。 更正下边语句的错误 
INPUT: 
SQL》 select sysdate DATE 
567 
…………………………………………………………Page 568……………………………………………………………
SQL 21 日自学通(V1。0) 翻译人 笨猪 
2 from dual; 
OUTPUT: 
select sysdate DATE 
* 
ERROR at line 1: 
ORA…00923: FROM keyword not found where expected 
DATE 是 ORACLE SQL 的保留字 如果你想把列句命名为 DATE 你应该在它的两边 
加上单引号 
568 
………………………………………………………………………用户上传之内容结束……………………………………………………………………………………
小说推荐
返回首页返回目录