0

my proc is:

create or replace PROCEDURE SP_TBL_COMPARE_TEST3(
    SRC_COLS     IN VARCHAR2,
    TGT_COLS     IN VARCHAR2)
IS
  CNT1     NUMBER(5);
  SQL_TEXT2 VARCHAR(4000);

BEGIN
  SQL_TEXT2:= 'select count(*) from (select regexp_substr('||src_cols||','||'[^,]+'||', +1, level) from dual connect by regexp_substr('||src_cols||','||'[^,]+'||', +1, level) is not null )'; 
  EXECUTE IMMEDIATE SQL_TEXT2 into CNT4;
END

I am trying to get the input for the src cols and separating to count them but i am getting invalid identifier error. but the columns are available in the input and it is accurate

Connecting to the database sp_test. ORA-00936: missing expression ORA-06512: at "SP_TEST.SP_TBL_COMPARE_TEST3", line 19 ORA-06512: at line 13 Process exited. Disconnecting from the database sp_test

can anyone tell me what is wrong?

1
  • If you are counting list elements you can simplify: select regexp_count('1,2,3,4', ',')+1 from dual;. Of course make sure the data does not contain the delimiter. Commented Sep 30, 2016 at 13:28

1 Answer 1

1

You are missing some quotes in dynamic SQL; this should work:

create or replace PROCEDURE SP_TBL_COMPARE_TEST3(
    SRC_COLS     IN VARCHAR2,
    TGT_COLS     IN VARCHAR2)
IS
  CNT1     NUMBER(5);
  SQL_TEXT2 VARCHAR(4000);

BEGIN
  SQL_TEXT2:= 'select count(*) from (select regexp_substr('''||src_cols||''','||'''[^,]+'||''', +1, level) from dual connect by regexp_substr('''||src_cols||''','||'''[^,]+'||''', +1, level) is not null )'; 
  dbms_output.put_line(SQL_TEXT2);
  EXECUTE IMMEDIATE SQL_TEXT2 into CNT1;
END;

Besides, notice that you never use the second parameter of your procedure.

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.