Skip to Main Content

Breadcrumb

Question and Answer

Connor McDonald

Thanks for the question, Sam.

Asked: May 27, 2016 - 6:51 am UTC

Last updated: May 28, 2016 - 11:08 am UTC

Version: Oracle 11g

Viewed 10K+ times! This question is

You Asked

I am trying to perform this but getting error.
create or replace procedure sync_multiple_new as
poi_userid number(10);
phone varchar2(1000);
source_cpcid number(10);
rec_id number(10);
CURSOR abc IS select subject_id,
SUBJECT_NAME,
SUBJECT_IMAGE,
SUBJECT_ADDRESS,
SUBJECT_PERSONALEMAIL,
SUBJECT_PERSONALPHONENUMBER,
subject_gender,
ID,
USERNAME,
PASS,
USER_ID,
LAST_LOGIN,
TYPE,
SOURCE_TYPE,
STATUS,
DSTATUS,
PHMODEL,
DEVICESNO,
PHONENO from users;
begin
for rec in abc
loop
if rec.subject_id is null then
          
          insert into user(NAME,GENDER,IMAGE) values (rec.subject_name,rec.subject_gender,rec.subject_image);
          
elseif (rec.id is null) Then
            
            insert into user(NAME,GENDER,IMAGE,source) values (rec.subject_name,rec.subject_gender,rec.subject_image);
           
end if;

end loop;
end;

Error: PLS-00103: Encountered the symbol "THEN" when expecting one of the following: := . ( % ;
Error: PLS-00103: Encountered the symbol "IF" when expecting one of the following: ; <an identifier> <a double-quoted delimited-identifier> current delete exists prior <a single-quoted SQL string>


and Connor said...

Change ELSEIF to ELSIF

SQL> declare
  2
  3  CURSOR abc IS select * from all_Objects;
  4  begin
  5  for rec in abc
  6  loop
  7    if rec.object_id is null then
  8            null;
  9    elseif rec.owner is null then
 10            null;
 11    end if;
 12
 13  end loop;
 14  end;
 15  /
  elseif rec.owner is null then
         *
ERROR at line 9:
ORA-06550: line 9, column 10:
PLS-00103: Encountered the symbol "REC" when expecting one of the following:
:= . ( @ % ;
The symbol ":=" was substituted for "REC" to continue.
ORA-06550: line 9, column 28:
PLS-00103: Encountered the symbol "THEN" when expecting one of the following:
; and or
The symbol "; was inserted before "THEN" to continue.


SQL>
SQL>
SQL>
SQL>
SQL> declare
  2
  3  CURSOR abc IS select * from all_Objects;
  4  begin
  5  for rec in abc
  6  loop
  7    if rec.object_id is null then
  8            null;
  9    elsif rec.owner is null then
 10            null;
 11    end if;
 12
 13  end loop;
 14  end;
 15  /

PL/SQL procedure successfully completed.


Rating

  (2 ratings)

Is this answer out of date? If it is, please let us know via a Comment

Comments

To Sam

Rajeshwaran, Jeyabal, May 27, 2016 - 12:41 pm UTC

Turn that up into a bulk process, above Cursor FOR loop may change like this.

insert first
 when subject_id is null then 
  into user(name,gender,image)
   values(subject_name,subject_gender,subject_image)
 when id is null then 
  into user(name,gender,image,source)
   values(rec.subject_name,rec.subject_gender,subject_image,
     subject_source)
select subject_id,subject_name,subject_image,subject_address,
subject_personalemail,subject_personalphonenumber,subject_gender,
id,username,pass,user_id,last_login,type,source_type,status,
dstatus,phmodel,devicesno,phoneno 
from users; 

Reviewer suggestion

Ghassan, May 28, 2016 - 6:11 am UTC

...rather turn this with one insert. ..
Insert into mytable (..)
Select. .case when.. ....


Connor McDonald
May 28, 2016 - 11:08 am UTC

Indeed.

More to Explore

PL/SQL demos

Check out more PL/SQL tutorials on our LiveSQL tool.

PL/SQL docs

PL/SQL reference manual from the Oracle documentation library