3

I'm new to Oracle and having an issue deleting a value from an array. What I'm trying to: If I've got an array with 1, 2, 3, 4 I want to remove 2 once the database has dealt with this array value and then move onto 3.

The code I'm using is:

type test_rec is record (temp_id number,
      pos1 number,
      pos2 number,
      pos3 number);

type test_array is table of test_rec index by binary_integer;

PROCEDURE pr_test (
parv_test IN test_array)
AS
BEGIN
FOR i in parv_test.first .. parv_test.last LOOP
    IF parv_test(i).action_type = 'I' THEN
        INSERT STATEMENT

        parv_test.delete(i);
    END IF;
END LOOP;
END pr_test ;

However, I get the error:

PLS-00363: expression 'parv_test' cannot be used as an assignment target

Can someone tell me where I'm going wrong?

Thanks a lot.

Cheers

Alex

3
  • Try changing the parameter definition: parv_test IN OUT test_array Commented Feb 22, 2017 at 11:40
  • 1
    copy parv_test to local parameter, you can not modify input parameter Commented Feb 22, 2017 at 11:44
  • Thanks both, that worked great. All sorted now Commented Feb 22, 2017 at 12:05

1 Answer 1

3

You can not modify input parameter,

Try like this,

create or replace package body test_pkg is

   type test_rec is record(temp_id number,
                                 pos1 number,
                                 pos2 number,
                                 pos3 number,
                                 action_type varchar2(1));

   type test_array is table of test_rec index by binary_integer;

   PROCEDURE pr_test(parv_test IN test_array) AS parv_test_local test_array;
BEGIN
  parv_test_local := parv_test;
  FOR i in parv_test_local.first .. parv_test_local.last LOOP
    IF parv_test_local(i).action_type = 'I' THEN
      --INSERT STATEMENT

      parv_test_local.delete(i);
    END IF;
  END LOOP;
END pr_test;

begin
null;
end test_pkg;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.