这是我的分页存储过程:create or replace package testpackage as
TYPE test_cursor is ref cursor;
end testpackage;
--开始编写分页的过程
create or replace procedure fenye
(tableName in varchar2,
Pagesize in number,--一页显示记录数
pageNow in number,
myrows out number,--总记录数
myPageCount out number,--总页数
p_cursor out testpackage.test_cursor--返回的记录集
) is
--定义部分
--定义sql语句 字符串
v_sql varchar2(1000);
--定义两个整数
v_begin number:=(pageNow-1)*Pagesize+1;
v_end number:=pageNow*Pagesize;
begin
--执行部分
v_sql:='select * from (select t1.*, rownum rn from (select * from '||tableName||')
t1 where
rownum<='||v_end||') where rn>='||v_begin;
--v_sql:='select rownum as columid,t1.* from '||tableName||' t1 where rownum<='||v_end||' and
--rn>='||v_begin||'order by columid asc';
--把游标和sql关联
open p_cursor for v_sql;
--计算myrows和myPageCount
--组织一个sql语句
v_sql:='select count(*) from '||tableName;
--执行sql,并把返回的值,赋给myrows;
execute inmediate v_sql into myrows;
--计算myPageCount
--if myrows%Pagesize=0 then这样写是错的
if mod(myrows,Pagesize)=0 then
myPageCount:=myrows/Pagesize;
else
myPageCount:=myrows/Pagesize+1
end if;
--关闭游标
close p_cursor;
end;
红色部分的语句我使用两个sql语句,都不能通过编译,不知道是这里的问题还是其他问题,错误代码是:
PLS-00103:Encounted the symbol 'CREATE'
TYPE test_cursor is ref cursor;
end testpackage;
--开始编写分页的过程
create or replace procedure fenye
(tableName in varchar2,
Pagesize in number,--一页显示记录数
pageNow in number,
myrows out number,--总记录数
myPageCount out number,--总页数
p_cursor out testpackage.test_cursor--返回的记录集
) is
--定义部分
--定义sql语句 字符串
v_sql varchar2(1000);
--定义两个整数
v_begin number:=(pageNow-1)*Pagesize+1;
v_end number:=pageNow*Pagesize;
begin
--执行部分
v_sql:='select * from (select t1.*, rownum rn from (select * from '||tableName||')
t1 where
rownum<='||v_end||') where rn>='||v_begin;
--v_sql:='select rownum as columid,t1.* from '||tableName||' t1 where rownum<='||v_end||' and
--rn>='||v_begin||'order by columid asc';
--把游标和sql关联
open p_cursor for v_sql;
--计算myrows和myPageCount
--组织一个sql语句
v_sql:='select count(*) from '||tableName;
--执行sql,并把返回的值,赋给myrows;
execute inmediate v_sql into myrows;
--计算myPageCount
--if myrows%Pagesize=0 then这样写是错的
if mod(myrows,Pagesize)=0 then
myPageCount:=myrows/Pagesize;
else
myPageCount:=myrows/Pagesize+1
end if;
--关闭游标
close p_cursor;
end;
红色部分的语句我使用两个sql语句,都不能通过编译,不知道是这里的问题还是其他问题,错误代码是:
PLS-00103:Encounted the symbol 'CREATE'
SQL> create or replace procedure fenye
2 (tableName in varchar2,
3 Pagesize in number,--一页显示记录数
4 pageNow in number,
5 myrows out number,--总记录数
6 myPageCount out number,--总页数
7 p_cursor out testpackage.test_cursor--返回的记录集
8 ) is
9 --定义部分
10 --定义sql语句 字符串
11 v_sql varchar2;
12 --定义两个整数
13 v_begin number:=(pageNow-1)*Pagesize+1;
14 v_end number:=pageNow*Pagesize;
15 begin
16 --执行部分
17 v_sql:='select * from ( rownum rn,select t1.* from '||tableName||' t1)
18 where rn<='||v_end||' and rn>='||v_begin|| ';
19 --把游标和sql关联
20 open p_cursor for v_sql;
21 --计算myrows和myPageCount
22 --组织一个sql语句
23 v_sql:='select count(*) from dual';
24 --执行sql,并把返回的值,赋给myrows;
25 execute immediate v_sql into myrows;
26 --计算myPageCount
27 --if myrows%Pagesize=0 then这样写是错的
28 if mod(myrows,Pagesize)=0 then
29 myPageCount:=myrows/Pagesize;
30 else
31 myPageCount:=myrows/Pagesize+1
32 end if;
33 --关闭游标
34 close p_cursor;
35 end;
36 /Warning: Procedure created with compilation errors.SQL> show errors;
Errors for PROCEDURE FENYE:LINE/COL ERROR
-------- -----------------------------------------------------------------
23/9 PLS-00103: Encountered the symbol "SELECT" when expecting one of
the following:
. ( * @ % & = - + ; < / > at in is mod remainder not rem
<an exponent (**)> <> or != or ~= >= <= <> and or like
between || member SUBMULTISET_
The symbol ";" was substituted for "SELECT" to continue.23/34 PLS-00103: Encountered the symbol ";
--执行sql,并把返回的值,赋给myrows;
execute immediate v_sql i" when expecting one of the following:
. , @ ; for <an identifier>LINE/COL ERROR
-------- -----------------------------------------------------------------
<a double-quoted delimited-identifier> group having intersect
minus order partition start subpartition union where connect
SAMPLE_
另外:我想问一下: 17 v_sql:='select * from ( rownum rn,select t1.* from '||tableName||' t1)
18 where rn<='||v_end||' and rn>='||v_begin|| ';
中的红色部分可不可以去掉?
前后贴出来的代码都不一致,请耐心的再看看自己写出来的SQL,
首先(execute inmediate v_sql into myrows; ),“inmediate ”错了,应该是“immediate”。
第二:(myPageCount:=myrows/Pagesize+1)后面“;”忘记了 你问的那个红色的部分可以去掉,如果你就加一个“’”,那倒错了。
下面2点就是楼上说的
2、execute inmediate v_sql into myrows; immediate书写错误3、myPageCount:=myrows/Pagesize+1 缺;