ORACLE的存储过程的变量定义问题

Rewiah 2001-12-07 09:37:00
菜鸟就是菜鸟,这样的问题也不知道怎么回事!

ORACLE的存储过程里,变量是怎么定义的?我以下两种写法都报"有语法错误":
1、
create or replace procedure proc_test (
aId in number
)
as
begin
declare lChar varchar2(30);
select Desc into lChar from parts where id=aId;
dbms_output.put_line(lChar);
end;
/

2、
create or replace procedure proc_test (
aId in number
)
as
declare lChar varchar2(30);
begin
select Desc into lChar from parts where id=aId;
dbms_output.put_line(lChar);
end;
/
...全文
2050 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
Rewiah 2001-12-08
  • 打赏
  • 举报
回复
谢谢三千大哥在临走前回答我的问题。
也谢谢 panther_totem(青争岁月),Free_Man(浪迹天涯)。

to:Free_Man(浪迹天涯)
我输错了,应该是Descs.

Free_Man 2001-12-08
  • 打赏
  • 举报
回复
create or replace procedure proc_test( aId in number ) as
lChar varchar2(30);
begin
select Desc into lChar from parts where id=aId;
dbms_output.put_line(lChar);
exception
when others then
dbms_output.put_line( 'Error' );
end;
/

2、
create or replace procedure proc_test( aId in number ) as
lChar varchar2(30);
begin
select Desc into lChar from parts where id=aId;
dbms_output.put_line(lChar);
exception
when others then
dbms_output.put_line( 'Error' );
end;
/

以上三千兄写的很明白,我这里说一下其他的问题.
我想知道你parts的Desc字段是怎么建立的.

panther_totem 2001-12-08
  • 打赏
  • 举报
回复
oracle的内部变量如果是procedure或者function之类的是在as/is 和 begin 之间定义的,
只有在写pl/sql块时是:
declare
变量
begin
主体
exception
错误陷阱
end;
KingSunSha 2001-12-07
  • 打赏
  • 举报
回复
1、create or replace procedure proc_test (
aId in number
)
as
lChar varchar2(30);
begin
select Desc into lChar from parts where id=aId;
dbms_output.put_line(lChar);
end;

2、
create or replace procedure proc_test (
aId in number
)
as
lChar varchar2(30);
begin
select Desc into lChar from parts where id=aId;
dbms_output.put_line(lChar);
end;
KingSunSha 2001-12-07
  • 打赏
  • 举报
回复
1、create or replace procedure proc_test (
aId in number
)
as
lChar varchar2(30);
begin
select Desc into lChar from parts where id=aId;
dbms_output.put_line(lChar);
end;

2、
create or replace procedure proc_test (
aId in number
)
as
lChar varchar2(30);
begin
select Desc into lChar from parts where id=aId;
dbms_output.put_line(lChar);
end;

2,596

社区成员

发帖
与我相关
我的任务
社区描述
Sybase相关技术讨论区
社区管理员
  • Sybase社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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