Functions in SQL: Manipulating Strings : String Function « String « SQL / MySQL

SQL / MySQL
1. Backup Load
2. Command MySQL
3. Cursor
4. Data Type
5. Database
6. Date Time
7. Flow Control
8. Function
9. Insert Delete Update
10. Join
11. Key
12. Math
13. Procedure Function
14. Select Clause
15. String
16. Table Index
17. Transaction
18. Trigger
19. User Permission
20. View
21. Where Clause
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / C Sharp
C# / CSharp Tutorial
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
SQL / MySQL » String » String Function 
Functions in SQL: Manipulating Strings

/*

mysql> Select * from StudentExam;
+-----------+------+------------+
| StudentID | Mark | Comments   |
+-----------+------+------------+
|        10 |   46 | Java       |
|        10 |   65 | C#         |
|        10 |   79 | JavaScript |
|        11 |   66 | Java       |
|        11 |   85 | C#         |
|        11 |   99 | JavaScript |
+-----------+------+------------+
6 rows in set (0.00 sec)

mysql> /* Real command */
mysql> SELECT
    ->    CONCAT(RIGHT(Name, LENGTH(Name- INSTR(Name, ' '1),
    ->           ', ', LEFT(Name, INSTR(Name, ' '1))
    ->    AS StudentName
    -> FROM Student
    -> ORDER BY StudentName;
+---------------+
| StudentName   |
+---------------+
|  But, Cory    |
|  Harvests, JJ |
|  Yin, Joe     |
+---------------+
rows in set (0.04 sec)


*/

/* Prepare the data */ 
DROP TABLE Student;

CREATE TABLE Student (
   StudentID INT NOT NULL PRIMARY KEY,
   Name      VARCHAR(50NOT NULL
)TYPE = InnoDB;


/* Insert data for testing */ 
INSERT INTO Student (StudentID,NameVALUES (1,'Joe Yin');
INSERT INTO Student (StudentID,NameVALUES (2,'Cory But');
INSERT INTO Student (StudentID,NameVALUES (3,'JJ Harvests');

Select * from StudentExam;

  
/* Real command */
SELECT
   CONCAT(RIGHT(Name, LENGTH(Name- INSTR(Name, ' '1),
          ', ', LEFT(Name, INSTR(Name, ' '1))
   AS StudentName
FROM Student
ORDER BY StudentName;

           
       
Related examples in the same category
1. Using String Functions in Your SQL Statements
w_w___w___.__j_a_v_a2___s_.__c___o___m___ | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.