Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 137069
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T07:02:53+00:00 2026-05-11T07:02:53+00:00

I have a query that has … WHERE PRT_STATUS=’ONT’ … The prt_status field is

  • 0

I have a query that has

… WHERE PRT_STATUS=’ONT’ …

The prt_status field is defined as CHAR(5) though. So it’s always padded with spaces. The query matches nothing as the result. To make this query work I have to do

… WHERE rtrim(PRT_STATUS)=’ONT’

which does work.

That’s annoying.

At the same time, a couple of pure-java DBMS clients (Oracle SQLDeveloper and AquaStudio) I have do NOT have a problem with the first query, they return the correct result. TOAD has no problem either.

I presume they simply put the connection into some compatibility mode (e.g. ANSI), so the Oracle knows that CHAR(5) expected to be compared with no respect to trailing characters.

How can I do it with Connection objects I get in my application?

UPDATE I cannot change the database schema.

SOLUTION It was indeed the way Oracle compares fields with passed in parameters.

When bind is done, the string is passed via PreparedStatement.setString(), which sets type to VARCHAR, and thus Oracle uses unpadded comparision — and fails.

I tried to use setObject(n,str,Types.CHAR). Fails. Decompilation shows that Oracle ignores CHAR and passes it in as a VARCHAR again.

The variant that finally works is

setObject(n,str,OracleTypes.FIXED_CHAR); 

It makes the code not portable though.

The UI clients succeed for a different reason — they use character literals, not binding. When I type PRT_STATUS=’ONT’, ‘ONT’ is a literal, and as such compared using padded way.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T07:02:54+00:00Added an answer on May 11, 2026 at 7:02 am

    Note that Oracle compares CHAR values using blank-padded comparison semantics.

    From Datatype Comparison Rules,

    Oracle uses blank-padded comparison semantics only when both values in the comparison are either expressions of datatype CHAR, NCHAR, text literals, or values returned by the USER function.

    In your example, is 'ONT' passed as a bind parameter, or is it built into the query textually, as you illustrated? If a bind parameter, then make sure that it is bound as type CHAR. Otherwise, verify the client library version used, as really old versions of Oracle (e.g. v6) will have different comparison semantics for CHAR.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have search query that has many optional parameters and then search word field
I have an query that has been giving me trouble. I think there is
I have the following query with many LEFT JOIN clauses that has 7 result
Suppose I have a SQL Query that isn't really nice. The SQL Query has
I have objects that has a DateTime property, how can i query for the
I have a query like below that has groups (COL1) and that group's values
I have a query that is filtered by SO Number. It also has a
I have a query that has a very costly INDEX SEEK operation in the
Edit: using SQL Server 2005. I have a query that has to check whether
I have a Query class that has a number of properties that are collections

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.