Click to See Complete Forum and Search --> : pl/sql problem!!
jung1975
03-21-2001, 12:32 PM
DECLARE
2 v_weight NUMBER(3) := 600;
3 v_message VARCHAR2(255) := 'Product 11002';
4 BEGIN
5 /* SUB-BLOCK */
6 DECLARE
7 v_weight NUMBER(3) := 1;
8 v_message VARCHAR2(255) := 'Product 11001';
9 v_new_locn VARCHAR2(50) := 'Europe';
10 BEGIN
11 v_weight := v_weight + 1;
12 v_new_locn := 'Western ' || v_new_locn;
13 END;
14 v_weight := v_weight + 1;
15 v_message := v_message || ' is in stock';
16 v_new_locn := 'Western ' || v_new_locn;
17* END;
18 RA-06550: line 16, column 1:
LS-00201: identifier 'V_NEW_LOCN' must be declared
RA-06550: line 16, column 1:
L/SQL: Statement ignored
Does anybody can tell me what did I wrong?
Thanks!
bensr
03-21-2001, 12:45 PM
Some indenting is always usefull to see what happened,
I don't know the use of it, but declare :
v_weight NUMBER(3) := 1;
v_message VARCHAR2(255) := 'Product 11001';
v_new_locn VARCHAR2(50) := 'Europe';
on a higher level, or in this way:
DECLARE
v_weight NUMBER(3) := 600;
v_message VARCHAR2(255) := 'Product 11002';
BEGIN
/* SUB-BLOCK */
DECLARE
v_weight NUMBER(3) := 1;
v_message VARCHAR2(255) := 'Product 11001';
v_new_locn VARCHAR2(50) := 'Europe';
BEGIN
BEGIN
v_weight := v_weight + 1;
v_new_locn := 'Western ' || v_new_locn;
END;
v_weight := v_weight + 1;
v_message := v_message || ' is in stock';
v_new_locn := 'Western ' || v_new_locn;
END;
END;
/
bensr
03-21-2001, 12:46 PM
Sorry for my remark of indenting,
I noticed, my indents are gone too
Baili
03-21-2001, 10:19 PM
Try to declare v_new_locn in the main block declare section. Sub block variables are not visible in main block. Hope I'm right.
culonbu
03-22-2001, 02:32 AM
the scope of v_new_locn is visible INSIDE SUB-BLOCK, it won't be seen in MAIN BLOCK .
u must declare in in main block
/* MAIN BLOCK */
DECLARE
1 v_new_locn VARCHAR2(50) := 'Europe'; /* <<< MOVE FROM LINE 9 <<< */
2 v_weight NUMBER(3) := 600;
3 v_message VARCHAR2(255) := 'Product 11002';
4 BEGIN
5 ---/* SUB-BLOCK */
6 ---DECLARE
7 -----v_weight NUMBER(3) := 1;
8 -----v_message VARCHAR2(255) := 'Product 11001';
9 ----- /* v_new_locn VARCHAR2(50) := 'Europe'; >>> MOVE TO LINE 1 <<< */
10 -----BEGIN
11 --------v_weight := v_weight + 1;
12 --------v_new_locn := 'Western ' || v_new_locn;
13 -----END; /* SUB-BLOCK */
14 ---v_weight := v_weight + 1;
15 ---v_message := v_message || ' is in stock';
16 ---v_new_locn := 'Western ' || v_new_locn;
17* END; /* MAIN BLOCK */
PSoni
03-26-2001, 07:55 AM
Hi,
I any variabe declared in a block is not visible in its outer block.
Thanks
P. Soni
Originally posted by Baili
Try to declare v_new_locn in the main block declare section. Sub block variables are not visible in main block. Hope I'm right.
You are. Since the inner block in which the variable is declared is closed in line 13, there is no such variable defined in line 16.
Commit;
6502