Usman Farooq
Usman Farooq

Reputation: 123

How can i limit the output of select statement for a varchar column in Oracle?

i have a table in which i store the information (product id and description ) of all my products, description column is of type VarChar2(200). i want to format the output of this column in select statement to only result me specific part of output string. E.G Here is my simple select statement:

Select PRODUCTId, PRODUCT_DESC From ProductTable Order By PRODUCTId Desc;

this statement result me the output as:

ProductId            Product_Desc
1                    Oxford English-Oxford-Oxford Press-Textbook

now i want only the specific part of the output result from product_description column. i have already checked Trim() function but that did not helped me. can someone help me?

Upvotes: 0

Views: 236

Answers (2)

praveen_mora
praveen_mora

Reputation: 34

You can use SUBSTR() function. You can provide start and end position for the product_desc column.

The query should be like:

Select product_id,substr(product_desc,2,4) from producttable;

Here you'll get 4 chars from the second one.

Upvotes: 0

XtremeBytes
XtremeBytes

Reputation: 1497

A substring function may help.

SELECT SUBSTR('ABCDEFG',3,4) "Substring" FROM DUAL;

Upvotes: 1

Related Questions