Home » SQL & PL/SQL » SQL & PL/SQL » SP2-0552 Bind variable not declared ERROR
SP2-0552 Bind variable not declared ERROR [message #213894] |
Fri, 12 January 2007 12:54  |
oraclenub2006
Messages: 56 Registered: December 2006 Location: new york
|
Member |
|
|
I need help urgently. Please!!!!
SET SERVEROUTPUT ON;
ACCEPT nTaxNum varchar2(19) Prompt 'Please Enter Tax Map Number: '
DECLARE
TaxNum varchar2(19);
exec :TaxNum := '&nTaxNum'
select substr(x, 1, 4)
||'-'||substr(x,5,3)
||'.'||substr(x,8,2)
||'-'||substr(x,10,2)
||'.'||substr(x,12,2)
||'-'||substr(x,14,3)
||'.'||substr(x,17) -- code never get here
from (select mtl.tax_number x from tax_table)
where :TaxNum = mtl.taxnumber
-- call function to qry database after conversion
-- for loop to get records
/
I am getting this:
SQL> /
Enter value for ntaxmapnum: 0600108000300010001
old 5: exec :TaxNum := '&nTaxNum'
new 5: exec :TaxNum := '0600108000300010001'
SP2-0552: Bind variable "TAXNUM" not declared.
|
|
|
|
Re: SP2-0552 Bind variable not declared ERROR [message #213907 is a reply to message #213898] |
Fri, 12 January 2007 13:56   |
oraclenub2006
Messages: 56 Registered: December 2006 Location: new york
|
Member |
|
|
Sorry for the mismatch I am new at this bear w/ me here:
I did look at your link. Quite helpfull! I came up w/ this:
CREATE OR REPLACE FUNCTION PadTaxNum (u_string IN VARCHAR2) -- usr string
RETURN VARCHAR2
IS
ntaxnum VARCHAR2(25)
:= '&ntaxnum'
substr(x, 1, 4)
||'-'||substr(x,5,3)
||'.'||substr(x,8,2)
||'-'||substr(x,10,2)
||'.'||substr(x,12,2)
||'-'||substr(x,14,3)
||'.'||substr(x,17) x
BEGIN
-- my main qry
RETURN
END;
/
I get a warning: function created w/ compilation errors.
Any idea will be greatly appreciated. Thks!
|
|
|
|
|
Re: SP2-0552 Bind variable not declared ERROR [message #213917 is a reply to message #213911] |
Fri, 12 January 2007 14:27   |
 |
Littlefoot
Messages: 21825 Registered: June 2005 Location: Croatia, Europe
|
Senior Member Account Moderator |
|
|
I admit, I didn't figure out what would be the result of this function, but here it is - it compiles and, actually, returns something. See if you can use it.SQL> CREATE OR REPLACE FUNCTION PadTaxNum (x IN VARCHAR2) -- usr string
2 RETURN VARCHAR2
3 IS
4 BEGIN
5 RETURN
6 SUBSTR(x, 1, 4)
7 ||'-'||SUBSTR(x,5,3)
8 ||'.'||SUBSTR(x,8,2)
9 ||'-'||SUBSTR(x,10,2)
10 ||'.'||SUBSTR(x,12,2)
11 ||'-'||SUBSTR(x,14,3)
12 ||'.'||SUBSTR(x,17);
13 END;
14 /
Function created.
SQL> SELECT padtaxnum('My name is Littlefoot') FROM dual;
PADTAXNUM('MYNAMEISLITTLEFOOT')
---------------------------------------------------------------------------
My n-ame. i-s .Li-ttl.efoot
SQL>
|
|
|
|
|
|
Re: SP2-0552 Bind variable not declared ERROR [message #214489 is a reply to message #213926] |
Tue, 16 January 2007 13:26   |
oraclenub2006
Messages: 56 Registered: December 2006 Location: new york
|
Member |
|
|
I finally got it to work btu no conversion took place. I am now sure what am I missing?
Thks!
SQL> ed
Wrote file afiedt.buf
1 CREATE OR REPLACE FUNCTION PadTaxNum (u_string IN VARCHAR2) -- usr string
2 RETURN VARCHAR2
3 IS
4 ntaxnum VARCHAR2(25) := '&u_string';
5 BEGIN
6 RETURN ntaxnum;
7 ntaxnum := SUBSTR(u_string, 1, 4)
8 ||'-'||SUBSTR(u_string, 5,3)
9 ||'.'||SUBSTR(u_string, 8,2)
10 ||'-'||SUBSTR(u_string, 10,2)
11 ||'.'||SUBSTR(u_string, 12,2)
12 ||'-'||SUBSTR(u_string, 14,3)
13 ||'.'||SUBSTR(u_string, 17);
14* END;
SQL> /
Enter value for u_string: 0600108000300010001
old 4: ntaxnum VARCHAR2(25) := '&u_string';
new 4: ntaxnum VARCHAR2(25) := '0600108000300010001';
Function created.
SQL> select padtaxnum('ntaxnum') from ttable where rownum <= 15;
PADTAXNUM('NTAXNUM')
--------------------------------------------------------------------------------
0600108000300010001
0600108000300010001
0600108000300010001
0600108000300010001
0600108000300010001
0600108000300010001
0600108000300010001
0600108000300010001
0600108000300010001
0600108000300010001
0600108000300010001
PADTAXNUM('NTAXNUM')
--------------------------------------------------------------------------------
0600108000300010001
0600108000300010001
0600108000300010001
0600108000300010001
15 rows selected.
|
|
|
|
|
FUNCTION COMPLIED OK BUT RESULT NOT. [message #215761 is a reply to message #215751] |
Tue, 23 January 2007 16:19   |
oraclenub2006
Messages: 56 Registered: December 2006 Location: new york
|
Member |
|
|
Sorry about that. Here we go.
After padding the user input varchar(19)
the following funtion added the '.'. '-' etc...5 in total
SUBSTR(x, 1, 4)
||'-'||SUBSTR(x,5,3)
||'.'||SUBSTR(x,8,2)
||'-'||SUBSTR(x,10,2)
||'.'||SUBSTR(x,12,2)
||'-'||SUBSTR(x,14,3)
||'.'||SUBSTR(x,17);
...
The output becomes a varchar2(25)
SQL> select padtaxnum('ntaxnum') from ttable where rownum <= 15;
is supposed to give the following:
PADTAXNUM('NTAXNUM')
-----------------------------------------------------------------0600-108.00-03.00-010.001
0600-108.00-03.00-010.001
0600-108.00-03.00-010.001
0600-108.00-03.00-010.001
0600-108.00-03.00-010.001
0600-108.00-03.00-010.001
0600-108.00-03.00-010.001
0600-108.00-03.00-010.001
0600-108.00-03.00-010.001
0600-108.00-03.00-010.001
0600-108.00-03.00-010.001
0600-108.00-03.00-010.001
0600-108.00-03.00-010.001
0600-108.00-03.00-010.001
... 15 total
Thanks!
|
|
|
Re: SP2-0552 Bind variable not declared ERROR [message #215768 is a reply to message #213894] |
Tue, 23 January 2007 18:18   |
flyboy
Messages: 1903 Registered: November 2006
|
Senior Member |
|
|
Quote: | 1 CREATE OR REPLACE FUNCTION PadTaxNum (u_string IN VARCHAR2) -- usr string
2 RETURN VARCHAR2
3 IS
4 ntaxnum VARCHAR2(25) := '&u_string';
5 BEGIN
6 RETURN ntaxnum;
7 ntaxnum := SUBSTR(u_string, 1, 4)
8 ||'-'||SUBSTR(u_string, 5,3)
9 ||'.'||SUBSTR(u_string, 8,2)
10 ||'-'||SUBSTR(u_string, 10,2)
11 ||'.'||SUBSTR(u_string, 12,2)
12 ||'-'||SUBSTR(u_string, 14,3)
13 ||'.'||SUBSTR(u_string, 17);
14* END;
SQL> /
|
So your function has a parameter u_string, which is unused.
Then a local variable ntaxnum which is assigned a pl/sql variable u_string (if not defined, then asked for it and directly substituted in the function).
You directly return this value. So the calculation you are doing after the RETURN is never proceeded.
You call this function with the string constant 'ntaxnum' (however the function parameter is not used, so it does not matter).
Maybe you want to do this:
1 CREATE OR REPLACE FUNCTION PadTaxNum (u_string IN VARCHAR2) -- usr string
RETURN VARCHAR2
IS
BEGIN
RETURN SUBSTR(u_string, 1, 4)
||'-'||SUBSTR(u_string, 5,3)
||'.'||SUBSTR(u_string, 8,2)
||'-'||SUBSTR(u_string, 10,2)
||'.'||SUBSTR(u_string, 12,2)
||'-'||SUBSTR(u_string, 14,3)
||'.'||SUBSTR(u_string, 17);
END;
/
select padtaxnum(ntaxnum) from ttable where rownum <= 15;
This function has a parameter u_string, which is changed in the desired way and returned as a result.
You call this function with the ntaxnum column value.
Check the differences of the results.
|
|
|
|
|
Re: SP2-0552 Bind variable not declared ERROR [message #216034 is a reply to message #216030] |
Wed, 24 January 2007 14:48   |
oraclenub2006
Messages: 56 Registered: December 2006 Location: new york
|
Member |
|
|
Here is what I've done in sqlPlus several weeks back:
select substr(x, 1, 4) -- here is where padding is done
||'-'||substr(x,5,3)
||'.'||substr(x,8,2)
||'-'||substr(x,10,2)
||'.'||substr(x,12,2)
||'-'||substr(x,14,3)
||'.'||substr(x,17) Tax_Number
from (select '&t_number' x from ttable)
where rownum <=15
SQL> /
Enter value for t_number: 1000109000700005001
old 8: from (select '&t_number' x from ttable)
new 8: from (select '1000109000700005001' x from ttable)
TAX_NUMBER
-------------------------
1000-109.00-07.00-005.001 -- note the result after padding
1000-109.00-07.00-005.001 -- hope to store 15 or less in var
1000-109.00-07.00-005.001
1000-109.00-07.00-005.001
1000-109.00-07.00-005.001
...
Elapsed: 00:00:00.01
Execution Plan
----------------------------------------------------------
0 SELECT STATEMENT Optimizer=CHOOSE
1 0 COUNT (STOPKEY)
2 1 TABLE ACCESS (FULL) OF 'TTable'
I wanted to use a function instead to make it more efficient.
Note 2 things:
The number entered by usr will come from an other app as a variable. This value is entered as 19 varchar after padding this number is 25 varchar2. I wanted to use a bind variable where the stored padded # will be hence the parameter in question: PADTAXNUM('NTAXNUM')
After I succesfully created the function and executed it here is the result: there is no error, but I did not get the desired result that I got using sql plus:
Here it is again:
SQL> ed
Wrote file afiedt.buf
1 CREATE OR REPLACE FUNCTION PadTaxNum (u_string IN VARCHAR2) -- usr string
2 RETURN VARCHAR2
3 IS
4 ntaxnum VARCHAR2(25) := '&u_string';
5 BEGIN
6 RETURN ntaxnum;
7 ntaxnum := SUBSTR(u_string, 1, 4) -- code below did not exec
8 ||'-'||SUBSTR(u_string, 5,3)
9 ||'.'||SUBSTR(u_string, 8,2)
10 ||'-'||SUBSTR(u_string, 10,2)
11 ||'.'||SUBSTR(u_string, 12,2)
12 ||'-'||SUBSTR(u_string, 14,3)
13 ||'.'||SUBSTR(u_string, 17);
14* END;
SQL> /
Enter value for u_string: 0600108000300010001
old 4: ntaxnum VARCHAR2(25) := '&u_string'; -- wrong s/b 19
new 4: ntaxnum VARCHAR2(25) := '0600108000300010001'; -- s/b 25
Function created.
SQL> select padtaxnum('ntaxnum') from ttable where rownum <= 15;
PADTAXNUM('NTAXNUM')
--------------------------------------------------------------------------------
0600108000300010001 -- note there is no padding, I need # padded
0600108000300010001
0600108000300010001
...
I am sorry for all the confusion. I hope I made it clear for you.
Thanks again for all your patience.
|
|
|
|
Re: SP2-0552 Bind variable not declared ERROR [message #216041 is a reply to message #216036] |
Wed, 24 January 2007 16:23   |
oraclenub2006
Messages: 56 Registered: December 2006 Location: new york
|
Member |
|
|
Anacedent,
So close yet soooo far. That was pretty good. I just need to debug why data appears to be corrupted.
Here is what the latest change yields:
SQL> r
1 CREATE OR REPLACE FUNCTION PadTaxNum (u_string IN VARCHAR2)
2 RETURN VARCHAR2
3 IS
4 ntaxnum VARCHAR2(25):= '&u_string';
5 BEGIN
6 -- RETURN ntaxnum;
7 ntaxnum := SUBSTR(u_string, 1, 4)
8 ||'-'||SUBSTR(u_string, 5,3)
9 ||'.'||SUBSTR(u_string, 8,2)
10 ||'-'||SUBSTR(u_string, 10,2)
11 ||'.'||SUBSTR(u_string, 12,2)
12 ||'-'||SUBSTR(u_string, 14,3)
13 ||'.'||SUBSTR(u_string, 17);
14 RETURN ntaxnum;
15* END;
old 4: ntaxnum VARCHAR2(25):= '&u_string';
new 4: ntaxnum VARCHAR2(25):= '0300074000500027000';
Function created.
SQL> select padtaxnum('ntaxnum')from ttable where rownum <=15;
Unfortunatly here is what the output looks like:
PADTAXNUM('NTAXNUM')
-----------------------------------------------------------------
ntax-num.-.-.
ntax-num.-.-.
ntax-num.-.-.
ntax-num.-.-.
ntax-num.-.-.
ntax-num.-.-.
ntax-num.-.-.
ntax-num.-.-.
ntax-num.-.-.
ntax-num.-.-.
ntax-num.-.-.
PADTAXNUM('NTAXNUM')
------------------------------------------------------------------------------
ntax-num.-.-.
ntax-num.-.-.
ntax-num.-.-.
ntax-num.-.-.
15 rows selected.
Many thks though.
|
|
|
|
Re: SP2-0552 Bind variable not declared ERROR [message #216064 is a reply to message #216034] |
Wed, 24 January 2007 21:50   |
flyboy
Messages: 1903 Registered: November 2006
|
Senior Member |
|
|
oraclenub2006 wrote on Wed, 24 January 2007 21:48 | I wanted to use a function instead to make it more efficient.
|
Instead of one query requiring user input you will each time create/replace a stored function which stores the entered value and then call it (efficiency bonus).
When I look into your first version, no VARCHAR2 constant 'ntaxnum' neither variable ntaxnum is used. However you call it correct. If so, there is no need for it in the second version.
oraclenub2006 wrote on Wed, 24 January 2007 21:48 | The number entered by usr will come from an other app as a variable. This value is entered as 19 varchar after padding this number is 25 varchar2. I wanted to use a bind variable where the stored padded # will be hence the parameter in question: PADTAXNUM('NTAXNUM')
|
Do you want the stored pl/sql function to take the value of the variable from your sqlplus session (or wherever it is)? It is not possible, you have to get the desired value in your sqlplus session.
-- create a stored function (only once)
CREATE OR REPLACE FUNCTION PadTaxNum (par IN VARCHAR2)
RETURN VARCHAR2
IS
BEGIN
RETURN SUBSTR(par, 1, 4)
||'-'||SUBSTR(par, 5,3)
||'.'||SUBSTR(par, 8,2)
||'-'||SUBSTR(par, 10,2)
||'.'||SUBSTR(par, 12,2)
||'-'||SUBSTR(par, 14,3)
||'.'||SUBSTR(par, 17);
END;
/
-- call user to enter desired value in sqlplus
accept u_string char prompt "Enter the value: "
-- or define its value directly
-- define u_string="0300074000500027000"
-- and call the stored procedure for the desired output
select padtaxnum(&u_string) from ttable where rownum <= 15;
-- if you want to pass it from another function, use a sqlplus bind variable
-- by the way you used this term, where did you get it?
variable u_string char(19)
execute :u_string := <other_app_call>
-- and call the stored procedure for the desired output
select padtaxnum(:u_string) from ttable where rownum <= 15;
Sorry for mixing these two approaches in my previous post (suppose you would complain of the result if you tried it). However if it does not satisfy your needs, start with studying documentation to write your own solution.
anacedent wrote on Thu, 25 January 2007 00:16 | Rhetorical question - what is the difference between "u_string" in LINE#1 and LINE#4?
| Maybe this causes the misunderstanding. So I add another: what is the difference between ntaxnum in line 4 and 'ntaxnum' passed as parameter to the function?
|
|
|
|
|
|
Re: SP2-0552 Bind variable not declared ERROR [message #216290 is a reply to message #216259] |
Fri, 26 January 2007 03:03  |
flyboy
Messages: 1903 Registered: November 2006
|
Senior Member |
|
|
oraclenub2006 wrote on Thu, 25 January 2007 22:25 | Perhaps I may need to use && w/ my '&&usr_sting' variable like so, since the same content of that var will be used twice. By that I mean I have 2 sets og Qry joined via union all. Based upon your above suggestion I'd have to call that function twice which is not a problem, but I dont want to prompt user twice for that same # within a session. Let me know what you think.
|
Since you define u_string, it may be used in the sqlplus session as many times as you want until you UNDEFINE it. As you see, no && was used, no need to enter u_string value since it was defined by ACCEPT till UNDEFINE.
SQL> set verify off
SQL> accept u_string char prompt "Enter the value: "
Enter the value: 0300074000500027000
SQL> select 'test '||&u_string col from dual;
COL
-----------------------
test 300074000500027000
SQL> select 'test '||&u_string col from dual union all
2 select 'test '||&u_string col from dual;
COL
-----------------------
test 300074000500027000
test 300074000500027000
SQL> undefine u_string
SQL> select 'test '||&u_string col from dual;
Zadejte hodnotu pro u_string: 0300074000500027000
COL
-----------------------
test 300074000500027000
SQL>
Next time try to make these testcases on your own.
|
|
|
Goto Forum:
Current Time: Sat Jul 26 15:31:30 CDT 2025
|