I'm trying to write a procedure to do an insert.
The first one works fine.
1 create or replace procedure change_id_no(p_oldidno in varchar2, p_newidno in varchar2)
2 as
3 begin
4 insert into company_details (id_no, registration_no)
5 values
6 (p_newidno, (select registration_no from company_details where id_no = 'p_oldidno'));
7 end change_id_no;
SQL> /
Procedure created.
But when I try this (ie, when I have more than one value in the select stmt), it tends to fail.
CAn you tell me what's wrong with this statement and how should I be writing it?
1 create or replace procedure change_id_no(p_oldidno in varchar2, p_newidno in varchar2)
2 as
3 begin
4 insert into company_details (id_no, registration_no, company_name)
5 values
6 (p_newidno, (select registration_no, company_name from company_details where id_no = 'p_oldidno'));
7 end change_id_no;
SQL> /
Warning: Procedure created with compilation errors.
SQL> sho errors
Errors for PROCEDURE CHANGE_ID_NO:
basically what I trying to do is give new id values for existing ones.
Is there anything wrong if I try to update the primary key?
id_no is the primary key in this table.
can I give
update company_details set id_no='newid' where id_no='oldid';
is it right to do so or does this have any impact?
thanks a lot
jmodic
02-20-2003, 11:15 AM
Originally posted by thomasp
1 create or replace procedure change_id_no(p_oldidno in varchar2, p_newidno in varchar2)
2 as
3 begin
4 insert into company_details (id_no, registration_no, company_name)
5 values
6 (p_newidno, (select registration_no, company_name from company_details where id_no = 'p_oldidno'));
7 end change_id_no;
SQL> /
Warning: Procedure created with compilation errors.
SQL> sho errors
Errors for PROCEDURE CHANGE_ID_NO:
You can't list more than one column/expression in a select statement of the VALUES clause - it's not PL/SQL's restriction, it is SQL's restriction.
However I don't understand why you are using such a complicated form of an insert statement at all. You should change your second procedure to something like this:
create or replace procedure change_id_no(p_oldidno in varchar2, p_newidno in varchar2)
as
begin
insert into company_details (id_no, registration_no, company_name)
select p_newidno, registration_no, company_name
from company_details where id_no = p_oldidno;
end change_id_no;
thomasp
02-20-2003, 11:36 AM
thanks jmodic, but I'm still getting an error saying missing left parenthesis.
what do you think about the update stmt? will that work???
thanks a lot
jmodic
02-20-2003, 11:44 AM
Originally posted by thomasp
...
PRIORITY, COMPANY_ADDRESS_STREET_2, LOCKED_TIME, FSA_AC_NO)
VALUES
SELECT p_newidno, REGISTRATION_NO, SORT_CODE, COUNTRY_CODE,
...
Remove the line "VALUES", ie change the above to: