+ -
当前位置:首页 → 问答吧 → 为什么我写的这个存储过程不能建立啊

为什么我写的这个存储过程不能建立啊

时间:2011-11-14

来源:互联网

create   or   replace   procedure   pd   (cname   in   varchar2(55))
is
age_     int
begin
select   age   into   age_   from   student   where   name=cname;
end;
/

  为什么编译老是通不过啊,

作者: wjwjouwen   发布时间: 2011-11-14

求高人

作者: wjwjouwen   发布时间: 2011-11-14

procedure定义参数的时候不需要指定长度
这样就ok了
SQL code
create   or   replace   procedure   pd   (cname   in   varchar2) 
is 
age_     int 
begin 
select   age   into   age_   from   student   where   name=cname; 
end;

作者: tx2730   发布时间: 2011-11-14

引用楼主 wjwjouwen 的回复:
create or replace procedure pd (cname in varchar2(55))
is
age_ int
begin
select age into age_ from student where name=cname;
end;
/

为什么编译老是通不过啊,

再加上2楼的,另外,age_ int这句后面要有分号。

作者: yixilan   发布时间: 2011-11-14

+1
引用 3 楼 yixilan 的回复:

引用楼主 wjwjouwen 的回复:
create or replace procedure pd (cname in varchar2(55))
is
age_ int
begin
select age into age_ from student where name=cname;
end;
/

为什么编译……

作者: wangjj89621   发布时间: 2011-11-14

谢谢了,已经解决, 但是用declare 调用怎么调用啊??

作者: wjwjouwen   发布时间: 2011-11-14

类似这样的写法来调用就可以了.
当然不止这一种.
SQL code
declare
v_param varchar2(200);--定义变量
begin
v_param:='Printing test!';--给变量赋值
dbms_output.put_line(v_param);--调用存储过程dbms_output.put_line并传入参数
end;

作者: tx2730   发布时间: 2011-11-14

declare
  cname varchar2(55) := ''
begin
  pd(cname);
end;

作者: yixilan   发布时间: 2011-11-14

创建表的代码:
SQL code

CREATE TABLE Student
(
    SID VARCHAR(20),
    Age INT,
    SName   VARCHAR(20)
);



创建存储过程的代码:
SQL code

CREATE OR REPLACE PROCEDURE pd(cname VARCHAR2) IS
age_ INT;
BEGIN
  SELECT  age into age_ from Student where sname=cname;
END pd;



执行存储过程:在SQL*PLus中写一个PL/SQL块
SQL code

DECLARE
    -- 定义变量
    v_param VARCHAR(200);
BEGIN
    --变量赋值并调用存储过程
    v_param := '张三';
    exec pd(v_param);
END;



作者: LuiseRADL   发布时间: 2011-11-14

执行存储过程:
SQL code

DECLARE
    -- 定义变量
    v_param VARCHAR(20) := 'aa';
BEGIN    
    pd(v_param);
END;

作者: LuiseRADL   发布时间: 2011-11-14

楼上的几位兄弟已经讲解的很详细了

作者: 888888888888   发布时间: 2011-11-14

结贴率为0,看不下去了,伤心啊

作者: tx2730   发布时间: 2011-11-14