1

I started a new job and needing to learn Oracle for the job. I am trying to convert this simple code so I can build more complex queries down the road

DECLARE @NPI = VARCHAR(20)

SET @NPI = '123456789'

SELECT *

FROM AFFILIATION

WHERE NPI = @NPI

I am trying to figure out to set parameters in Oracle and then use them in the WHERE statement or other places within the code.

I think I have figured out part of my question but not sure of the full conversion

DECLARE NPI1 varchar(20):= '123456789'

I am looking to set verables/parameters and use them later in the code. YES I dont need it in this query but If i know how to use it for the query I can build much more complex Oracle queries.

1 Answers1

0

Use a bind variable:

VARIABLE npi VARCHAR2(20);

Then use PL/SQL to set its value:

BEGIN
  :npi = '1234567890';
END;
/

or EXEC:

EXEC :npi = '1234567890';

Then you can use it in your query:

SELECT *
FROM   AFFILIATION
WHERE  NPI = :npi
MT0
  • 143,790
  • 11
  • 59
  • 117