Avatar of Rao_S
Rao_S
 asked on

Can you help me resolve a ORA-01006?

hi, i get a ORA-01006: bind variable does not exist  ..... error with this, from a packaged proc, can you please help me with this...

EXECUTE IMMEDIATE
            'select  oldest_backup_time,newest_backup_time  into :lv_oldest, :lv_newest from '
            || lv_dbname
            || '.'
            || 'rc_backup_set_summary'
            || '@'
            || 'LINK_ABCDEF '
            USING lv_oldest,lv_newest,lv_dbname;
Oracle Database

Avatar of undefined
Last Comment
Rao_S

8/22/2022 - Mon
MikeOM_DBA

Missing colon, here: ...   || lv_dbname
flow01

You are passing 3 variables (using ,,)  and defined 2 in your query :lv.

You can't pass however the databaselink name as a bind variable, so you must include it in the query text.

Try
lv_dbname := ' 'LINK_ABCDEF ';
EXECUTE IMMEDIATE
            'select  oldest_backup_time,newest_backup_time  into :lv_oldest, :lv_newest from '
            || lv_dbname
            || '.'
            || 'rc_backup_set_summary'
            || '@'
            || lv_dbname
            USING lv_oldest,lv_newest;
flow01

Is the schema name same as dblink ?
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
ASKER CERTIFIED SOLUTION
MikeOM_DBA

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Peter Chan

Try
EXECUTE IMMEDIATE
            'select  oldest_backup_time,newest_backup_time  into :lv_oldest, :lv_newest from '
            || lv_dbname
            || '.'
            || 'rc_backup_set_summary'
            || '@'
            || 'LINK_ABCDEF '
            USING lv_oldest,lv_newest;

Open in new window

MikeOM_DBA

1) Your query does not have and conditions and therefore will none of the posted variations will work unless the table has ONE row.

2) In the EXECUTE IMMEDIATE statement, the "USING" part is to supply bind variable values to the query and the "INTO" part is to receive results from the query.

3) Other than variables, in order to supply information that builds the query and which is contained in variables (like schema and/or table name and/or database link. etc...), you must CONCATENATE these variables to the query  text.
Rao_S

ASKER
hi flow, the schema name is not same as the link name, i tried to use the link name as a variable, but your script did not work...
hi mikeom_dba, i tried your scipt, and it worked thank you...
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Rao_S

ASKER
thank you..