从表和函数中选择

发布于 2024-08-29 03:05:20 字数 814 浏览 7 评论 0原文

我有一个返回表的函数。返回的表包含(除其他外)一个 store_id。我可以获取特定 transaction_id 和 city_id 的 store_id,如下所示:

select store_id from table(user2.f_get_store(15, 12345)); 
--where 15 and 12345 are city_id and transation_id

我有另一个包含交易列表的表(其中包括 transaction_id 和 city_id)。 查询

store_id, city_id, transaction_id

我想要一个返回事务表中每个条目的 。我的第一个猜测是:(

select user2.f_get_store(city_id, transaction_id), city_id, transaction_id
from table_name;

简化了不重要的细节)

但是,这会产生“ORA-00932:不一致的数据类型”错误。我需要如何构建这个查询?

(我正在使用 Oracle)

~~~~~~编辑~~~~~~

当我尝试时

select user2.f_get_store(city_id, transactioN_id) from table_name;

,我收到权限不足的错误。我认为这是因为 f_get_store 的所有者与我正在使用的用户不同。

(我编辑了示例代码以显示该函数由不同用户拥有)

I have a function that returns a table. The returned table contains (among other things) a store_id. I can get the store_id for a particular transaction_id and city_id as follows:

select store_id from table(user2.f_get_store(15, 12345)); 
--where 15 and 12345 are city_id and transation_id

I have another table that contains a list of transactions (which includes transaction_id and city_id). I want a query that returns

store_id, city_id, transaction_id

for every entry in the transaction table. My first guess was:

select user2.f_get_store(city_id, transaction_id), city_id, transaction_id
from table_name;

(simplified away the unimportant details)

However, this yields an "ORA-00932: inconsistent datatypes" error. How do I need to structure this query?

(I'm using Oracle)

~~~~~EDIT~~~~~

When I try

select user2.f_get_store(city_id, transactioN_id) from table_name;

I get insufficient privileges error. I presume this is because f_get_store is owned by a different user than the one I am using.

(I edited the example code to show the function being owned by a different user)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

零崎曲识 2024-09-05 03:05:20

我认为你想要一个标量子查询:

select (select store_id from table(user2.f_get_store(city_id, transaction_id))) store_id, city_id, transaction_id
from table_name;

I think you want a scalar subquery:

select (select store_id from table(user2.f_get_store(city_id, transaction_id))) store_id, city_id, transaction_id
from table_name;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文