Thursday, 21 February 2013

How to restrict the length of a field in a SELECT query

I was writing the MINUS query, 
In source table the length of the column was 300 characters and in target the length was trimmed to 60 characters.

So here is the solution:



In MYSQL Data Base:
 
SELECT LastName, SUBSTRING(FirstName, 0, 6) AS FIRSTNAME FROM Person.Person

In oracle the syntax is :

SELECT LASTNAME, SUBSTR(FIRSTNAME, 0, 6) AS FIRSTNAME FROM PERSON.PERSON


These queries will restrict the length of the field to 6 characters.
You can modify it as per your convenience.

These two queries are working and have been tested.
 
Suggestions are welcome on this.

No comments:

Post a Comment