对名称中包含数字的表立即执行
execute immediate for tables having number in their names
我的包中有一个立即执行程序,当 v_object_name
类似于 20200823_AGL 时,我收到此错误:
ORA-00903: Invalid table name
我该如何解决?
EXECUTE IMMEDIATE 'SELECT MAX(LAST_UPDATE),COUNT(*) FROM ' || v_object_name || ''
INTO v_max_update_date,
v_count;
来自 Oracle 文档:Schema Object Names and Qualifiers
Nonquoted identifiers must begin with an alphabetic character from your database character set. Quoted identifiers can begin with any character.
EXECUTE IMMEDIATE 'SELECT MAX(LAST_UPDATE),COUNT(*) FROM "' || v_object_name || '"'
INTO v_max_update_date,
v_count;
一个更完整的例子:
declare
v_object_name char(12) := '20200823_AGL';
v_count pls_integer;
begin
execute immediate 'select count(*) from "' || v_object_name || '"'
into v_count;
--
DBMS_OUTPUT.PUT_LINE('v_count = ' || v_count);
end;
此类对象可能是使用双引号创建的。
create view "1_test_view" as select 1 col_name from dual; --> ORA-00999: invalid view name
create view "1_test_view" as select 1 col_name from dual: --> works fine
表格规则相同
在这种情况下,您还需要使用双引号从此类对象中查询
select * from 1_test_view; --> ORA-00903: Invalid table name
select * from "1_test_view"; --> will work fine
我的包中有一个立即执行程序,当 v_object_name
类似于 20200823_AGL 时,我收到此错误:
ORA-00903: Invalid table name
我该如何解决?
EXECUTE IMMEDIATE 'SELECT MAX(LAST_UPDATE),COUNT(*) FROM ' || v_object_name || ''
INTO v_max_update_date,
v_count;
来自 Oracle 文档:Schema Object Names and Qualifiers
Nonquoted identifiers must begin with an alphabetic character from your database character set. Quoted identifiers can begin with any character.
EXECUTE IMMEDIATE 'SELECT MAX(LAST_UPDATE),COUNT(*) FROM "' || v_object_name || '"'
INTO v_max_update_date,
v_count;
一个更完整的例子:
declare
v_object_name char(12) := '20200823_AGL';
v_count pls_integer;
begin
execute immediate 'select count(*) from "' || v_object_name || '"'
into v_count;
--
DBMS_OUTPUT.PUT_LINE('v_count = ' || v_count);
end;
此类对象可能是使用双引号创建的。
create view "1_test_view" as select 1 col_name from dual; --> ORA-00999: invalid view name
create view "1_test_view" as select 1 col_name from dual: --> works fine
表格规则相同
在这种情况下,您还需要使用双引号从此类对象中查询
select * from 1_test_view; --> ORA-00903: Invalid table name
select * from "1_test_view"; --> will work fine