0

我的任务是将一个新的插入transaction_code到一个包含同一个表的 min_cost 和 max_cost 的表中。我要做的是从事务代码为 2 的县获取 min_cost,从事务代码为 4 的县获取 max_cost。这是我到目前为止的情况。

我将收到的错误作为注释写在我收到它们的行旁边。我也尝试将数组用作表格,我认为它不会起作用,但我把它们留在了那里,这样你就会明白我的尝试(它们被注释掉了)。

declare 
    type cost_min_array IS TABLE OF court_cost.cost_range_min%type INDEX BY BINARY_INTEGER;
    type cost_max_array IS TABLE OF court_cost.cost_range_max%type INDEX BY BINARY_INTEGER;
    v_min_cost cost_min_array;
    v_min_cost cost_max_array;
BEGIN
  begin
    select cost_range_min -- SQL STATEMENT IGNORED
    bulk collect into v_min_cost
    from court_cost
    where state = 'IL'
    and transaction_code = 4
    and end_date is null
    order by county
  EXCEPTION WHEN OTHERS THEN --SQL COMMAND NOT PROPERLY ENDED
    v_min_cost.delete;
  END;

  BEGIN
    select cost_range_max -- SQL STATEMENT IGNORED
    bulk collect into v_max_cost
    from court_cost
    where state = 'IL'
    and transaction_code = 2
    and end_date is null
    order by county
  EXCEPTION WHEN OTHERS THEN -- SQL COMMAND NOT PROPERLY ENDED
    v_max_cost.delete;
  END;

  for indx in 1..v_min_cost.count
  loop
    insert into court_cost -- SQL STATEMENT IGNORED
      (TRANSACTION_CODE,
      STATE,
      COUNTY,
      COST_RANGE_MIN,
      BEGIN_DATE,
      END_DATE,
      DATE_INSERTED,
      COURT,
      COST_RANGE_MAX)
    select lcc.TRANSACTION_CODE,
      lcc.STATE,
      lcc.COUNTY,
      v_min_cost(indx),
      lcc.BEGIN_DATE,
      lcc.END_DATE,
      lcc.DATE_INSERTED,
      lcc.COURT,
      v_max_cost(indx)
    from court_cost lcc
--      cost_min_array cmn,
--      cost_max_array cmx
  end loop; -- SQL COMMAND NOT PROPERLY ENDED
end; -- ENCOUNTERED THE SYMBOL ; WHEN EXPECTING LOOP

任何朝着正确方向的推动将不胜感激,谢谢。

4

2 回答 2

1

您在导致错误的代码中错过了三次分号。在代码中,我已经添加了它们,请检查代码现在是否运行。被忽略的语句即将到来,因为它的末尾没有添加分号,甚至在同一语句中也考虑了异常部分,这就是给出错误的原因。

declare 

    type cost_min_array IS TABLE OF court_cost.cost_range_min%type INDEX BY BINARY_INTEGER;
    type cost_max_array IS TABLE OF court_cost.cost_range_max%type INDEX BY BINARY_INTEGER;
    v_min_cost cost_min_array;
    v_min_cost cost_max_array;

BEGIN

  begin

    select cost_range_min -- SQL STATEMENT IGNORED
    bulk collect into v_min_cost
    from court_cost
    where state = 'IL'
    and transaction_code = 4
    and end_date is null
    order by county--semi colon added

  EXCEPTION WHEN OTHERS THEN --SQL COMMAND NOT PROPERLY ENDED
    v_min_cost.delete;

END;


 BEGIN

    select cost_range_max -- SQL STATEMENT IGNORED
    bulk collect into v_max_cost
    from court_cost
    where state = 'IL'
    and transaction_code = 2
    and end_date is null
    order by county--semi colon added
  EXCEPTION WHEN OTHERS THEN -- SQL COMMAND NOT PROPERLY ENDED
    v_max_cost.delete;
  END;

  for indx in 1..v_min_cost.count

  loop

    insert into court_cost -- SQL STATEMENT IGNORED
      (TRANSACTION_CODE,
      STATE,
      COUNTY,
      COST_RANGE_MIN,
      BEGIN_DATE,
      END_DATE,
      DATE_INSERTED,
      COURT,
      COST_RANGE_MAX)
    select lcc.TRANSACTION_CODE,
      lcc.STATE,
      lcc.COUNTY,
      v_min_cost(indx),
      lcc.BEGIN_DATE,
      lcc.END_DATE,
      lcc.DATE_INSERTED,
      lcc.COURT,
      v_max_cost(indx)
    from court_cost lcc;--semi colon added
--      cost_min_array cmn,
--      cost_max_array cmx
  end loop; -- SQL COMMAND NOT PROPERLY ENDED
end; -- ENCOUNTERED THE SYMBOL ; WHEN EXPECTING LOOP
于 2013-07-25T21:05:22.657 回答
0

您的 SQL 语句后缺少分号。尝试

declare 
    type cost_min_array IS TABLE OF court_cost.cost_range_min%type INDEX BY BINARY_INTEGER;
    type cost_max_array IS TABLE OF court_cost.cost_range_max%type INDEX BY BINARY_INTEGER;
    v_min_cost cost_min_array;
    v_min_cost cost_max_array;
BEGIN
  begin
    select cost_range_min -- SQL STATEMENT IGNORED
    bulk collect into v_min_cost
    from court_cost
    where state = 'IL'
    and transaction_code = 4
    and end_date is null
    order by county;  -- semi-colon added
  EXCEPTION WHEN OTHERS THEN --SQL COMMAND NOT PROPERLY ENDED
    v_min_cost.delete;
  END;

  BEGIN
    select cost_range_max -- SQL STATEMENT IGNORED
    bulk collect into v_max_cost
    from court_cost
    where state = 'IL'
    and transaction_code = 2
    and end_date is null
    order by county;  -- semi-colon added
  EXCEPTION WHEN OTHERS THEN -- SQL COMMAND NOT PROPERLY ENDED
    v_max_cost.delete;
  END;

  for indx in 1..v_min_cost.count
  loop
    insert into court_cost -- SQL STATEMENT IGNORED
      (TRANSACTION_CODE,
      STATE,
      COUNTY,
      COST_RANGE_MIN,
      BEGIN_DATE,
      END_DATE,
      DATE_INSERTED,
      COURT,
      COST_RANGE_MAX)
    select lcc.TRANSACTION_CODE,
      lcc.STATE,
      lcc.COUNTY,
      v_min_cost(indx),
      lcc.BEGIN_DATE,
      lcc.END_DATE,
      lcc.DATE_INSERTED,
      lcc.COURT,
      v_max_cost(indx)
    from court_cost lcc;  -- semi-colon added
--      cost_min_array cmn,
--      cost_max_array cmx
  end loop; -- SQL COMMAND NOT PROPERLY ENDED
end; -- ENCOUNTERED THE SYMBOL ; WHEN EXPECTING LOOP

看看这是否会有所改善。

分享和享受。

于 2013-07-25T20:39:31.893 回答