PL/SQL题(带答案),求解说高手 (答案连接)

答案+问题:
CREATE TABLE STUDENT_TEST
(
STUDENT_NAME VARCHAR2(30 BYTE),
STUDENT_SEX NUMBER(2),
STUDENT_AGE NUMBER(3),
CHINESE NUMBER(8),
ENGILSH NUMBER(8),
COMPUTER NUMBER(8),
SALL NUMBER(8),
PAIMING VARCHAR2(30 BYTE),
IF_HEGE VARCHAR2(6 BYTE)
);

create or replace procedure t_student_teat(if_flag out varchar2)
is
vn_student_name varchar2(20);
vn_student_sex number(2);
vn_student_age number(2);
vn_chinese number(3);
vn_enlish number(3);
vn_computer number(3);
vn_all number(3);
vn_paiming number(5);
vn_count number(10);
vn_allcount number(10);
boy number(10) := 0;
girl number(10) := 0;
--vn_if_hege varchar2(20);

cursor c_tt is
select student_name from student_test order by sall desc;
begin

if_flag := '1';

for i in 1 .. 1000 loop
select 'student_name' || lpad(i, 4, '0')
/*1.怎么查询内容带引号?lpad(i, 4, '0')是什么意思?*/
into vn_student_name
from dual;
/*2.此表是哪来的?*/

select trunc(dbms_random.value(17, 20)) into vn_student_age from dual;
/*3.此语句详细解释每个词的意思,与使用方法*/
select trunc(dbms_random.value(1, 151)) into vn_chinese from dual;
select trunc(dbms_random.value(1, 151)) into vn_enlish from dual;
select trunc(dbms_random.value(1, 151)) into vn_computer from dual;
vn_all := vn_chinese + vn_enlish + vn_computer;

vn_student_sex := round(DBMS_RANDOM.VALUE(1, 2));
/*4.等号后边的用法说明*/
if vn_student_sex = 1 then
/*5.if语句如何实现功能简述,boy和girl不用定义?怎么还出现501了*/
girl := girl + 1;
else
boy := boy + 1;
end if;

if boy >= 501 then
vn_student_sex := 1;
elsif girl >= 501 then
vn_student_sex := 2;
end if;
vn_paiming := 1;

insert into student_test
values
(vn_student_name,
vn_student_sex,
vn_student_age,
vn_chinese,
vn_enlish,
vn_computer,
vn_all,
vn_paiming,
'Y');
end loop;
commit;
/*6.往后是啥意思?*/
select count(*) into vn_allcount from student_test;
vn_count := 1;
for rec in c_tt loop
update student_test
set paiming = vn_count
where student_name = rec.student_name;
commit;
if vn_count > vn_allcount * 0.8 then
update student_test
set if_hege = 'N'
where student_name = rec.student_name;
commit;
end if;

vn_count := vn_count + 1;
end loop;
commit;
exception
when others then
dbms_output.put_line(sqlerrm);
if_flag := '0';
rollback;

end t_student_teat;
由于有字数限制,我分2块写题和答案,答案满意者,200分全送上
这是题目连接
http://zhidao.baidu.com/question/241580602.html

麻烦也说下结构体,就是大概的结构。思路

/*1.怎么查询内容带引号?lpad(i, 4, '0')是什么意思?*/
LPAD(i, 4, '0')就是说如果i不够4位,就在左边补0,譬如i为1,则返回0001,如果i为123,返回0123
into vn_student_name
from dual;
/*2.此表是哪来的?*/ dual是oracle里面的一个特殊表,系统自带的,只有一行,用这个来作为from后面的,就只返回一条记录

select trunc(dbms_random.value(17, 20)) into vn_student_age from dual;
/*3.此语句详细解释每个词的意思,与使用方法*/
dbms_random.value(17, 20)返回一个大于等于17,小于20的数字。trunc() 忽略小数点部分,返回整数部分

select trunc(dbms_random.value(1, 151)) into vn_chinese from dual;
select trunc(dbms_random.value(1, 151)) into vn_enlish from dual;
select trunc(dbms_random.value(1, 151)) into vn_computer from dual;
vn_all := vn_chinese + vn_enlish + vn_computer;

vn_student_sex := round(DBMS_RANDOM.VALUE(1, 2));
将产生一个大于等于1,小于2得随机数,round()函数四舍五入取整数
/*4.等号后边的用法说明*/
if vn_student_sex = 1 then
/*5.if语句如何实现功能简述,boy和girl不用定义?怎么还出现501了*/
功能很清晰啊,根据student_sex来给girl, boy数量+1
girl := girl + 1;
else
boy := boy + 1;
end if;

if boy >= 501 then
vn_student_sex := 1;
elsif girl >= 501 then
vn_student_sex := 2;
end if;
vn_paiming := 1;

insert into student_test
values
(vn_student_name,
vn_student_sex,
vn_student_age,
vn_chinese,
vn_enlish,
vn_computer,
vn_all,
vn_paiming,
'Y');
end loop;
commit;
/*6.往后是啥意思?*/
根据curose c_tt来做更新student_tet操作。根据student_test里面的纪录数字判断是否要更新student_test if_hege字段
如果有sql exception发生,就rollback
温馨提示:答案为网友推荐,仅供参考
第1个回答  2011-03-22
1.怎么查询内容带引号?lpad(i, 4, '0')是什么意思?
字符串操作,实现“学生姓名以studet_name0001形式”的要求,lpad(i, 4, '0')是左补'0'
2.此表是哪来的?
dual是系统虚拟表
select trunc((17, 20)) into vn_student_age from dual;
3.此语句详细解释每个词的意思,与使用方法*/
dbms_random.value是使用dbms_random包里面的方法value,目的是取得随机数的。trunc把随4.即守护截取得到整数
round也是oracle函数,
5.if语句如何实现功能简述,boy和girl不用定义?怎么还出现501了
boy和girl前面是有定义的,是number(10)类型,初始化0
6.往后是啥意思?*/
for rec in c_tt loop是for使用c_tt cursor循环更新名次。实现“7) 按照成绩的多少排名字。。分数多的在前面。
8) 排名名次在总人数的前80%的为合格 if_hege插入‘Y’,剩余的为不合格 if_hege 插入‘N’!”两个要求的
第2个回答  2011-04-06
大概思路可百度Hi中给你分析