开发者

Oracle: query with 'N' function - which datatype should I use?

开发者 https://www.devze.com 2023-01-31 06:40 出处:网络
I have created an Oracle table with an indexed varchar2 column, called \'ID\'. A software I\'m using is reading this table, but instead of running queries like

I have created an Oracle table with an indexed varchar2 column, called 'ID'.

A software I'm using is reading this table, but instead of running queries like

select * from table_na开发者_C百科me where ID='something'

it does (notice the extra "N" before the value)

select * from table_name where ID=N'something'

which is causing some kind of character conversion.

The problem is that, while the 1st query is performing a range scan, the 2nd is performing a full table scan.

Since I cannot modify the queries that this software is running, which data type should I use, instead of varchar2, so that the conversion performed by the 'N' function does not imply a full table scan?


The prefix N before the string is used to specify a NVARCHAR2 or NCHAR datatype.

When comparing NVARCHAR2s to VARCHAR2s, Oracle converts the VARCHAR2 variable to NVARCHAR2. This is why you are experiencing a FULL SCAN.

Use a NVARCHAR2 column instead of a VARCHAR2 in your table if you can't modify the query.

0

精彩评论

暂无评论...
验证码 换一张
取 消