sql - PLS-00382: expression is of wrong type in Oracle cursor -


i have written cursor in oracle 11g follows:

declare cursor qna_cursor          select activity_id, question, answer          table1         question != 'surveytext'         order activity_id, question;          cur_count       int := 1;         que             nvarchar2(10);         ans             nvarchar2(10);         sqlcommand      nvarchar2(500);         rowcountvar     int;     begin         queans         in qna_cursor         loop             if cur_count = 4 cur_count := 1; end if;   /* have 3 questions each activity_id */             que := 'question' || cur_count;     /* question1, question2, question3 */             ans := 'answer' || cur_count;       /* answer1, answer2, answer3 */              sqlcommand := 'update table2 set '||que||' = :1, '||ans||' = :2 activity_id = :3';             execute immediate sqlcommand using queans.question, queans.answer, queans.activity_id;              cur_count := cur_count + 1;         end loop;     end; 

this schema table1 , table2:

create table table2( activity_id             numeric(19,0), question1               nvarchar2(2000), answer1                 nvarchar2(2000), question2               nvarchar2(2000), answer2                 nvarchar2(2000), question3               nvarchar2(2000), answer3                 nvarchar2(2000) )  create table table1( activity_id             numeric(19,0), question                nvarchar2(2000), answer                  nvarchar2(2000) ) 

when try compile in sqldeveloper, getting following error @ line execute dynamic query 'execute immmediate':

pls-00382: expression of wrong type 

i have played around lot, couldn't figure out reason. data types same corresponding columns in both table. can please tell me can problem?

change datatype of sqlcommand nvarchar2 varchar2. execute immediate expects varchar, varchar2 or char. code given below should work

declare   cursor qna_cursor     select activity_id,            question,            answer       table1      question != 'surveytext'      order activity_id,               question;   cur_count   int := 1;   que         varchar2(10);   ans         varchar2(10);   sqlcommand  varchar2(500); --> should varchar, varchar2 or char   rowcountvar int; begin   queans in qna_cursor loop     if cur_count = 4       cur_count := 1;     end if; /* have 3 questions each activity_id */     que := 'question' || cur_count; /* question1, question2, question3 */     ans := 'answer' || cur_count; /* answer1, answer2, answer3 */     sqlcommand := 'update table2 set ' || que || ' = :1, ' || ans || ' = :2 activity_id = :3';     execute immediate sqlcommand using queans.question, queans.answer, queans.activity_id;     cur_count := cur_count + 1;   end loop; end; / 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -