Quote:If this is the case why Oracle assumes bind variables to be only varchar type!
This is wrong. Oracle knows the datatype of the variable because YOU (in your client application) tell it.
SQL> variable n_sal number
SQL> exec :n_sal:= 1000
SQL> @traceon
Session altered.
SQL> select * from emp where sal > :n_sal;
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
---------- ---------- --------- ---------- ------------------- ---------- ---------- ----------
7499 ALLEN SALESMAN 7698 20/02/1981 00:00:00 1600 300 30
7521 WARD SALESMAN 7698 22/02/1981 00:00:00 1250 500 30
7566 JONES MANAGER 7839 02/04/1981 00:00:00 2975 20
7654 MARTIN SALESMAN 7698 28/09/1981 00:00:00 1250 1400 30
7698 BLAKE MANAGER 7839 01/05/1981 00:00:00 2850 30
7782 CLARK MANAGER 7839 09/06/1981 00:00:00 2450 10
7788 SCOTT ANALYST 7566 19/04/1987 00:00:00 3000 20
7839 KING PRESIDENT 17/11/1981 00:00:00 5000 10
7844 TURNER SALESMAN 7698 08/09/1981 00:00:00 1500 0 30
7876 ADAMS CLERK 7788 23/05/1987 00:00:00 1100 20
7902 FORD ANALYST 7566 03/12/1981 00:00:00 3000 20
7934 MILLER CLERK 7782 23/01/1982 00:00:00 1300 10
12 rows selected.
SQL> @traceoff
Session altered.
Content of trace file:
...
PARSING IN CURSOR #7 len=36 dep=0 uid=57 oct=3 lid=57 tim=927600340250 hv=1782574640 ad='6fa8fbb8'
select * from emp where sal > :n_sal
END OF STMT
PARSE #7:c=0,e=16587,p=0,cr=0,cu=0,mis=1,r=0,dep=0,og=1,tim=927600340242
BINDS #7:
kkscoacd
Bind#0
oacdty=02 mxl=22(22) mxlc=00 mal=00 scl=00 pre=00
oacflg=03 fl2=1000000 frm=00 csi=00 siz=24 off=0
kxsbbbfp=080a9b08 bln=22 avl=02 flg=05
value=1000
EXEC #7:c=15625,e=117869,p=0,cr=0,cu=0,mis=0,r=0,dep=0,og=1,tim=927600580673
WAIT #7: nam='SQL*Net message to client' ela= 18 driver id=1111838976 #bytes=1 p3=0 obj#=50293 tim=927600648738
FETCH #7:c=0,e=163,p=0,cr=4,cu=0,mis=0,r=1,dep=0,og=1,tim=927600666951
...
Note "oacdty=02" which means datatype NUMBER.
SQL> set serveroutput off
SQL> var s_sal varchar2(10);
SQL> exec :S_SAL := '1000'
PL/SQL procedure successfully completed.
SQL> @traceon
Session altered.
SQL> select * from emp where sal > :s_sal;
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
---------- ---------- --------- ---------- ------------------- ---------- ---------- ----------
7499 ALLEN SALESMAN 7698 20/02/1981 00:00:00 1600 300 30
7521 WARD SALESMAN 7698 22/02/1981 00:00:00 1250 500 30
7566 JONES MANAGER 7839 02/04/1981 00:00:00 2975 20
7654 MARTIN SALESMAN 7698 28/09/1981 00:00:00 1250 1400 30
7698 BLAKE MANAGER 7839 01/05/1981 00:00:00 2850 30
7782 CLARK MANAGER 7839 09/06/1981 00:00:00 2450 10
7788 SCOTT ANALYST 7566 19/04/1987 00:00:00 3000 20
7839 KING PRESIDENT 17/11/1981 00:00:00 5000 10
7844 TURNER SALESMAN 7698 08/09/1981 00:00:00 1500 0 30
7876 ADAMS CLERK 7788 23/05/1987 00:00:00 1100 20
7902 FORD ANALYST 7566 03/12/1981 00:00:00 3000 20
7934 MILLER CLERK 7782 23/01/1982 00:00:00 1300 10
12 rows selected.
SQL> @traceoff
Session altered.
Content of trace:
...
select * from emp where sal > :s_sal
END OF STMT
PARSE #6:c=0,e=108,p=0,cr=0,cu=0,mis=0,r=0,dep=0,og=1,tim=928062645755
BINDS #6:
kkscoacd
Bind#0
oacdty=01 mxl=32(10) mxlc=00 mal=00 scl=00 pre=00
oacflg=03 fl2=1000000 frm=01 csi=178 siz=32 off=0
kxsbbbfp=07f6a3bc bln=32 avl=04 flg=05
value="1000"
EXEC #6:c=0,e=194664,p=0,cr=0,cu=0,mis=0,r=0,dep=0,og=1,tim=928062946413
WAIT #6: nam='SQL*Net message to client' ela= 14 driver id=1111838976 #bytes=1 p3=0 obj#=-1 tim=928062958604
FETCH #6:c=0,e=164,p=0,cr=4,cu=0,mis=0,r=1,dep=0,og=1,tim=928062994912
...
Note "oacdty=01" which means datatype VARCHAR2.
Regards
Michel
[Updated on: Mon, 12 December 2011 02:08]
Report message to a moderator