17,377
社区成员
发帖
与我相关
我的任务
分享
1、创建一个函数
create or replace function fun_count
(score in number)
return number
is
t_score number;
begin
select score into t_score from cj where score=t_score;
return t_score;
exception
when no_data_found then
dbms_output.put_line('no data');
when others then
dbms_output.put_line('error');
end;
2、调用函数
var count number;
exec count:=fun_count(23);
2、调用函数
var count number;
exec :count:=fun_count(23);
SQL>
SQL> create or replace function fun_count
2 (score in number)
3 return number
4 is
5 t_score number;
6 begin
7 select id into t_score from test where NAME='aaaa';
8 return t_score;
9 exception
10 when no_data_found then
11 dbms_output.put_line('no data');
12 when others then
13 dbms_output.put_line('error');
14 end;
15 /
Function created
SQL>
SQL> declare
2 cont number;
3 begin
4 cont := fun_count(23);
5 dbms_output.put_line(cont);
6 end;
7 /
PL/SQL procedure successfully completed
SQL>
SQL> declare
2 count number;
3 begin
4 count := fun_count(23);
5 dbms_output.put_line(count);
6 end;
7 /
dbms_output.put_line(count);
*
第 5 行出现错误:
ORA-06550: 第 5 行, 第 23 列:
PLS-00204: 函数或伪列 'COUNT' 只能在 SQL 语句中使用
ORA-06550: 第 5 行, 第 2 列:
PL/SQL: Statement ignored