一个朋友在国外找工作的面试题目,关系生存问题,请各位大侠救一命

wewelive 2007-04-23 03:45:50
The following are the questions
Please try to answer following PL/SQL, SQL and database question,
*) Can we declare a column having number data type and its scale is
larger than pricesion
ex: column_name NUMBER(10,100), column_name NUMBAER(10,-84) ?
*) Explain the usage of WHERE CURRENT OF clause in cursors ?
*) What is Overloading of procedures ?
*) What is Pragma EXECPTION_INIT ? Explain the usage ?
*) What are the return values of functions SQLCODE and SQLERRM ?
*) Is it possible to use Transaction control Statements such a
ROLLBACK or COMMIT in Database Trigger ? Why ?
*) How we can create a table in PL/SQL block. insert records into
it??? is it possible by some procedure or function?? please give
example...
*) What are advantages for Stored Procedures?
*) PL/SQL benchmark and profile:
Two piece of PL/SQL blocks, finish the same task, can you tell which
one is better and why?
Please benchmark it on 9i and 10g both, and list the benchmark detail figures.
1.1:
ORA920> begin
2 for i in 1 .. 5000
3 loop
4 for x in ( select ename, empno, hiredate from emp )
5 loop
6 null;
7 end loop;
8 end loop;
9 end;
10 /
PL/SQL procedure successfully completed.
1.2
ORA920> declare
2 l_ename dbms_sql.varchar2_table;
3 l_empno dbms_sql.number_table;
4 l_hiredate dbms_sql.date_table;
5 begin
6 for i in 1 .. 5000
7 loop
8 select ename, empno, hiredate
9 bulk collect into l_ename, l_empno, l_hiredate
10 from emp;
11 end loop;
12 end;
13 /
PL/SQL procedure successfully completed.
...全文
617 27 打赏 收藏 转发到动态 举报
写回复
用AI写文章
27 条回复
切换为时间正序
请发表友善的回复…
发表回复
xiaoxiao1984 2007-04-26
  • 打赏
  • 举报
回复
嗯,支持bobfang(匆匆过客)
说的粉具体的说
bobfang 2007-04-26
  • 打赏
  • 举报
回复
SQL> l
1 declare ii number(8,-10);
2 begin
3 ii := 999999999000000000;
4 dbms_output.put_line(ii);
5* end;
SQL> /
declare ii number(8,-10);
*
ERROR 位于第 1 行:
ORA-06502: PL/SQL: numeric or value error: number precision too large
ORA-06512: at line 3


SQL> 3
3* ii := 999999999000000000;
SQL> c/999999999000000000/999999994000000000
3* ii := 999999994000000000;
SQL> /
999999990000000000

PL/SQL 过程已成功完成。

SQL> 3
3* ii := 999999994000000000;
SQL> c/999999994000000000/-999999994000000000;
3* ii := -999999994000000000;
SQL> /
-999999990000000000

PL/SQL 过程已成功完成。

SQL> 3
3* ii := -999999994000000000;
SQL> c/-999999994000000000/4000000000/
3* ii := 4000000000;
SQL> /
0

PL/SQL 过程已成功完成。

SQL>
bobfang 2007-04-26
  • 打赏
  • 举报
回复
SQL> l
1 declare ii number(8,10);
2 begin
3 ii := 0.00999999999;
4 dbms_output.put_line(ii);
5* end;
SQL> /
declare ii number(8,10);
*
ERROR 位于第 1 行:
ORA-06502: PL/SQL: numeric or value error: number precision too large
ORA-06512: at line 3


SQL> 3
3* ii := 0.00999999999;
SQL> c/0.00999999999/0.00999999991
3* ii := 0.00999999991;
SQL> /
.0099999999

PL/SQL 过程已成功完成。

SQL> 3
3* ii := 0.00999999991;
SQL> c/0.00999999991/0.00000000001
3* ii := 0.00000000001;
SQL> /
0

PL/SQL 过程已成功完成。

bobfang 2007-04-26
  • 打赏
  • 举报
回复
更正,NUMBER(8,-10)和number(8,10)都是可以的。NUMBER(8,-10)表示存的数据的绝对值大于等于1E10,小于1E19,而number(8,10)表示数据的绝对值大于等于1E-10,小于1E-2。
baojianjun 2007-04-26
  • 打赏
  • 举报
回复
如xiaoxiao1984(笨猫儿)所说number(x,y)中的y值由-84到127如果仅仅从程序的一般可执行性上说你的定义的NUMBER类型的字段中的 Y不超过这个范围都是可以的,但是如果要考虑字段的实际用意就是有问题的
还是 bobfang(匆匆过客) 的理解比较深刻:)发现自己不懂的东西越来越多了
baojianjun 2007-04-26
  • 打赏
  • 举报
回复
对于超出精度的NUMBER定义如NUMBER(10,100)你只能够存储0值或空值:)

一般意义上将number(x,y)中的有要小于X才有实际意义,但是如果只是讨论程序上的可执行性,那就没有关系了是可以定义的
bobfang 2007-04-26
  • 打赏
  • 举报
回复
column_name NUMBER(10,-84)那种情况语法上是不出错,但没任何意义,因为存进去的总是0。
SQL> l
1 declare ii number(8,-2);
2 begin
3 ii := -34567.89;
4 dbms_output.put_line(ii);
5* end;
SQL> /
-34600

PL/SQL 过程已成功完成。

SQL> 1
1* declare ii number(8,-2);
SQL> c/-2/-10
1* declare ii number(8,-10);
SQL> /
0

PL/SQL 过程已成功完成。

SQL> 1
1* declare ii number(8,-10);
SQL> c/-10/10
1* declare ii number(8,10);
SQL> /
declare ii number(8,10);
*
ERROR 位于第 1 行:
ORA-06502: PL/SQL: numeric or value error: number precision too large
ORA-06512: at line 3


SQL>
xiaoxiao1984 2007-04-26
  • 打赏
  • 举报
回复
to baojianjun(包子) :
db2inst2@HASL>declare
2 is_num number(10,11);
3 begin
4 is_num := 0.00000000001;
5 end;
6 /

PL/SQL 过程已成功完成。

number(10, 11)也是对的阿,哪里不对啦
xiaoxiao1984 2007-04-26
  • 打赏
  • 举报
回复
to

db2inst2@HASL>declare
2 is_num number(10,100);
3 begin
4 is_num := 0;
5 end;
6 /

PL/SQL 过程已成功完成。
number(p, s) p 1到38;s -84到127

number(10, 100)为啥不对阿

baojianjun 2007-04-25
  • 打赏
  • 举报
回复
Can we declare a column having number data type and its scale is
larger than pricesion

这个和NUMBER的精度限制有关系,number(10,100)这样的是错误的,而number(10,-84)是可以的
for example :
SQL> declare
2 is_num number(10,100);
3 begin
4 is_num := 1;
5 end;
6 /

declare
is_num number(10,100);
begin
is_num := 1;
end;

ORA-06502: PL/SQL: 数字或值错误 : 数值精度太高
ORA-06512: 在line 4

SQL>
SQL> declare
2 is_num number(10,-84);
3 begin
4 is_num := 1;
5 end;
6 /

PL/SQL procedure successfully completed

Executed in 0 seconds

SQL>
SQL> declare
2 is_num number(10,11);
3 begin
4 is_num := 1;
5 end;
6 /

declare
is_num number(10,11);
begin
is_num := 1;
end;

ORA-06502: PL/SQL: 数字或值错误 : 数值精度太高
ORA-06512: 在line 4

Study_Now 2007-04-25
  • 打赏
  • 举报
回复
学习一下
xiaoxiao1984 2007-04-25
  • 打赏
  • 举报
回复
*) Can we declare a column having number data type and its scale is
larger than pricesion
ex: column_name NUMBER(10,100), column_name NUMBAER(10,-84)

是可以的,number(6,4)或者number(6,7)也是正确的,只不过数据精度不是123.456这样的而已

*) How we can create a table in PL/SQL block. insert records into
it??? is it possible by some procedure or function?? please give
example..

当然可以在PL/SQL块中创建表和插入数据:
SQL>begin
2 execute immediate 'create table ttt(id number)' ;
3 execute immediate 'insert into ttt values(1)' ;
4 end;
5 /

PL/SQL 过程已成功完成。

SQL>select *from ttt;

ID
----------
1

同样可以在存储过程中做这两件事情,但是不可以在自定义函数中做这两件事情
liuyuw 2007-04-25
  • 打赏
  • 举报
回复
不结贴?
baggio785 2007-04-24
  • 打赏
  • 举报
回复
最后一题,我认为是第一种快,因为循环变量只做一次求值,而第二种明显要操作数据库5000次
baggio785 2007-04-24
  • 打赏
  • 举报
回复
*) How we can create a table in PL/SQL block. insert records into
it??? is it possible by some procedure or function?? please give
example...

直接在pl/sql中是不允许执行ddl语句的,但是可以通过动态sql语句来执行
baggio785 2007-04-24
  • 打赏
  • 举报
回复
*) Can we declare a column having number data type and its scale is
larger than pricesion
ex: column_name NUMBER(10,100), column_name NUMBAER(10,-84) ?

answer:一般情况刻度范围要小于精度的,否则会报错。例如:
declare
v_num number(6,3);
begin
v_num := 123.456;
end;

是正确的,

declare
v_num number(6,-9);
begin
v_num := 123.456;
end;

也是正确的

declare
v_num number(6,4);或者v_num number(6,7);
begin
v_num := 123.456;
end;
d
都是错误的

liuyuw 2007-04-23
  • 打赏
  • 举报
回复
最后一题,我觉得应该是后面一种快,没有试过。
因为bulk collect提供了对数据的快速检索,比一般的for循环肯定要快。

答完了,希望大牛们更正、补充:)
wewelive 2007-04-23
  • 打赏
  • 举报
回复
多谢多谢liuyuw
liuyuw 2007-04-23
  • 打赏
  • 举报
回复
第8题:Stored Procedures的优点很明显,就是提高开发效率,方便维护、调试等等。另外我看到说Stored Procedures的另外一个优点是降低网络负担,不知道是不是真的-_-
liuyuw 2007-04-23
  • 打赏
  • 举报
回复
第7题,在plsql里面是不支持DDL的,所以不能建表,但看他问题的提法又感觉能有其他的办法建表,但我不知道,呵呵
加载更多回复(7)

17,134

社区成员

发帖
与我相关
我的任务
社区描述
Oracle开发相关技术讨论
社区管理员
  • 开发
  • Lucifer三思而后行
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧