SELECT INTO doing case insensitive query?
Hi all,
I'm having a problem with a query acting as if it is case-insensitive when I do a "SELECT table.x INTO variable ...". If I do the same query, without the "INTO variable", I get one result, as expected.
The query is similar to the following:
SELECT table_id INTO variable FROM table WHERE table.varchar2column = 'name' AND table.integercolumn = int_variable;
There is a unique constraint forcing the varchar2column / integercolumn values to be unique.
If the varchar2column has two entries that differ only in case, a regular select statement returns one result. However, in the stored procedure using the INTO, I get the following error message:
ORA-01422: exact fetch returns more than requested number of rows
It does not get that if I remove the entry that differs only in letter-case. This is Oracle 10.2.0.1.0, if that matters.
I need this query to be case sensitive. I'm not a DB expert, I'm just a developer trying to fix a problem. I attempted to run "ALTER session SET nls_sort = binary" in the stored procedure, but I guess I can't do that...
Any suggestions would be appreciated.
791307 wrote:
SELECT table_id INTO variable FROM table WHERE table.varchar2column = 'name' AND table.integercolumn = int_variable;
...When you say, "...AND table.integercolumn = int_variable;" What is the name of int_variable? Does that name match some column name? Could you post the table creats and a complete sample PL/SQL block with your issue?
One of the things that gets me every once in awhile is having a variable name that matches a column name. In that case the column name is used inside the select statement, not the variable. To avoid that issue, I use v_ for all my variables. (Others have different standard prefixes.)
I only point this out, because it might be given results that look case insensitive on the varchar2 column, but is really an issue with the integer column matching to a variable:
SQL> drop table T;
Table dropped.
SQL> create table T (id number constraint T_PK primary key
2 , Varchar2Data varchar2(20)
3 , NumberData number(38)
4 , constraint T_UK1 unique (Varchar2Data, NumberData)
5 );
Table created.
SQL> insert into T values (1, 'STRING', 100);
1 row created.
SQL> insert into T values (2, 'string', 200);
1 row created.
SQL> insert into T values (3, 'STRING', 300);
1 row created.
SQL> select * from T where Varchar2Data = 'STRING' and NumberData = 100;
ID VARCHAR2DATA NUMBERDATA
1 STRING 100
SQL> declare
2 NumberData number(38);
3 Id Number;
4 begin
5 NumberData := 100;
6 select Id into Id
7 from T
8 where T.Varchar2Data = 'STRING'
9 and T.NumberData = NumberData;
10 DBMS_OUTPUT.PUT_LINE(Id);
11 end;
12 /
declare
ERROR at line 1:
ORA-01422: exact fetch returns more than requested number of rows
ORA-06512: at line 6
SQL> declare
2 v_NumberData number(38);
3 v_Id Number;
4 begin
5 v_NumberData := 100;
6 select Id into v_Id
7 from T
8 where T.Varchar2Data = 'STRING'
9 and T.NumberData = v_NumberData;
10 DBMS_OUTPUT.PUT_LINE(v_Id);
11 end;
12 /
1
PL/SQL procedure successfully completed.
SQL>
Similar Messages
-
Case insensitive query on a CLOB item
Hi all
i have this problem...
i have a table which contains a CLOB column
in my form i have a block based on this table.
i noticed that when i query the form on the clob item , it doesn't accept the case insensitive query property.
(so if i query %AA% the form doesn't show 'Aa' or the 'aa')
can you please help me?
thanks!Forms is not really instrumented to query clobs directly. Google "oracle forms and clob" to see some suggestions on how to handle clobs in Forms
-
GetOrdinal of AseDataReader Class is not doing case-insensitive search
hi,
I am working on 12.5.4 version of sybase ASE.I am using 'Sybase.AdoNet2.AseClient.dll' to connect with database. I am using GetOrdinal method of ASEDatareader class (that as per documentation performs a case-sensitive lookup first. If it fails , a second search that is case-insensitive occurs) but in my case it is not performing case-insensitive search. I am attaching the document for your reference.
http://infocenter.sybase.com/help/index.jsp?topic=/com.infocenter.dc20066.1570100/doc/html/san1364409576274.html
Thanks,
RamanHi Monica,
Another thing you want to make sure is on your ASE that the oledb/adonet MDA scripts are up to snuff. Some of our fixes in the driver are in this.
If you login into the ASE and get the output of sp_version.
You should get something like this:
OLEDB MDA Scripts
15.7.0.1250.1013/Wed Feb 19 UTC 00:28:47 2014
The ado.net driver and the older oledb driver use some specific MDA scripts on the ASE.
Read the coverletter of the SDK (Software Developers Kit for ASE). It explains how to update the MDA scripts. They are on the client side $sybase\ADONET\sp.
So where you downloaded the SDK you want to click Info then look for the README.
This is all the SDKs:
* Updating the metadata stored procedures required by ODBC, OLE DB and
jConnect Drivers on Adaptive Server Enterprise
Certain new features and bug fixes in ODBC, OLE DB and jConnect drivers
require you to modify the metadata stored procedures in Adaptive Server.
These stored procedures may not be up-to-date on your host ASE server due
to various reasons.
If the metadata stored procedures are outdated, you may not be able to use
some of the fixes that are implemented in this SP/ESD, so you will need to
manually install the updated metadata stored procedures.
To update the metadata stored procedures in Adaptive Server, first determine
the version of the meta-data scripts installed on the ASE. To do so, execute
the following command:
sp_version
go
The version number of the ODBC, OLE DB and jConnect meta-data scripts will
be displayed.
Review the version number column and compare it against the version of the
driver being used.
If the metadata scripts are outdated, the version installed will be older
than the driver build number or you will encounter one of the following:
- stored procedure sp_version is not found
- the stored procedure output does not print a row for the driver
The updated scripts are included with the drivers and can be installed as
follows:
For ODBC & OLE DB:
- Go the "sp" directory under the ODBC/OLE DB installation directory
- Execute the install_odbc_sprocs script for the ODBC Driver and
install_oledb_sprocs script for OLE DB Provider.
Syntax for using the script is:
install_[odbc/olebd]_sprocs <ServerName> <username> [<password>]
where <ServerName> is the name of the Adaptive Server
<username> is the username to connect to the server
[<password>] is the password the username
(don’t supply this for null password)
For jConnect:
- Go to the "sp" directory under the jConnect installation directory. Based
on your host ASE server version, choose the appropriate SQL script.
- Use isql or another tool of your choice to execute the selected script.
This will install the current meta-data stored procedures.
Thanks,
Dawn -
Is there any performant way to do case insensitive searches within the database other than using upper on the column?
If I use upper(col name) the index on the column is bypassed and hence this effects performance.
Is there any other way to do this.
Thanks
VandanaIn 10g rel.2 :
alter session set nls_comp=linguistic;
Execute your query; it should work for text search case insensitive
You can also use regular expression function like regexp_like() with match_option set to i:
select ename
from emp
where regexp_like(ename, k, i);
Best Regards
Krystian Zieja / mob -
Case insensitive query from a JSP
I am using JDeveloper 3.1 to create JSP applications using the wizard for business components for JSP application.
The default query screen allows a search to be performed on all the fields on the table (using the Findform web bean).
How can I change the search such that the query is Case Insensitive ?
Many Thanks,
Ketan.
Many Thanks,
Ketan.Forms is not really instrumented to query clobs directly. Google "oracle forms and clob" to see some suggestions on how to handle clobs in Forms
-
I'm trying to do a query ignoring case.
select to_upper(node) from STATUS where to_upper(node) = 'KAN';
I get ORA-00904 : invalid colum name
I also tried to use a column alias but got the same result
select to_upper(node) nnn from STATUS where nnn = 'KAN'
I'm stuck
GeorgeHi,
try upper(node) instead of to_upper.
hth -
Case insensitive query or search in Form
Hi,
I have created a form based on a table. If i fill any of the field and then clicks the Query button for saerch it give me the record but it is case sensitive. How can i get this functionality ir-respectative of upeer-case or lower-case.
Thanks in advance.
EjazIn the onQuery procedure you find this code:
if "_convert" and "_operator" is not null then
"_value" := replace("_value",'''','''''');
"_where" := "_where" ||'ENAME' || "_operator" || ''''|| "_value" ||''' and ';
elsif "_convert" and "_operator" is null then
"_value" := replace("_value",'''','''''');
"_where" := "_where" ||'ENAME like '''|| "_value" ||''' and ';
elsif not "_convert" then
"_where" := "_where" ||'ENAME '|| "_value" ||' and ';
end if;
You should modify this to get what you want. However be warned that changing the generated package is not supported and any changes will be lost on regenerating the component.
Regards,
Hsiu -
How do I convert a case sensitive drive to a case insensitive drive?
I have recently purchased a MacMini Server, and installed the 2 internal hard drives in a RAID 0 configuration to obtain the speed and 1 TB capacity, but unfortunately (rather stupidly in retrospect) formatted the drive in case sensitive mode.
On installing the operating system and multiple applications, everything seemed to work well until I tried to install Adobe Acrobat X Pro. This application refuses to install on a case sensitive formatted drive, which I now understand is a common problem.
The question is how can I convert to a case insensitive format without reinstalling all of the software from scratch?
I have a Time Machine backup, and the easiest thing for me would be to reformat the drive, and then restore from the Time Machine backup.
Will this process work? Or will there be some complications and files that will not function if they were originally installed on a case sensitive drive?
Any help is appreciated....iPartition can do it ( http://www.coriolis-systems.com/iPartition.php ).
from iPartition Help:
Make Case Sensitive/Case Insensitive
HFS+ now supports a case sensitive format as well as the usual case insensitive format. On a case sensitive volume, the names “Readme”, “README” and “ReadMe” would all represent different files, even if they were in the same folder.
This option allows you to non-destructively change a case sensitive volume into a case insensitive one, and vice-versa. If you are going from a case sensitive volume to a case insensitive volume, some of your files may be renamed automatically by iPartition so that they do not clash. If all of the files in the table below were in the same directory, the right hand column shows the new names iPartition would choose for them:
Old name New name
README.txt README.txt
ReadMe.txt ReadMe 1.txt
Readme.txt Readme 2.txt
README README
ReadMe ReadMe 1
Readme Readme 2
Notice that iPartition puts the number before any file extension.
N.B. iPartition does not transform filenames with numbers on the end back into their original forms. There is no way to tell which files were renamed by the user and which were renamed by the conversion process. -
If I have a table that has a column called login_name defined as char(64).
I currenrly prepare statments that look like:
select something from some_table where login_name like ?;
Can I use the following if I wanted to implement a case insensitive query, and are there performance implications?
select something from some_table where UPPER(login_name) like ?;The best way from a performance perspective is to also store the upper (or lower) case form of 'login_name' in an additional column of the table (ucase_login_name), have the application itself convert the parameter value to upper or lower case and the njust do:
select something from some_table where ucase_login_name like ?;
As long as any wildcards are at the end of the passed in parameter this will use an index if one is defined on that column.
Chris -
Case with select into and sub query
hi im trying to use case and select with sebqueries, but my beginer like understanding of syntax fails me. can someone point out what im doing wrong in the case select below. im using select into, as i ultimatly need to load a ref cursor for use with crystal reports.
thanks
james
ps if anyone is london based, and would like to spend a day or two teaching me how to be a bit better at PL/SQL (can aford to pay a little bit) please get in touch!!
SELECT
Case (select kind_code from event where
event.event_id = event.container_event_id)
when 1094006
then promo_name
end
into result
FROM promo, promo_plan , event_promotion
WHERE promo.promo_id = promo_plan.promo_id
AND promo_plan.promo_plan_id = event_promotion.promo_plan_id
AND event_promotion.detail_id = '33532282'
when blah then 'blah';Hello
AH i see what you are driveing at, yes i am just using case slect to determin which >routine to run, as the name is stored in a diferent location depending on the event kind >code. are are you saying i need multiple selects within the case statment? one for each >type of kind code?Well it depends really. If the select
select kind_code from event where
event.event_id = event.container_event_idIs going to return more than one row for any given run, you're going to need to take a bit of a different approach. Is it the case that this query will return more than one row which would mean that you want value X and value Y for each row?
Using the test data and everything from before:
SQL> CREATE OR REPLACE PROCEDURE p_GetStuff(ac_Result OUT sys_refcursor)
2 IS
3
4 BEGIN
5 /*
6 This uses a cartesian product i.e. repeat every row in
7 dt_test_data against every row in dt_test_event
8 */
9 OPEN Ac_Result FOR
10 SELECT
11 CASE dt_test_event.kind_code
12 WHEN 1 THEN
13 dt_test_data.object_name
14 WHEN 2 THEN
15 dt_test_data.object_type
16 END
17 FROM
18 dt_test_data,
19 dt_test_event;
20
21 END;
22 /
Procedure created.
SQL> var x refcursor
SQL> exec p_getstuff(:x)
PL/SQL procedure successfully completed.
SQL> print x
CASEDT_TEST_EVENT.KIND_CODEWHEN1THENDT_TEST_DATA.OBJECT_NAMEWHEN2THENDT_TEST_DAT
ABC
ABC4
AD1
AD2
ADHOC_CONTACT_LOG
AK_CD_CLAIM_VALIDATION_SOURCE
AK_CD_CLAIM_VALIDATION_TYPE
AK_CLAIM_ACTION_ROWSOURCE
APPROVAL_LIST_MEM_IE
APPROVE_GRP_HIST_IE
10 rows selected.
SQL> insert into dt_test_event values(2);
1 row created.
SQL> exec p_getstuff(:x)
PL/SQL procedure successfully completed.
SQL> print x
CASEDT_TEST_EVENT.KIND_CODEWHEN1THENDT_TEST_DATA.OBJECT_NAMEWHEN2THENDT_TEST_DAT
ABC
ABC4
AD1
AD2
ADHOC_CONTACT_LOG
AK_CD_CLAIM_VALIDATION_SOURCE
AK_CD_CLAIM_VALIDATION_TYPE
AK_CLAIM_ACTION_ROWSOURCE
APPROVAL_LIST_MEM_IE
APPROVE_GRP_HIST_IE
TABLE
CASEDT_TEST_EVENT.KIND_CODEWHEN1THENDT_TEST_DATA.OBJECT_NAMEWHEN2THENDT_TEST_DAT
TABLE
TABLE
TABLE
TABLE
INDEX
INDEX
INDEX
INDEX
INDEX
20 rows selected.Or an alternative to that would be, if you have a fixed number of event ids and they relate to a fixed number of attributes you could use something like:
CREATE OR REPLACE PROCEDURE p_GetStuff3(ac_Result OUT sys_refcursor)
IS
BEGIN
The SUBSTR
is just there to make sure the data fit on screen, my SQL*Plus
is a bit weird!
OPEN Ac_Result FOR
SELECT
SUBSTR(MAX(DECODE(dt_test_event.kind_code,1,dt_test_data.object_name,NULL)),1,30) attribute_1,
SUBSTR(MAX(DECODE(dt_test_event.kind_code,2,dt_test_data.object_type,NULL)),1,30) attribute_2
FROM
dt_test_data,
dt_test_event
GROUP BY
object_name;
END;
SQL> delete from dt_test_event where kind_code=2;
1 row deleted.
SQL> exec p_getstuff3(:x)
PL/SQL procedure successfully completed.
SQL> print x
ATTRIBUTE_1 ATTRIBUTE_2
ABC
ABC4
AD1
AD2
ADHOC_CONTACT_LOG
AK_CD_CLAIM_VALIDATION_SOURCE
AK_CD_CLAIM_VALIDATION_TYPE
AK_CLAIM_ACTION_ROWSOURCE
APPROVAL_LIST_MEM_IE
APPROVE_GRP_HIST_IE
10 rows selected.
SQL> insert into dt_test_event values(2);
1 row created.
SQL> exec p_getstuff3(:x)
PL/SQL procedure successfully completed.
SQL> print x
ATTRIBUTE_1 ATTRIBUTE_2
ABC TABLE
ABC4 TABLE
AD1 TABLE
AD2 TABLE
ADHOC_CONTACT_LOG TABLE
AK_CD_CLAIM_VALIDATION_SOURCE INDEX
AK_CD_CLAIM_VALIDATION_TYPE INDEX
AK_CLAIM_ACTION_ROWSOURCE INDEX
APPROVAL_LIST_MEM_IE INDEX
APPROVE_GRP_HIST_IE INDEX
10 rows selected.Message was edited by:
david_tyler
Oops, copy + pasted the wrong comments for the 2nd proc. -
SELECT Query to get the Values in Case insensitive Format
Hi ,
This is hari,
I want to select the user name in a table ex: username="HARI" or username='Hari' or username="HaRi" like this
If i wrote the query like
select username from userdb where username="Hari";
it is displaying the records which only matches "Hari" only .
can anybody help me out on this query asap please....
the query should return all the results
which matches any of the following strings as inputs "HARI" or "HaRi" or "hAri" or the like.
Awaiting for Response,
Thanks & Regards
HariAnother solution is setting NLS_SORT to CI - case insensitive (or whatever_your_language_is_CI) and NLS_COMP to ANSI:
SQL> with t as (
2 select 'HARI' name from dual union all
3 select 'Hari' name from dual union all
4 select 'HaRi' name from dual
5 )
6 select *
7 from t
8 where name = 'hArI'
9 /
no rows selected
SQL> alter session set nls_sort = binary_ci
2 /
Session altered.
SQL> alter session set nls_comp=ansi
2 /
Session altered.
SQL> with t as (
2 select 'HARI' name from dual union all
3 select 'Hari' name from dual union all
4 select 'HaRi' name from dual
5 )
6 select *
7 from t
8 where name = 'hArI'
9 /
NAME
HARI
Hari
HaRi
SQL> SY. -
Select query case insensitive for data type VARG
Hi Experts,
I am having trouble in retrieving the results from a table using select query.
I have a table (Users) as below
Name (VARG) Number(INTEGER)
Murthy 0001
murthy 0002
when I am querying the table with select query as -
select * from Users where Name = 'Murthy'
this query is returning only one record which matches with capital letter of 'M', though both the record names are same.
I have seen in IBM forum to make the select query as case insensitive using the UPPER key word, I have tried this as below -
select * from Users where UPPER(Name) = 'MURTHY'
But this query is not working in my case...
My DB2 version is 8.1.5
Can any one please help in fixing this problem...
Thanks in Advance,
MurthyHi Murthy,
your query is the right to one to select both records. I don't see why it doesn't work.
Are you sure you posted the query that you have executed ?
What is the result of this query ?
But i don't really know how an VARG (Varying-length graphic string) will work. It could be that the UPPER-Function will work in another way as it works on VARCHAR.
regards
Kay -
Hi all,
I'm trying to pratice EJB 3 (which I learnt at school), with JSF and JPA, but i'm really stuck with that error :
Exception [TOPLINK-6094] (Oracle TopLink Essentials - 2.0 (Build b41-beta2 (03/30/2007))): oracle.toplink.essentials.exceptions.QueryException
Exception Description: The parameter name [departmentID] in the query's selection criteria does not match any parameter name defined in the query.
Query: ReadAllQuery(oracle.datamodel.Employees)
I will try to explain clearly what i'm trying to do :
In fact, i'm following that tutorial :
http://www.oracle.com/technology/obe/obe1013jdev/10131/ejb_and_jpa/master-detail_pagewith_ejb.htm
But, as i didn't have any oracle database, but had a mysql one on my machine, i decided to use that DB instead of the the oracle DB... So i created a set of example data (to replace the oracle example set) ...so i created the tables EMPLOYEE, and DEPARTMENT... with the correct relations (FK) and PK)
All was ok, i choose my "mysql-connector" (jdbc) instead of the oracle jdbc connector... so i could follow the tutorial.
My problem appears at the step 12 (of "Creating a Master-Detail JavaServer Faces Page"), when i run the file deptEmployees.jspx.
The information of the first departement displays correctly :
departmentID 1
departmentName ... etc
but it can't display the employees belonging to that department !
the error is :
JBO-29000: Exception Description: The parameter name [departmentID] in the query's selection criteria does not match any parameter name defined in the query. Query: ReadAllQuery(oracle.datamodel.Employees)
I think i understand what is the problem... I think that the query in charge of gathering the data of a specific departement need a parameter, but couldn't find it. But i don't know why :-/ I have tried many things and read the topics talking about that error... but it didn't solved the problem. I don't know anymore where to investigate.
I have created a Zip file of my work (it's an EJB/JSF Application.. with jdev 10.1.3.3.0)
(available here : http://dl.free.fr/mQ5esdQuS/EJB_appli.zip)
I would be glad if someone could take few minutes to help me.
Thank you in advance,
Thomas B (student)Hello,
This is a common mistake. Java string comparisons in TopLink are case sensitive by default, and since column names are uppercase when defaulted, TopLink cannot find the "departmentID" column name. In this case, Departments ID column defaults to "DEPARTMENTID" as required by the JPA specification.
Either change Departments id annotation to @Id
@Column(name="departmentID", nullable = false)
private Integer departmentID;or change Employees' ManytoOne annotation to:
@ManyToOne
@JoinColumn(name = "departmentID", referencedColumnName = "DEPARTMENTID")
private Departments departments;Best Regards,
Chris -
Select Into statement in db function - query from granted schema table
problem with "select into" in db function in 10.2
There are two schemas. 'mdbdev' is the master database and 'devusr' is granted SELECT table access to execute queries in mdbdev schema.
with devusr, in SQL, I'm able to execute the following query
select wm_concat(strConcatedCountryList)
from (select country_name as strConcatedCountryList from mdbdev.country_master mdbcm
where mdbcm.country_ship_status = <param?>
order by country_name)
but when I use the same query in function/procedure with "select into", the compilation failed with error *"table or view does not exist"*
FUNCTION GETCOUNTRYLISTTOSHIP (SHIP_STATUS IN NUMBER)
RETURN VARCHAR2
IS
var2CountryList VARCHAR2(1000);
BEGIN
select wm_concat(strConcatedCountryList) INTO var2CountryList
from (select country_name as strConcatedCountryList from mdbdev.country_master mdbcm
where mdbcm.country_ship_status = <value of SHIP_STATUS>
order by country_name);
return var2CountryList;
END;
Please advise/help/hint :)David, Justine, Thank you. The facts from this forum post helped a lot to get the solution.
The query helped a lot (select * from all_tab_privs_recd where owner = 'MDBDEV' and table_name = 'COUNTRY_MASTER").
there was a grant using ???(donno wht DBA said) and no direct SELECT grant on that country_master to "devusr". grant command executed. Now, it works :) -
Case insensitive search in select statement
Hi Experts,
I have entries in table as mixed case. For example i am searching on an attribute called description in the table. I want the serch to be case insensitive for that attribute. Because in table it is i.e. JUMBO Pack and in the search attribute it is i.e. Jumbo Pack.
I do not want to translate both to the same case and search. Is there an option?
Best Regards!
SandipHi Sandip,
One more alternative:
If ztext is ur original field which is saving the mixed text.
Append one extra field(ztext_upper) to the table.
Now if " Sap Sdn" is the text we are saving then
While saving the entires to the table,
1. asusual save the value(" Sap Sdn") to teh original field(ztext)
2. translate the value to upper case(SAP SDN) and save this entry to teh newly appended field(ztext_upper)
Now while doing search, translate to upper case and compare with the value in ztext_upper. If it satisfies then for display options select the original value from the field (ztext) which is corresponding to the satisfied ztext_upper field.
Regards,
Swarna Munukoti.
Maybe you are looking for
-
Can you help me with a Cost problem in an Order?
Hello SAP experts, i have a question regarding orders and their costs if i go inside an order and i go to the menu then ->Goto->Costs->Analisys-> and then choose the layout ->Target/Actual Comparison, in this layout there is a column that says Total
-
Hello, I find the ACR adjustments in Bridge and LR to be much more intuitive than Aperture. But, I don't want to switch to LR since Aperture (to me) wins hands-down as an overall better application. Until I really get a good handle on working with Ap
-
i forgot my passode to my ipod and im trying to restore it. i went through some steps. says connect ipod to itunes then when i connect box comes up n says i have to unlock my passcode to my ipod which i dont know. i thknk its lock now. want come back
-
Align Stage to center of PasteBoard (or window when exported)
Hi everyone! I think there's something wrong with my flash =/ I'm doing some tests and I'm trying to create a simple presentation. It's not something I'll be using online. I just want it to present some things at school. Since I don't know the resolu
-
Transform activity - 10.1.2.2
I have a syncronous read file activity that reads a csv, works great. Then I try to transform to the next partner link. Here is what I get in the console. They payload looks fine to me, it was created by the native conversion wizard in the tool. rece