【发布时间】:2017-03-18 04:48:58
【问题描述】:
create or replace procedure address_insert
as
CREATE type colorarray is varray(10) of varchar2(10);
CREATE type cities is varray(6) of varchar2(20);
CREATE type states is varray(6) of varchar2(15);
CREATE type zipcodes is varray(6) of number(10);
CREATE type countries is varray(6) of varchar2(15);
city cities;
Colour colorarray;
zip zipcodes;
state states;
country countries;
id1 number;
x number;
ca number;
r number;
begin
x:=1;
ca:=1;
id1:=1;
r:=1;
city:=cities('Visakhapatnam','Hyderabad','Bangalore','Chennai','Kurnool','secunderabad');
colour :=colorarray('Red', 'Blue', 'green', 'Dark blue', 'yellow', 'orange', 'brown', 'black', 'white', 'purple');
state:=states('Telangana','Tamilnadu','Karnataka','Andhra Pradesh','Madya Pradesh','Kerala');
zip:=zipcodes(530081,500072,316190,981272,717999,621896);
country:=countries('India','Nepal','Pakistan','USA','Bangladesh','UK');
while x<(select count(persons_id) from person_data) loop
if ca>10 then
ca:=1;
end if;
if r>6 then
r:=1;
end if;
insert into persons_addresses(Address_id,Persons_id,flatname,flatno,house_color,contact_person,address_line1,address_line2,address_line3,
city,district,state,zipcode,country) values
(id1,(select persons_id from (select persons_id,row_number()over (order by persons_id) as rn from person_data)tmp where rn=x),
(SELECT dbms_random.string('L', 15) from dual),(SELECT round(dbms_random.value(100,1000)) num FROM dual),colour(ca),
(SELECT dbms_random.string('L', 5)|| ' ' ||dbms_random.string('L', 7) from dual),
(SELECT dbms_random.string('L', 9)|| ' ' ||dbms_random.string('L', 6)|| ' ' ||dbms_random.string('L', 8)|| ' ' ||dbms_random.string('L', 10)
FROM dual),(SELECT dbms_random.string('L', 9)|| ' ' ||dbms_random.string('L', 6)|| ' ' ||
dbms_random.string('L', 8)|| ' ' ||dbms_random.string('L', 10) FROM dual),(SELECT dbms_random.string('L', 9)|| ' ' ||
dbms_random.string('L', 6)|| ' ' ||dbms_random.string('L', 8)|| ' ' ||dbms_random.string('L', 10) FROM dual),city(r),(SELECT dbms_random.string('L', 9) from dual),
state(r),zip(r),country(r));
commit;
id1:=id1+1;
ca:=ca+1;
r:=r+1;
x:=x+1;
end loop;
EXCEPTION -- exception handlers begin
WHEN OTHERS THEN -- handles all other errors
DBMS_OUTPUT.PUT_LINE (SQLCODE|| ' ' || SQLERRM);
end;
有一个编译警告。
警告:执行完成并带有警告过程 address_insert 已编译。
执行时:
execute address_insert
从命令第 1 行开始的错误:执行 address_insert 错误 报告:ORA-06550:第 1 行,第 7 列:PLS-00905:对象 DATAFOCUS_GROUP.ADDRESS_INSERT 无效 ORA-06550:第 1 行,第 7 列: PL/SQL:语句被忽略 06550. 00000 - “第 %s 行,第 %s 列:\n%s” *原因:通常是 PL/SQL 编译错误。 *行动:
有什么方法可以找出编译错误?
SELECT *
FROM USER_ERRORS
WHERE NAME = 'ADDRESS_INSERT'
上述查询有助于检索错误。
错误:
“PLS-00103:在期待其中之一时遇到符号“CREATE” 以下:
begin function pragma procedure subtype type current cursor delete exists 先前的外部语言符号“CREATE”被忽略。 " 由于可变数组定义而遇到上述错误。 有没有其他选择?
其他错误:
“PLS-00103:在期待其中一个时遇到符号“SELECT” 以下:
( - + case mod new not null continue avg count current 存在 max min prior sql stddev sum variance 执行 forall 合并 时间 时间戳 间隔 日期 管道
,来自“
【问题讨论】: