立即执行 - ORA-00904: STRING: 无效标识符

execute immediate - ORA-00904: STRING: invalid identifier

我收到错误

ORA-00904: ggCategory: invalid identifier.

如果我 运行 select 正常,它可以正常工作并且 returns 正确的值。有谁知道语法错误在哪里?

execute immediate 'create table TEST_TABLE as (
    select 
        category.name l_category,
        u.*
    from 
        User u
    inner join listtext_view category on u.categoryID=category.ID and category.ident='||'ggCategory'||'
    )';

什么是ggcategory?我认为它是一个变量(或参数);如果是这样,则不应将其括在单引号中,即

execute immediate 'create table TEST_TABLE as (
select 
    category.name l_category,
    u.*
from User u inner join listtext_view category on
          u.categoryID=category.ID and category.ident=' || ggCategory ||')';
                                                           ----------

此外,table name 肯定不是 User 因为它是 Oracle 函数的保留字。

如果 ggCategory 是一个字符串文字,那么:

execute immediate 'create table TEST_TABLE as (
    select 
        category.name l_category,
        u.*
    from 
        User u
    inner join listtext_view category on u.categoryID=category.ID and category.ident=''ggCategory''
    )';

如果它是一个变量那么:

execute immediate 'create table TEST_TABLE as (
    select 
        category.name l_category,
        u.*
    from 
        User u
    inner join listtext_view category on u.categoryID=category.ID and category.ident='||ggCategory||'
    )';

假设,在后一种情况下,它是一个数字或其他不需要引用的东西;或者,如果确实需要引用:

execute immediate 'create table TEST_TABLE as (
    select 
        category.name l_category,
        u.*
    from 
        User u
    inner join listtext_view category on u.categoryID=category.ID and category.ident='''||ggCategory||'''
    )';