EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 360+ Courses All in One Bundle
  • Login
Home Data Science Data Science Tutorials Oracle Tutorial Oracle WILDCARDS
Secondary Sidebar
Oracle Tutorial
  • Advanced
    • Timestamp to Date in Oracle
    • Oracle Golden Gate
    • Oracle Virtual Machine
    • Oracle Describe Table
    • Oracle Clauses
    • Oracle Having Clause
    • Oracle?Primavera
    • Oracle FOREIGN Key
    • PIVOT in Oracle
    • Oracle Alter Table
    • Oracle Queries
    • Oracle Views
    • Oracle Window Functions
    • Oracle String Functions
    • Oracle Date Functions
    • Oracle Analytic Functions
    • Oracle Aggregate Functions
    • Select in Oracle
    • INSERT in Oracle
    • DISTINCT in Oracle
    • Function in Oracle
    • Oracle GROUP_CONCAT
    • Oracle INSTR()
    • Oracle CONVERT
    • Oracle LENGTH()
    • Oracle EXISTS
    • Oracle REPLACE()
    • Oracle MERGE
    • Oracle LEAD()
    • Oracle EXTRACT()
    • Oracle LISTAGG()
    • Oracle SYS_CONTEXT()
    • Oracle COALESCE
    • Oracle NVL()
    • Oracle SYSDATE()
    • Oracle?Date Format
    • Oracle SYS_GUID()
    • Oracle WILDCARDS
    • Oracle Synonyms
    • Oracle Subquery
    • BETWEEN in Oracle
    • FETCH in Oracle
    • Oracle Index
    • Oracle Function-based Index
    • Oracle UNIQUE Index
    • Oracle Bitmap Index
    • Oracle Column
    • Oracle Triggers
    • Oracle Procedures
    • Sample Database for Oracle
    • Oracle LIKE Operator
    • ORDER BY in Oracle
    • Oracle ORDER BY DESC
    • GROUP BY in Oracle
    • Oracle GROUP BY HAVING
    • Oracle Aliases
    • Table in Oracle
    • Oracle Temporary Table
    • Oracle? Table Partition
    • Oracle rename table
    • Oracle CTE
    • Cursor in Oracle
    • Oracle LOCK TABLE
    • Oracle Tablespace
    • Oracle CARDINALITY
    • Oracle REGEXP
    • Oracle REGEXP_REPLACE
    • Oracle to_date
    • JSON in Oracle
    • Oracle COMMIT
    • Oracle GRANT
    • Oracle MD5
    • Oracle ROLLBACK
    • Oracle Users
    • Oracle TIMESTAMP
    • IF THEN ELSE in Oracle
    • Oracle While Loop
    • Oracle Clone Database
    • Oracle Backup Database
    • Oracle? XML
    • Oracle XMLAGG
    • Oracle XMLTABLE
    • Oracle Performance Tuning
    • Oracle B Tree Index
    • Oracle fusion
    • Oracle ebs
    • Oracle GRC
    • Oracle ERP
    • Oracle ASM
    • Oracle Cloud
    • Oracle HCM Cloud
    • Oracle Integration Cloud
    • Oracle Jinitiator
    • Oracle pathfinder
    • Oracle VirtualBox
    • Oracle Weblogic Server
    • Oracle decode
    • Oracle Exadata
    • Oracle ZFS
    • Oracle? utilities
    • JDBC Driver for Oracle
    • Oracle? DBA Versions
    • Oracle DBA Salary
  • Basic
    • Oracle Marketing Cloud
    • What is Oracle?
    • Career in Oracle
    • How to Install Oracle
    • Oracle Versions
    • What Is Oracle Database
    • Oracle Data Warehousing
    • Oracle Warehouse Builder
    • Career In Oracle Database Administrator
    • Career In Oracle DBA
    • What is Oracle RAC
    • Oracle DBA
    • Oracle? Vanderbilt
    • What is RMAN Oracle
    • Oracle Database Administration
    • Oracle Operators
    • Oracle Constraints
    • Oracle number
    • Oracle Data Types
    • Oracle UNIQUE Constraint
    • Oracle Check Constraint
  • Joins
    • Joins in Oracle
    • Inner Join in Oracle
    • Oracle Cross Join
    • Left Join in Oracle
    • OUTER Join in Oracle
    • Oracle Full Outer Join
    • Natural Join in Oracle
    • Oracle Self Join
    • Oracle hash join
    • Oracle? Update with Join
  • Oracle SET Operators
    • UNION in Oracle
    • Oracle UNION ALL
    • INTERSECT in Oracle
    • MINUS in Oracle
  • Interview Questions
    • Oracle Interview Questions
    • Oracle Apps Interview Questions
    • Oracle Apps Technical Interview Questions
    • Oracle Database Interview Questions
    • Oracle Forms Interview Questions
    • Oracle PL/SQL Interview Questions
    • Oracle RAC Interview Questions
    • Oracle SOA Interview Questions

Related Courses

Oracle Course Training

Oracle DBA Certification Course

MongoDB Certification Training

Oracle WILDCARDS

By Priya PedamkarPriya Pedamkar

Oracle WILDCARDS

What is Oracle WILDCARDS?

Oracle WILDCARDS are referred for character pattern matching operation as a WILD CARD SEARCH. The WILDCARDS can be used with the LIKE operator. The WILDCARDS with LIKE operator allows us to perform character pattern matching.

All in One Data Science Bundle(360+ Courses, 50+ projects)
Python TutorialMachine LearningAWSArtificial Intelligence
TableauR ProgrammingPowerBIDeep Learning
Price
View Courses
360+ Online Courses | 50+ projects | 1500+ Hours | Verifiable Certificates | Lifetime Access
4.7 (86,171 ratings)

There are two WILDCARDS in Oracle which are:

Start Your Free Data Science Course

Hadoop, Data Science, Statistics & others

  • %: It represents a sequence of any number of characters including zero.
  • _: It represents any single character but only at the specified position.
  • WILDCARDS with LIKE operator must be used in WHERE clause
  • WILDCARDS with LIKE operator can be used in SELECT statement
  • WILDCARDS with LIKE operator can be used for DML operations (INSERT, UPDATE, DELETE)

Syntax:

SELECT …….FROM Table_Name WHERE ColumnName LIKE WILDCARD             character/pattern/literal.

OR

SELECT col_1, col_2…..col_n FROM Table_Name WHERE ColumnName LIKE           ‘pat%’;

Description:

  • Col_1/2/n: The column(s) or calculation as per your requirement.
  • Table_Name: As per your requirement
  • WHERE: It’s mandatory to use this operator.
  • Column_Name: The condition will be applied to the column to filter the data.
  • LIKE: It’s an operator that allows WILDCARDS to be used.

Implementations of WILDCARDS with Examples

In this section, we’ll see the implementation of Oracle WILDCARDS and its behavior. For that, we will use the below sample table (Employee & Dept_category) with 14 & 8 records to understand the Oracle WILDCARDS behavior.

Code:

SELECT * FROM Employee;

Output:

Oracle WILDCARDS-1.1

Code:

SELECT * FROM Dept_category;

Output:

Oracle WILDCARDS-1.2

1. % WILDCARD

Code:

SELECT Name, Designation, DOJ, Salary FROM Employee WHERE Name LIKE 'CH%';

Output:

Oracle WILDCARDS-1.3

In the above SELECT statement % WILDCARD with LIKE operator filter the record(s) based on the condition. It returns only those records which name begins with character pattern “CH” in the Name column and returns the matched record(s). The SQL statement fetched ‘CHANDAN’ details because in the Name column only CHANDAN starts with the “CH” character. % represents any sequence of any number of characters including zero.

2. % WILDCARD with NOT keyword

Code:

SELECT Name, Designation, DOJ, Salary FROM Employee WHERE Name NOT LIKE 'B%';

Output:

Oracle WILDCARDS-1.4

In this output, two records are missing, WHY?

Because the above SELECT statement contains NOT keyword with WILDCARD and LIKE operator. It means this SQL statement selects only those records which does not start with the supplied pattern ‘B’ with % WILCARD.

Code:

SELECT Name, Designation, DOJ, Salary FROM Employee WHERE Name LIKE '%E%';

Output:

Oracle WILDCARDS-1.5

In this example, % WILDCARD is being used twice after and before “E”. It means it selects the entries from Name column which consists of ‘E’ character at least once at any position and displays the records.

3. Underscore ( ‘_’) WILDCARD

Code:

SELECT Name, Designation, DOJ, Salary FROM Employee WHERE Designation LIKE '_O%'

Output:

Oracle WILDCARDS-1.6

As underscore (‘_’) WILDCARD represents any single character at the specified position.

So this statement searches the entry in the Designation column which is having the second character ‘O’, but the first character can be anything. And returns the matching pattern as a result.

4. Underscore ( ‘_’) WILDCARD with NOT keyword

Code:

SELECT Name, Designation, DOJ, Salary FROM Employee WHERE Designation NOT LIKE '_O%';

Output:

Output-1.7

So this statement having NOT keyword with WILCARD, which means it searches the entry in the Designation column which does not consist the second character ‘O’, but the first character can be anything. And returns the matching pattern as a result.

5. Drawback of WILDCARDS

Example #1

SELECT Department FROM Dept_Category WHERE Department LIKE '%_%';

Output:

Output-1.8

The above SELECT statement returns all rows from the Dept_Category table but the expected result was the record(s) which consists only ‘_’ character because of the WILDCARD condition. So it’s the wrong output.

Example #2

SELECT deptno, dname, loc FROM Dept WHERE dname LIKE ‘%%%’;

Output:

Output-1.9

The above SELECT statement returns all rows from the Dept_Category table but the expected result was the record(s) which consists only ‘%’ character because of the WILDCARD condition. So it’s the wrong output.

There are two questions arise:

Why this issue occurred when we used correct syntax in the above two examples?

  • In the above two examples, Oracle Optimizer considers _ & % as a WILDCARD, not a character.

How to fix this problem?

  • To fix this issue/drawback Oracle provides ESCAPE Clause.

ESCAPE Clause: ESCAPE clause is used to find the exact match for ‘_’ & ‘%’ as a character. ESCAPE clause has to be used along with ‘\’.

6. Underscore (‘_’) WILDCARD with ESCAPE Clause

Code:

SELECT Department FROM Dept_Category WHERE Department LIKE '%\_%' ESCAPE ‘\’;

Output:

Output-1.10

In the above example, Oracle optimizer considers ‘_’ as a character, not as a WILDCARD because of the ESCAPE clause. And it returns the expected result.

7. Underscore (‘%’) WILDCARD with ESCAPE Clause

Code:

SELECT Department FROM Dept_Category WHERE Department LIKE '%\%%' ESCAPE ‘\’;

Output:

Output-1.11

In the above example, Oracle optimizer considers ‘%’ (second from left) as a character, not as a WILDCARD because of the ESCAPE clause. And it returns the expected result.

Note: The keywords @, $, &, ^, ? Etc. can be used instead of ‘\’ with escape option to pass the WILDCARDS symbol as a character in a SQL query to get the exact match.

  • For Case sensitive character search, character function (UPPER, LOWER or INITCAP) can be used with WILDCARDS

Code:

SELECT Department, State FROM Dept_Category WHERE Department LIKE UPPER ('%^%ra%') ESCAPE '^';

Output:

Oracle WILDCARDS-1.12

  • Logical operator (AND, OR) can be used for multiple WILDCARD conditions

Code:

SELECT Department, State FROM Dept_Category WHERE LOWER (Department) LIKE ('%^%ra%') ESCAPE '^' OR  LOWER (Department) LIKE ('%!_de%') ESCAPE '!';

Output:

Oracle WILDCARDS-1.13

Note: In this case, query performance can be poor if the Table is big.

Oracle WILDCARDS can be applied to any data type.

Conclusion

Oracle WILDCARDS are keyword or symbol which enables us for character pattern matching operation on any data type column. Oracle WILDCARDS is a good option to find the record(s) in the scenario where we don’t have the exact content of the column.

Recommended Articles

This is a guide to Oracle WILDCARDS. Here we discuss the Introduction and the different wildcards in oracle along with different examples and its code implementation. You may also have a look at the following articles to learn more –

  1. Introduction to Oracle LIKE Operator
  2. Features & Types of Wildcards in MySQL
  3. How does Full Outer Join Work?
  4. BETWEEN in Oracle
  5. Guide to Oracle Window Functions
  6. Oracle While Loop | How to Works?
Popular Course in this category
Oracle Training (14 Courses, 8+ Projects)
  14 Online Courses |  8 Hands-on Projects |  120+ Hours |  Verifiable Certificate of Completion
4.5
Price

View Course

Related Courses

Oracle DBA Database Management System Training (2 Courses)4.9
All in One Financial Analyst Bundle- 250+ Courses, 40+ Projects4.8
0 Shares
Share
Tweet
Share
Primary Sidebar
Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Live Classes
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Database Management
  • Machine Learning
  • All Tutorials
Certification Courses
  • All Courses
  • Data Science Course - All in One Bundle
  • Machine Learning Course
  • Hadoop Certification Training
  • Cloud Computing Training Course
  • R Programming Course
  • AWS Training Course
  • SAS Training Course

ISO 10004:2018 & ISO 9001:2015 Certified

© 2022 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA
Free Data Science Course

SPSS, Data visualization with Python, Matplotlib Library, Seaborn Package

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA Login

Forgot Password?

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA
Free Data Science Course

Hadoop, Data Science, Statistics & others

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

Let’s Get Started

By signing up, you agree to our Terms of Use and Privacy Policy.

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more