在包中时,SQL命令会跳过where子句

时间:2019-01-17 23:10:35

标签: oracle plsql

我的plsql代码有问题,如果它在软件包中,它将跳过where子句,并给我错误的结果。我做了一个小测试,您可以运行。需要在SQL Developer中启用DBMS输出并依次运行,一次运行一个命令/块。 Oracle DB是版本12C。

create table tmp_bounding_box  (
  id number,
  x number(14,10),
  y number(14,10)
);

insert into tmp_bounding_box (id,x,y) values(1,0.0,0.0);
insert into tmp_bounding_box (id,x,y) values(1,0.0,4.0);
insert into tmp_bounding_box (id,x,y) values(1,4.0,4.0);
insert into tmp_bounding_box (id,x,y) values(1,4.0,0.0);
insert into tmp_bounding_box (id,x,y) values(2,1.0,1.0);
insert into tmp_bounding_box (id,x,y) values(2,1.0,3.0);
insert into tmp_bounding_box (id,x,y) values(2,3.0,3.0);
insert into tmp_bounding_box (id,x,y) values(2,3.0,1.0);
commit;

declare
    MAX_X number(14,10) := 0;
    MIN_X number(14,10) := 0;
    MAX_Y number(14,10) := 0;
    MIN_Y number(14,10) := 0;
    log_msg varchar2(4000);
begin  
    select max(x), min(x), max(y), min(y) into MAX_X, MIN_X, MAX_Y, MIN_Y 
    from tmp_bounding_box where id in ( 2 );

    log_msg := 'Bounding box: max_x<'||MAX_X||'> min_x<'||MIN_X||'> max_y<'||MAX_Y||'> min_y<'||MIN_Y||'>';
    dbms_output.put_line(log_msg);
end;

create or replace PACKAGE bounding_box_pck as 
    procedure GetBoundingBox( id number );
end bounding_box_pck;

create or replace PACKAGE BODY bounding_box_pck as
    procedure GetBoundingBox( id number ) is 
    MAX_X number(14,10) := 0;
    MIN_X number(14,10) := 0;
    MAX_Y number(14,10) := 0;
    MIN_Y number(14,10) := 0;
    log_msg varchar2(4000);
begin
    select max(x), min(x), max(y), min(y) into MAX_X, MIN_X, MAX_Y, MIN_Y 
    from tmp_bounding_box where id in ( id );

    log_msg := 'Bounding box: max_x<'||MAX_X||'> min_x<'||MIN_X||'> max_y<'||MAX_Y||'> min_y<'||MIN_Y||'>';
    dbms_output.put_line(log_msg);

  end GetBoundingBox;
end bounding_box_pck;

begin
    bounding_box_pck.GetBoundingBox(2);
end;

第一个pl / sql块返回:

Bounding box: max_x<3> min_x<1> max_y<3> min_y<1>

第二个pl / sql块返回:

Bounding box: max_x<4> min_x<0> max_y<4> min_y<0>

我一直试图找出原因,但没有结果。

1 个答案:

答案 0 :(得分:7)

第二步

test

此查询在where子句中单独比较id列。它没有使用您的变量。考虑将您的变量名称更改为v_id

self. myCity = items[indexPath]