---
title: "where后面的字符串明明正确却查不到"
author: "ifox"
date: "2013-03-06T09:16:50Z"
tags: []
categories: ["数据库"]
slug: "where"
draft: false
lastmod: "2013-03-06T09:16:50Z"
id: 1823054
url: "https://ifox.iteye.com/blog/1823054"
---

今天在看到[http://haohaoxuexi.iteye.com/blog/1820541](http://haohaoxuexi.iteye.com/blog/1820541)这位朋友写的面试题的时候，自己没事，也在自己的电脑上建了张表。

结果查询的时候出问题了。

select * from student;

 

这样是可以查询出所有的记录的，但是加上条件就不行了，例如

select * from student where iname='张三';

让我很是好奇，后面细细想下才发现，原来是自己在建表的时候把这个字段写成了varchar2了，在Oracle中如果varchar2设置的是8位，实际数据占用2位的话，后面6位会被自动定义为空，也是存在的。

所以在查询的时候当然查询不到啦。

做个实验上面的语句假如这样写就可以查询的到了。

select * from student where iname like '张三%';