【问题标题】:oracle - Select from tables into object variableoracle - 从表中选择对象变量
【发布时间】:2013-12-05 19:19:52
【问题描述】:

假设我有这个对象类型:

create or replace
TYPE                   "InvestorInfoObject" AS OBJECT 
  ( 
  "InvestorAccount" Varchar2(15 Char), 
  "InvestorSeqNo" NUMBER(15,0), 
  "FirstName" VARCHAR2(50 CHAR) , 
   );

我需要一个函数来从不同的表中选择一些值并返回一个“InvestorInfoObject”。像这样:

create or replace
FUNCTION          "GetInvestorInfo" 
(
  Par_InvestorAccount "Pos"."InvestorAccount"%Type
)
Return "InvestorInfoObject" As 
  investorObj "InvestorInfoObject";
Begin


    Select 
      "InvestorInfoObject"(InvAccounts."InvestorAccount",InvAccounts."InvestorSeqNo",Individuals."FirstName") 
      into investorObj 
      From "InvestorAccounts" InvAccounts 
      Inner Join "Individuals" Individuals 
          On InvAccounts."InvestorSeqNo"=Individuals."Seq"
      Where "InvestorAccount"=Par_Investoraccount;


  RETURN Investorobj;
END "GetInvestorInfo";

但这会导致错误“错误(17,5):PL/SQL:SQL 语句被忽略”。这样做的正确语法是什么?

【问题讨论】:

  • 请不要使用区分大小写的双引号标识符:)
  • @beherenow,不要对双引号标识符如此苛刻。我摆脱了它们,仍然出现错误。我想我的语法有问题。
  • 原来我放错了括号! PL/SQL 编译器消息让人想起汇编中的旧时编码!
  • @sjjafari 我从来没有说过你的问题是由标识符引起的
  • 之所以不使用区分大小写的标识符,与错误无关,而是为了方便。 使用它们要容易得多……没有必要这样做,而且你犯错的可能性也大大降低了。

标签: sql oracle object plsql user-defined-types


【解决方案1】:

如果您要返回一个以上的值,可以使用 collection this 来完成

可以使用

声明

type student_mark 是整数的 varray(10);

x 学生标记;

function double_marks(x student_mark) 返回

student_mark 是

y student_mark;

开始

y := x;

for i 在 1..x.count 循环中

y(i) := 2*y(i);

结束循环;

返回 y;

结束;

开始

x := student_mark(156, 206, 360);

dbms_output.put_line(double_marks(x)(1));

dbms_output.put_line(double_marks(x)(2));

dbms_output.put_line(double_marks(x)(3));

结束;

在这里你也可以使用 object 而不是 varray 。一旦我执行了,我会回复你的

您提供的代码

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-26
    • 2020-07-30
    • 1970-01-01
    • 2022-01-27
    • 1970-01-01
    • 2018-04-21
    相关资源
    最近更新 更多