Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Mailing Lists -> Oracle-L -> RE: Dynamic select query

RE: Dynamic select query

From: Ofer Harel <oharel_at_barak013.net.il>
Date: Tue, 17 Dec 2002 03:28:46 -0800
Message-ID: <F001.0051AFEA.20021217032846@fatcity.com>


You should use the INSTR function

INSTR(string,substring,[position],[occurrence])

INSTR searches string for substring.
position is an integer indicating the character of string where Oracle begins the search. If position is negative, Oracle counts and searches backward from the end of string.
occurrence is an integer indicating which occurrence of string Oracle should search for. The value of occurrence must be positive. The function returns an integer indicating the position of the character in string that is the first character of this occurrence. The default values of both position and occurrence are 1, meaning Oracle begins searching at the first character of string for the first occurrence of substring. The return value is relative to the beginning of string, regardless of the value of position, and is expressed in characters. If the search is unsuccessful (if substring does not appear occurrence times after the position character of string) the return value is 0.

Examples:
SELECT INSTR('CORPORATE FLOOR','OR', 3, 2)   "Instring" FROM DUAL;  

  Instring


        14

select *
  from shipment
 where instr(ship_name,ship_id)>0;

HTH
regards

Ofer Harel
DBA team
Barak ITC
oharel_at_barak013.net.il

-----Original Message-----
[mailto:Ranganath.Krishnaswamy_at_blr.hpsglobal.com] Sent: Tuesday, December 17, 2002 12:39 PM To: Multiple recipients of list ORACLE-L

Hi all,

        I have a table by name shipment with two columns say ship_id and ship_name and data as follows:

SHIP_ID	SHIP_NAME
------------- 	-------------------
ABC 		1ABCLMN
XYZ 		23XYZ1112
ABB 		123LM

	I want to select all the columns in shipment table which has ship_id
as string in the ship_name column. For example, ship_id 'ABC' is present in '1ABCLMN'. So that record should be selected. The ship_id string may start from any position and end at any position in ship_name column. So I cannot use the substr function in this case. How do I write the select clause for this requirement?

        Any help in this regard is very much appreciated.

Thanks and Regards,

Ranganath
WARNING: The information in this message is confidential and may be legally privileged. It is intended solely for the addressee. Access to this message by anyone else is unauthorised. If you are not the intended recipient, any disclosure, copying, or distribution of the message, or any action or omission taken by you in reliance on it, is prohibited and may be unlawful. Please immediately contact the sender if you have received this message in error. Thank you.
--

Please see the official ORACLE-L FAQ: http://www.orafaq.com
--

Author: Krishnaswamy, Ranganath
  INET: Ranganath.Krishnaswamy_at_blr.hpsglobal.com

Fat City Network Services    -- 858-538-5051 http://www.fatcity.com
San Diego, California        -- Mailing list and web hosting services
---------------------------------------------------------------------
To REMOVE yourself from this mailing list, send an E-Mail message to: ListGuru_at_fatcity.com (note EXACT spelling of 'ListGuru') and in the message BODY, include a line containing: UNSUB ORACLE-L (or the name of mailing list you want to be removed from). You may also send the HELP command for other information (like subscribing).
--

Please see the official ORACLE-L FAQ: http://www.orafaq.com
--

Author: Ofer Harel
  INET: oharel_at_barak013.net.il
Fat City Network Services    -- 858-538-5051 http://www.fatcity.com
San Diego, California        -- Mailing list and web hosting services
---------------------------------------------------------------------
To REMOVE yourself from this mailing list, send an E-Mail message to: ListGuru_at_fatcity.com (note EXACT spelling of 'ListGuru') and in the message BODY, include a line containing: UNSUB ORACLE-L (or the name of mailing list you want to be removed from). You may also send the HELP command for other information (like subscribing). Received on Tue Dec 17 2002 - 05:28:46 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US