我正在研究一个从表中获取行并稍微更改名称以使总共 50 行的过程......正如您将在代码中看到的那样。
但是,我有一个问题
数字或值错误,您将在我尝试使用的代码中看到
dbms_output.put_line('some message');
但我的输出不想工作,所以发现问题变得很麻烦。
一个错误说
"PL/SQL: numeric or value error"
*Cause: An arithmetic, numeric, string, conversion, or constraint error
occurred. For example, this error occurs if an attempt is made to
assign the value NULL to a variable declared NOT NULL, or if an
attempt is made to assign an integer larger than 99 to a variable
declared NUMBER(2).
*Action: Change the data, how it is manipulated, or how it is declared so
that values do not violate constraints.
如果有人能指出我正确的方向(或什至如何让 dbms 工作),将不胜感激
(我已经打开了 dbms 并连接到服务器并设置了服务器输出;)
代码:
create or replace procedure bbt_phone_users (n in number) authid current_user
as
cursor r10 is select firstname, lastname, password_ from bbt_users_temp;
r10type r10%rowtype;
fn bbt_users_temp.firstname%type;
ln bbt_users_temp.lastname%type;
pass bbt_users_temp.password_%type;
tel varchar2(15);
keymap_ln varchar(4);
phone_end number(4);
name_end number;
begin
phone_end := 1000;
dbms_output.put_line('hey');
for i in 1 .. n
loop
open r10;
fetch r10 into fn, ln, pass;
close r10;
for oneRow in r10
loop
name_end := name_end + 1;
dbms_output.put_line('works pre-1');
--1
-- each row gets the phone_end, which increments on each iteration
phone_end := phone_end + 1;
tel := '(317) 456-' || to_char(phone_end);
dbms_output.put_line('works after 1');
--2
-- takes the last name, and adds 000 and some number if its less than 10 OR
-- adds (concatinates) 00 and the numbers if its > 10
if name_end < 10 then
ln := ln || '000' || to_char(phone_end, '9');
else
ln := ln || '00' || to_char(phone_end, '99');
end if;
dbms_output.put_line('works after 2');
--3
-- calls the KEYMAP function and passes it the lastname
keymap_ln := KEYMAP(ln);
dbms_output.put_line('works after 3');
--4
-- inserts all our values
insert into phone_users values(tel, fn, ln, keymap_ln, pass);
--5
--rest are ignored since we don't do anything with them
end loop;
end loop;
end;
/
call bbt_phone_users(10);
select * from phone_users;