以下是运行错误
SQL> exec pro_emp;
BEGIN pro_emp; END; *
SQL> exec pro_emp;
BEGIN pro_emp; END; *
解决方案 »
- 创建关键字自动增加的触发器出现问题了,求帮助
- 如何按日统计!!
- oracle for AIX安装报错
- oracle 全量备份报错
- 在线求助Oracle 基础知识
- 关于oracle数据库一次返回多条记录的问题
- Oracle SQL 重名中文 ORA-00911: invalid character
- 为什么我用刚创建的用户不能登录ORAClE呢?望各位帮忙解答一下
- 在同一张表,同一个动作(如 insert after)建立两个不同的行级触发器和表级触发器,请问哪个先执行?
- 求救:哪里能下载oracle8.0.6
- 想问一个比较初级的问题:索引、游标在数据库中到底有什么用啊?
- Easy Question:如何定義一個自增長的字段
如:
create or replace procedure pro_emp
is
t varchar2(10);
begin
select aaa into t from a where rownum =1;
end pro_emp;
/
应该这样写
create or replace procedure cslp
is
v1 number(5);
begin
select student_id into vi from students where studnet_name = "xxy802";
end;
CREATE OR REPLACE PACKAGE PROC_PACKAGE AS
TYPE t_cursor IS REF CURSOR;
END;在
CREATE OR REPLACE PROCEDURE pro_emp (
p_cursor in out proc_package.t_cursor)
is
begin
select * from emp;
end;
SQL> exec pro_emp;
BEGIN pro_emp; END; *
则
set serveroutput on;
create or replace procedure pro_emp
is
t emp%rowtype
begin
select * into t from emp where rownum =1;
dbms_output.put_line(t.aaa||' and '||t.bbb);
end;
/
BEGIN pro_emp; END; *
desc emp;
SQL> desc emp;
柤慜 NULL? 宆
----------------------------------------- -------- ---------------------------
EMPNO NOT NULL NUMBER(4)
ENAME VARCHAR2(10)
JOB VARCHAR2(9)
MGR NUMBER(4)
HIREDATE DATE
SAL NUMBER(7,2)
COMM NUMBER(7,2)
DEPTNO NUMBER(2)
create or replace procedure pro_emp
is
t emp%rowtype
begin
select * into t from emp where rownum =1;
dbms_output.put_line('ename is'||t.ename||' and his job is'||t.job);
end;
/
SQL> exec pro_emp;
BEGIN pro_emp; END; *
我用exec pro_emp 执行提示错误
SQL> exec pro_emp;
BEGIN pro_emp; END; *
在帮我看看,我先谢了!
SQL> connect demo/demo;
已连接。
SQL> desc employee;
名称 空值? 类型
----------------------------------------------------- -------- ---------------
EMPLOYEE_ID NOT NULL NUMBER(4)
LAST_NAME VARCHAR2(15)
FIRST_NAME VARCHAR2(15)
MIDDLE_INITIAL VARCHAR2(1)
JOB_ID NUMBER(3)
MANAGER_ID NUMBER(4)
HIRE_DATE DATE
SALARY NUMBER(7,2)
COMMISSION NUMBER(7,2)
DEPARTMENT_ID NUMBER(2)
SQL> set serveroutput on;
SQL> create or replace procedure pro_emp
2 is
3 t employee%rowtype;
4 begin
5 select * into t from employee where rownum =1;
6 dbms_output.put_line('lase_name is '||t.last_name||' and his job_id is '||t.job_id);
7 end;
8 /过程已创建。SQL> exec pro_emp;
lase_name is SMITH and his job_id is 667PL/SQL 过程已成功完成。SQL>
is
t employee%rowtype;
begin
select last_name into ls_name from employee where rownum =1;
end;
/
declare
t_name varchar2(20);
begin
pro_emp(t_name);
DBMS_OUTPUT.PUT_LINE('name is:'||t_name);
end;
/
这是KingSunSha大哥的一篇测试纪录,供学习参考
测试过程:
1、建立测试表
CREATE TABLE student
(
id NUMBER,
name VARCHAR2(30),
sex VARCHAR2(10),
address VARCHAR2(100),
postcode VARCHAR2(10),
birthday DATE,
photo LONG RAW
)
/ 2、建立带ref cursor定义的包和包体及函数:
CREATE OR REPLACE
package pkg_test as
/* 定义ref cursor类型
不加return类型,为弱类型,允许动态sql查询,
否则为强类型,无法使用动态sql查询;
*/
type myrctype is ref cursor; --函数申明
function get(intID number) return myrctype;
end pkg_test;
/ CREATE OR REPLACE
package body pkg_test as
--函数体
function get(intID number) return myrctype is
rc myrctype; --定义ref cursor变量
sqlstr varchar2(500);
begin
if intID=0 then
--静态测试,直接用select语句直接返回结果
open rc for select id,name,sex,address,postcode,birthday from student;
else
--动态sql赋值,用:w_id来申明该变量从外部获得
sqlstr := 'select id,name,sex,address,postcode,birthday from student where id=:w_id';
--动态测试,用sqlstr字符串返回结果,用using关键词传递参数
open rc for sqlstr using intid;
end if; return rc;
end get; end pkg_test;
/ 3、用pl/sql块进行测试:
declare
w_rc pkg_test.myrctype; --定义ref cursor型变量 --定义临时变量,用于显示结果
w_id student.id%type;
w_name student.name%type;
w_sex student.sex%type;
w_address student.address%type;
w_postcode student.postcode%type;
w_birthday student.birthday%type; begin
--调用函数,获得记录集
w_rc := pkg_test.get(1); --fetch结果并显示
fetch w_rc into w_id,w_name,w_sex,w_address,w_postcode,w_birthday;
dbms_output.put_line(w_name);
end; 4、测试结果:
通过。
我现在只想通过存储过程select不能用package存储过程应该如何写
谢谢!!
我现在只想通过存储过程select不能用package存储过程应该如何写
谢谢!!
只好用临时表了
CREATE GLOBAL TEMPORARY TABLE TMP_EMP AS SELECT * FROM EMP WHERE 1=2;
在存储过程中定义一个游表,通过FOR ..IN..LOOP 循环取出想要的数据行,并放到临时表TMP_EMP中,注意:不能使用COMMIT,不然临时表将自动清空数据。
完成后在外部访问临时表即可