0% found this document useful (0 votes)
66 views

SQL - Using Checkboxes in An Interactive Report With Primary Key - Stack Overflow

The user is trying to insert a new record for each user selected from a checkbox list in an interactive report. Each new record needs a unique primary key ("User Photo ID"). The provided code is inserting the same primary key value for each record, violating the unique constraint. To fix this, the suggestion is to generate a new primary key value from a sequence for each record inserted in the loop, rather than reusing the same value.

Uploaded by

khalidsn
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
66 views

SQL - Using Checkboxes in An Interactive Report With Primary Key - Stack Overflow

The user is trying to insert a new record for each user selected from a checkbox list in an interactive report. Each new record needs a unique primary key ("User Photo ID"). The provided code is inserting the same primary key value for each record, violating the unique constraint. To fix this, the suggestion is to generate a new primary key value from a sequence for each record inserted in the loop, rather than reusing the same value.

Uploaded by

khalidsn
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

12/10/2018 sql - Using checkboxes in an interactive report with primary key - Stack Overflow

Using checkboxes in an interactive report with Ask Question

primary key

Having a small issue with checkboxes


in an Apex report. I've added them to
the interactive report fine, and
everything works well when one box
is selected and submitted for
updating. However, I cannot select
multiple boxes because I get an error
about not having unique primary keys
(My own constraint which I cannot
break). The following is my current
page process(Slightly edited for
privacy) to update the database:

FOR i in 1..APEX_APPLICATION.G_F01.count
LOOP
INSERT INTO table_name(user_photo_id, created_by, created_on, photo_id, user_id)
values(:P58_USER_PHOTO_ID, :F125_USER_ID,sysdate,:P58_PHOTOS,
apex_application.g_f01(i));
END LOOP;

The item that the primary key is


derived from
(:P58_USER_PHOTO_ID) get's the
primary key from this code chunk:

declare
function get_pk return varchar2
is
begin
for c1 in (select TABLE_USER_PHOTO_SEQ.nextval next_val
from dual)
loop
return c1.next_val;
end loop;
end;
begin
:P58_USER_PHOTO_ID := get_pk;
end;

Is there anything I can change in


either of the two pieces of code so
that regardless of how many items
are selected, they each get their own
unique primary key? Thanks for any
help!

sql oracle-apex

By using our site, you acknowledge thatatyou


asked Feb 27 '12 have read and understand our Cookie Policy, Privacy Policy, and our
16:00
Terms of Service. user1235956

https://stackoverflow.com/questions/9468065/using-checkboxes-in-an-interactive-report-with-primary-key?rq=1 1/3
12/10/2018 sql - Using checkboxes in an interactive report with primary key - Stack Overflow
8 1 3

what are you trying to do here? For


each selected user you insert a record
into table name? Do you want to
assign each inserted record a new
photo id? Just clarify what you try to
do here a bit more. – Tom Feb 27 '12
at 17:27

Users will choose a picture first, to be


associate with each selected user
from a table (Via checkbox). Each
selected user should get a unique
'User Photo ID' for later referencing.
This will be a new INSERT action, not
an update action. Hopefully that's a
little clearer. – user1235956 Feb 27
'12 at 18:48

1 Answer

You can ditch the second code chunk


and just do this:

FOR i in 1..APEX_APPLICATION.G_F01.cou
LOOP
INSERT INTO table_name(user_photo_id
values(TABLE_USER_PHOTO_SEQ.nextval,
apex_application.g_f01(i));
END LOOP;

answered Feb 27 '12 at 17:26


Tony Andrews
107k 17 189 233

It doesn't like that, I get the following


error: ORA-06550: line 5, column 11:
PL/SQL: ORA-02289: sequence does
not exist ORA-06550: line 4, column
4: PL/SQL: SQL Statement ignored
Only thing I changed from your
comment was to change the table
name to match my own. I wouldn't
think that alone would cause that
error? – user1235956 Feb 27 '12 at
18:55

Much of why it goes wrong with what


you try to achieve is probably because
you have a page process which gets
you a pk value and fills in
P58_USER_PHOTO_ID. Afterwards,
you do a loop over selected records,
and for each record you use this item.
Evidently you will run into the key
constraint, since you use the same ID
for each record. The solution is indeed
to fetch a new ID for each inserted
record, which is what Tony has done
here. The sequence.nextval should
work, but you could try to put it in a
var first: v_id :=
By using our site,table_user_photo_seq.nextval;
you acknowledge that you have andread and understand our , , and our
then use v_id in your insert? – Tom
.
Feb 28 '12 at 8:18

https://stackoverflow.com/questions/9468065/using-checkboxes-in-an-interactive-report-with-primary-key?rq=1 2/3
12/10/2018 sql - Using checkboxes in an interactive report with primary key - Stack Overflow

By using our site, you acknowledge that you have read and understand our , , and our
.

https://stackoverflow.com/questions/9468065/using-checkboxes-in-an-interactive-report-with-primary-key?rq=1 3/3

You might also like