Blacq_Shadow
Blacq_Shadow

Reputation: 13

Like Command not working Oracle SQL

I am new to databases and PHP. In my code I am trying to create a table from within PHP script, Here is what I have.

create table booktable(BookID INT PRIMARY KEY,
                   BookName VARCHAR(100),
                   Published DATE,
                   Price NUMBER(18,2),
                   Author1 VARCHAR2(30),
                   Author2 VARCHAR2(30));

INSERT INTO booktable (BookID, BookName, Published, Price, Author1, Author2)
VALUES (1, 'Fundamentals of Digital Logic with VHDL Design','14-APR-08', 190.25,'Stephen Brown','Zvon Ko G.Vranesic');
INSERT INTO booktable (BookID, BookName, Published, Price, Author1, Author2)
VALUES (2, 'Distributed Systems Principles and Paradigm','26-JUL-13', 197.80,'Andrew S. Tanenbaum','Maarten Van Steen');
INSERT INTO booktable (BookID, BookName, Published, Price, Author1, Author2)
VALUES (3, 'Eat Real Food The Only Solution to Permanent weight Loss and Disease Prevention','1-APR-15', 29.99,'David Gillespie','');
INSERT INTO booktable (BookID, BookName, Published, Price, Author1, Author2)
VALUES (4, 'Introduction to Computational Science Modeling and Simulation for the sciences','2-MAY-06', 132.75,'Angela B.Shiflet','George W. Shiflet');
INSERT INTO booktable (BookID, BookName, Published, Price, Author1, Author2)
VALUES (5, 'Live Well on Less A Practical Guide to Running a Lean Household','27-MAY-15', 19.00,'Jody Allen','');
INSERT INTO booktable (BookID, BookName, Published, Price, Author1, Author2)
VALUES (6, 'Middle School: Just My Rotten Luck','1-JUL-15', 15.99,'James Patterson','');
INSERT INTO booktable (BookID, BookName, Published, Price, Author1, Author2)
VALUES (7, 'Clementine Rose and the Birthday Emergency','1-JUL-15', 12.99,'Jacqueline Harvey','');
INSERT INTO booktable (BookID, BookName, Published, Price, Author1, Author2)
VALUES (8, 'My Life It''s a long story','26-MAY-15', 32.99,'Willie Nelson','');
INSERT INTO booktable (BookID, BookName, Published, Price, Author1, Author2)
VALUES (9, 'Sword of Summer Magnus Chase','7-OCT-15', 15.99,'Rick Riordan','');

The table is created successfully, but when I try to run the query

`SQL> select * 
      from booktable
      where bookname like '%my%';`

It says no rows selected. I can't figure out where I am doing wrong. Thanks.

Upvotes: 1

Views: 463

Answers (2)

MGM_Squared
MGM_Squared

Reputation: 177

@alfasin is right. You could also you lower to achieve what you are trying to do

select * from booktable where lower(bookname) like '%my%';

Upvotes: 2

Nir Alfasi
Nir Alfasi

Reputation: 53525

That's because it's case sensitive and you have My contained in some of the fields - not my.

Try instead:

select * 
from booktable
where bookname like '%My%';

Upvotes: 1

Related Questions