我在这里遇到简单的PL / SQL问题。我将表格定义如下:
TYPE tr_GatheredData IS RECORD(
BS_ID number,
CUSTOMER_NAME varchar2(200),
MONTH varchar2(30),
YEAR number,
LEAKAGE number);
TYPE tt_GatheredData IS TABLE OF tr_GatheredData;
然后,我尝试启动一个像这样的变量:
results := tt_GatheredData(1, 'lol', 'omg', 2, 3);
一切对我来说都是正确的,但我明白了
错误(8,16):PLS-00306:调用“ TT_GATHEREDDATA”时参数的数量或类型错误
每次赞美。你们能告诉我问题在哪里吗?
答案 0 :(得分:1)
Oracle 18c qualified expression:
DECLARE
TYPE tr_GatheredData IS RECORD(
BS_ID number,
CUSTOMER_NAME varchar2(200),
MONTH varchar2(30),
YEAR number,
LEAKAGE number);
TYPE tt_GatheredData IS TABLE OF tr_GatheredData;
results tt_GatheredData;
BEGIN
results := tt_GatheredData(tr_GatheredData(1, 'lol', 'omg', 2, 3));
DBMS_OUTPUT.PUT_LINE(results(1).Customer_name);
END;
//
以前的版本:
DECLARE
TYPE tr_GatheredData IS RECORD(
BS_ID number,
CUSTOMER_NAME varchar2(200),
MONTH varchar2(30),
YEAR number,
LEAKAGE number);
TYPE tt_GatheredData IS TABLE OF tr_GatheredData;
results tt_GatheredData;
t tr_GatheredData ;
BEGIN
t.BS_ID := 1;
t.CUSTOMER_NAME := 'lol';
t.MONTH := 'omg';
t.YEAR := 2;
t.LEAKAGE := 3;
results := tt_GatheredData(t); -- element has to be record type
DBMS_OUTPUT.PUT_LINE(results(1).Customer_name);
END;
//
答案 1 :(得分:1)
//Get the date
System.DateTime a = System.DateTime.Now;
//Converts it to string
string b = a.ToString("yyyy-MM-dd HH:mm:ss");
System.Console.WriteLine(b);
//Convert to Byte Array
byte[] c = System.Text.Encoding.ASCII.GetBytes(b);
//Convert every byte as hex and join it
string d = "";
foreach (byte e in c)
d += string.Format("{0:x2}", e);
//Show the result
System.Console.WriteLine(d);
是tt_GatheredData
条记录的集合,因此您需要传递一组记录,而不是tr_GatheredData
。
正如Lukasz的回答所述,Oracle 18c之前的PL / SQL记录类型只是简单的多值变量,因此,如果您想要方便的构造函数,则必须编写自己的构造函数,否则声明每个(1, 'lol', 'omg', 2, 3)
记录并明确为其分配值。
集合类型的确包含隐式构造函数,或者您可以一次显式分配一个元素。
这是一种使用独立(18c之前的版本)记录构造函数来一次创建包含多个元素的集合的方法:
tr_GatheredData
输出:
declare
type tr_GatheredData is record
( bs_id number
, customer_name varchar2(200)
, month varchar2(30)
, year number
, leakage number );
type tt_GatheredData is table of tr_GatheredData;
results tt_GatheredData;
function new_gathereddata
( p_bs_id number
, p_customer_name varchar2
, p_month varchar2
, p_year number
, p_leakage number )
return tr_GatheredData
is
r tr_GatheredData;
begin
r.bs_id := p_bs_id;
r.customer_name := p_customer_name;
r.month := p_month;
r.year := p_year;
r.leakage := p_leakage;
return r;
end new_gathereddata;
begin
results :=
tt_GatheredData
( new_gathereddata(1, 'aaa', 'January', 1066, 10)
, new_gathereddata(2, 'bbb', 'February', 1588, 15)
, new_gathereddata(3, 'ccc', 'March', 1789, 20) );
dbms_output.put_line('Collection contains ' || results.count || ' records.');
dbms_output.put_line('results(3).year = ' || results(3).year);
end;