简体   繁体   English

Oracle SQL:从替换变量创建一个虚拟表

[英]Oracle SQL: create a dumy table from a substitution variable

In Oracle SQL, I can create a dummy table thanks to the code shown below:在 Oracle SQL 中,由于下面显示的代码,我可以创建一个虚拟表:

select crca.*
from my_real_table real_table, 
     table(ntde.ENCRYPT_ALL(:inputParam)) enc
where
    ...

I would like to be able to do same thing without using ntde.ENCRYPT_ALL , I would like to do something like that:我希望能够在不使用ntde.ENCRYPT_ALL的情况下做同样的事情,我想做这样的事情:

select crca.*
from my_real_table real_table, 
     table(:inputParam) enc
where
    ...

It does not work and I get this error:它不起作用,我收到此错误:

  1. 00000 - "cannot access rows from a non-nested table item" 00000 - “无法访问来自非嵌套表项的行”
    *Cause: attempt to access rows of an item whose type is not known at *原因:尝试访问类型未知的项目的行
    parse time or that is not of a nested table type解析时间或不是嵌套表类型的
    *Action: use CAST to cast the item to a nested table type *操作:使用 CAST 将项目转换为嵌套表类型

Do you know how to do that please?请问你知道怎么做吗?

As the exception says, use CAST :正如例外所说,使用CAST

SELECT c.*
FROM   my_real_table r 
       CROSS JOIN TABLE( CAST(:inputParam AS your_collection_type) ) c

This assumes that:这假设:

  • the bind variable contains an collection (and not a string);绑定变量包含一个集合(而不是字符串); and

  • the bind variable is being passed from an application (this is a Java example );绑定变量是从应用程序传递的(这是一个Java 示例); and

  • you have created an SQL collection type to cast the bind variable to.您已经创建了一个 SQL 集合类型来转换绑定变量。 For example:例如:

     CREATE TYPE your_collection_type AS TABLE OF NUMBER;

    Or, instead of creating your own collection type, you could use a built in collection (or VARRAY ) such as SYS.ODCIVARCHAR2LIST .或者,您可以使用内置集合(或VARRAY ),例如SYS.ODCIVARCHAR2LIST ,而不是创建自己的集合类型。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM