代码之家  ›  专栏  ›  技术社区  ›  David Oneill

从表和函数中选择

  •  0
  • David Oneill  · 技术社区  · 16 年前

    我有一个返回表的函数。返回的表中(除其他内容外)包含一个商店ID。我可以获取特定事务的商店ID和城市ID,如下所示:

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

    我有另一个表,其中包含一个事务列表(其中包括事务\u id和城市\u 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:数据类型不一致”错误。我需要如何构造这个查询?

    (我用的是甲骨文)

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

    当我尝试

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

    权限不足错误。我想这是因为F&U GeT&U商店的用户不同于我正在使用的用户。

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

    1 回复  |  直到 16 年前
        1
  •  2
  •   Dave Costa    16 年前

    我想您需要一个标量子查询:

    select (select store_id from table(user2.f_get_store(city_id, transaction_id))) store_id, city_id, transaction_id
    from table_name;
    
    推荐文章