Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Simple stored procedure - select with an if statement, returning a cursor

987522Sep 3 2013 — edited Sep 3 2013

Hi,

I'm trying to create a very simple stored procedure, but having never worked with them before I'm not quite sure what I'm doing wrong.

Here's my code:

create or replace

procedure contact_return(

    v_contact_id IN varchar2,

    p_cursor OUT SYS_REFCURSOR)

AS

begin

  set sql_statement varchar2(4000) := '

    SELECT URN,

      FIRSTNAME,

      LASTNAME,

      TITLE,

      CREATED_DT,

      AREA_URN,

      MOBILE,

      WORK,

      EMAIL,

      ORG_NAME,

      ADDRESS,

      POSTCODE,

      IN_USE

    FROM CONTACT';

   

  if v_contact_id is not null then

    sql_statement := sql_statement || ' where urn = ' || v_contact_id;

  end if;

 

  open p_cursor for sql_statement;

end;

It's actually returning 2 errors:

  • Error(7,3): PL/SQL: SQL Statement ignored
  • Error(7,7): PL/SQL: ORA-00922: missing or invalid option

Which seem to be a problem with my set sql_statement line, but it looks correct to me?

Thanks

This post has been answered by BluShadow on Sep 3 2013
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 1 2013
Added on Sep 3 2013
6 comments
1,021 views