Home » SQL & PL/SQL » SQL & PL/SQL » When I joining char and varchar2 column, I am not getting now rows (Oralce 11g)
When I joining char and varchar2 column, I am not getting now rows [message #608760] Mon, 24 February 2014 08:22 Go to next message
na.dharma@gmail.com
Messages: 82
Registered: May 2008
Location: bangalore
Member

Hi

When I joining char and varchar2 column, I am not getting now rows , if I use trim then I the query return the rows, why? What mechanism behind?

SQL> DROP TABLE a;
DROP TABLE a
           *
ERROR at line 1:
ORA-00942: table or view does not exist


SQL> DROP TABLE b;

Table dropped.

SQL> CREATE TABLE a (test CHAR(4))
  2  TABLESPACE warehouse_big_data;

Table created.

SQL> CREATE TABLE b (test VARCHAR2(4))
  2  TABLESPACE warehouse_big_data;

Table created.

SQL> INSERT INTO a
  2       VALUES ('NLS');

1 row created.

SQL> INSERT INTO b
  2       VALUES ('NLS');

1 row created.

SQL> SELECT LENGTH(test), test FROM a;

LENGTH(TEST) TEST
------------ ----
           4 NLS

SQL> SELECT LENGTH(test), test FROM b;

LENGTH(TEST) TEST
------------ ----
           3 NLS

SQL> SELECT *
  2    FROM a, b
  3   WHERE a.test = b.test;

no rows selected

SQL> SELECT *
  2    FROM a, b
  3   WHERE TRIM(a.test) = TRIM(b.test);

TEST TEST
---- ----
NLS  NLS

SQL>
Re: When I joining char and varchar2 column, I am not getting now rows [message #608761 is a reply to message #608760] Mon, 24 February 2014 08:25 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
because "NLS" is not equal to "NLS "
Re: When I joining char and varchar2 column, I am not getting now rows [message #608763 is a reply to message #608760] Mon, 24 February 2014 08:39 Go to previous messageGo to next message
manubatham20
Messages: 566
Registered: September 2010
Location: Seattle, WA, USA
Senior Member

You are not comparing the same data type.
Cast it.
Re: When I joining char and varchar2 column, I am not getting now rows [message #608766 is a reply to message #608763] Mon, 24 February 2014 08:54 Go to previous messageGo to next message
na.dharma@gmail.com
Messages: 82
Registered: May 2008
Location: bangalore
Member

Just I want to understand the mechanism of when we insert values into char and varchar2 what is happening

Re: When I joining char and varchar2 column, I am not getting now rows [message #608768 is a reply to message #608766] Mon, 24 February 2014 08:59 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
na.dharma@gmail.com wrote on Mon, 24 February 2014 06:54
Just I want to understand the mechanism of when we insert values into char and varchar2 what is happening



We don't understand what you don't understand.

we can NOT make you understand anything.

Re: When I joining char and varchar2 column, I am not getting now rows [message #608769 is a reply to message #608768] Mon, 24 February 2014 09:07 Go to previous messageGo to next message
manubatham20
Messages: 566
Registered: September 2010
Location: Seattle, WA, USA
Senior Member

shoud I use char or varchar2
Re: When I joining char and varchar2 column, I am not getting now rows [message #608770 is a reply to message #608769] Mon, 24 February 2014 09:09 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
You can lead some folks to knowledge; but you can't make them think.
Re: When I joining char and varchar2 column, I am not getting now rows [message #608775 is a reply to message #608766] Mon, 24 February 2014 10:42 Go to previous message
Solomon Yakobson
Messages: 3273
Registered: January 2010
Location: Connecticut, USA
Senior Member
na.dharma@gmail.com wrote on Mon, 24 February 2014 09:54
Just I want to understand the mechanism of when we insert values into char and varchar2 what is happening



When I don't understand I try to find it in docs:

CHAR Data Type
The CHAR data type specifies a fixed-length character string. Oracle ensures that all values stored in a CHAR column have the length specified by size. If you insert a value that is shorter than the column length, then Oracle blank-pads the value to column length.


SY.
Previous Topic: Employee(s) Getting Less Than the Average Salary
Next Topic: Date Typecast Usage
Goto Forum:
  


Current Time: Fri Apr 19 18:59:24 CDT 2024