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!

pl/sql insert if not exists

centerBJun 10 2015 — edited Jun 10 2015

Hi

My oracle version is 11g

I am trying to write a pl/sql where it checks whether the row exists and inserts if not.

if its exists it will return the primary key.

I have a table searchaddress which has column searchaddress_pk,town,street,postcode.

I have attached the package .The procedure works fine when it compares with all the table columns.

i manually inserted 3 rows

searchaddress_pk   town    street            postcode

  1                         london  high street     eh245gh

  2                         london

  3                         london  high street

if i pass all 3 values then it return the primary key 1 fine.

But if i pass 1 or 2 values then its not returning the primary key and inserting each and everytime.

in the procedure if i pass only town value london or town value london and street value high street,its inserting each and everytime.

I expected it to return 2 when i pass london

and 3 when i pass london and high street.

The procedure only works when i pass all 3 values.

as i am new to pl/sql  looking for some help if someone came across same scenario.

Thanks

This post has been answered by John Stegeman on Jun 10 2015
Jump to Answer

Comments

Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Jul 8 2015
Added on Jun 10 2015
8 comments
2,410 views