我正在使用Oracle的异构服务(HS)。我有一个名为employee
的Microsoft Access表的数据库链接。在使用SQL * Plus的Oracle连接中,我可以描述表的列和数据类型(desc employee
)。我也可以从远程表中选择并接收记录。
但是,使用匿名块时,我收到Oracle错误:
ORA-02070: database MSAccessODBC64 does not support TO_NUMBER in this context
MSAccessODBC64
是我在Windows 7中配置的ODBC DSN。
declare
my_record_position number := 60109;
my_record employee@MSAccessODBC64bit%rowtype;
begin
select
*
into
my_record
from
eemployee@MSAccessODBC64bit ---->> When I remove the database link, it works
where
staff_number = my_record_position ---->> when I remove the where clause, it works
order by
staff_number asc;
dbms_output.put_line(my_record.staff_number);
end;
/
declare
*
ERROR at line 1:
ORA-02070: database MSAccessODBC64 does not support TO_NUMBER in this context
ORA-06512: at line 5
HS是否需要某种问题或选项?我在俯瞰什么?
当我使用替换变量时,它会起作用并显示employee
id
。
define emp = 60109;
declare
my_record_position number := 60109;
my_record employee@MSAccessODBC64bit%rowtype;
begin
select
*
into
my_record
from
employee@MSAccessODBC64bit
where
staff_number = &emp
order by
staff_number asc;
dbms_output.put_line('emp=' || my_record.staff_number);
end;
/
emp=60109
PL/SQL procedure successfully completed.
===========initMSAccessODBC64bit.ora for ODBC==============
# This is a sample agent init file that contains the HS parameters that are
# needed for the Database Gateway for ODBC
#
# HS init parameters
#
HS_DESCRIBE_CACHE_HWM = 4000
HS_FDS_CONNECT_INFO = MSAccessODBC64bit
HS_FDS_TRACE_LEVEL = DEBUG
HS_OPEN_CURSORS = 50
HS_RPC_FETCH_REBLOCKING = ON
HS_RPC_FETCH_SIZE = 10000
HS_FDS_FETCH_ROWS = 100
HS_TRANSACTION_MODEL = READ_ONLY
#This was supposed to fix ORA-02070: database MSAccessODBC64bit does not
#support TO_number in this context
#This didn't work
#EnableWCharSupport = 0
答案 0 :(得分:1)
解决!根据可执行的游标sql语句,HS和ODBC Oracle服务的范围和用法受到限制。解决方法是使用虚拟DBMS_HS_PASSTHROUGH包。这将允许您使用pl / sql变量和绑定变量向远程数据库提交查询。以下示例是上述代码的替代。
declare
v_cursor BINARY_INTEGER;
my_record_position number := 1234;
my_record employees@MSAccessODBC64bit%rowtype;
my_empid employees.empid@MSAccessODBC64bit%type;
begin
v_cursor := DBMS_HS_PASSTHROUGH.open_cursor@MSAccessODBC64bit;
DBMS_HS_PASSTHROUGH.parse@MSAccessODBC64bit
(
v_cursor,
'select * from employee where empid = ' || my_record_position
|| 'order by empid asc'
);
WHILE DBMS_HS_PASSTHROUGH.fetch_row@MSAccessODBC64bit(v_cursor) > 0
LOOP
DBMS_HS_PASSTHROUGH.get_value@MSAccessODBC64bit(v_cursor, 1,my_record.empid);
dbms_output.put_line('empid=' || my_record.empid);
end loop;
end;
/
答案 1 :(得分:0)
错误表明此比较 -
staff_number = my_record_position
- 正在比较不同的数据类型,这会导致查询DBMS自动尝试将其中一个或两个转换为可能进行比较的数据类型。例如,您无法直接将CHAR
与NUMBER
进行比较;一个必须CAST
到另一个 - TO_NUMBER
建议正在发生。
TO_NUMBER
是特定于Oracle的函数,Access不支持。您可以通过在查询中添加几个CAST
来解决此问题,例如: -
CAST (staff_number AS INT) = CAST (my_record_position AS INT)
如果其中一个已经是INT
,则会增加一些不必要的开销,但这对您的使用可能无关紧要。