MYSQL has no explode()
like function built in. But you can easily add similar function to your DB and then use it from php queries. That function will look like:
CREATE FUNCTION SPLIT_STRING(str VARCHAR(255), delim VARCHAR(12), pos INT) RETURNS VARCHAR(255) RETURN REPLACE(SUBSTRING(SUBSTRING_INDEX(str, delim, pos), CHAR_LENGTH(SUBSTRING_INDEX(str, delim, pos-1)) + 1), delim, '');
Usage:
SELECT SPLIT_STRING('apple, pear, melon', ',', 1)
The example above will return apple
. I think that it will be impossible to return array in MySQL so you must specify which occurrence to return explicitly in pos
. Let me know if you succeed using it.
Related Posts:
- MySQL Error: : ‘Access denied for user ‘root’@’localhost’
- Unknown column in ‘field list’ error on MySQL Update query
- Unknown column in ‘field list’ error on MySQL Update query
- MySQL – Operand should contain 1 column(s)
- MySQL “CREATE TABLE IF NOT EXISTS” -> Error 1050
- MySQL Error: : ‘Access denied for user ‘root’@’localhost’
- MySQL create table if not exists and insert record only if table was created
- How do I use properly CASE..WHEN in MySQL
- How can I do a FULL OUTER JOIN in MySQL?
- MySQL query String contains
- What’s the difference between VARCHAR and CHAR?
- Case statement in MySQL
- How to declare a variable in MySQL?
- MySQL Cannot Add Foreign Key Constraint
- How to split the name string in mysql?
- How do I import an SQL file using the command line in MySQL?
- Can’t connect to local MySQL server through socket ‘/tmp/mysql.sock’ (2)
- mysql Foreign key constraint is incorrectly formed error
- MySQL: Invalid use of group function
- How can I return pivot table output in MySQL?
- Compare dates in MySQL
- MySQL “WITH” clause
- MySQL Multiple Joins in one query?
- Error Code: 2013. Lost connection to MySQL server during query
- MySQL syntax for Join Update
- Can’t connect to local MySQL server through socket ‘/tmp/mysql.sock’ (2)
- how to drop partition without dropping data in MySQL?
- MySQL combine two columns into one column
- Simple way to calculate median with MySQL
- Error 1046 No database Selected, how to resolve?
- MySQL Error 1264: out of range value for column
- Remove duplicate rows in MySQL
- How to SUM and SUBTRACT using SQL?
- Cast from VARCHAR to INT – MySQL
- SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax — PHP — PDO [duplicate]
- How do you force mysql LIKE to be case sensitive?
- MySQL – UPDATE multiple rows with different values in one query
- How to create a MySQL hierarchical recursive query?
- ERROR 1148: The used command is not allowed with this MySQL version
- Insert into a MySQL table or update if exists
- How to round down to nearest integer in MySQL?
- MySQL starts with searching issue
- Query to convert from datetime to date mysql
- Is it possible to GROUP BY multiple columns using MySQL?
- MySQL error: key specification without a key length
- Best way to test if a row exists in a MySQL table
- Check if MySQL table exists without using “select from” syntax?
- MySQL equivalent of DECODE function in Oracle
- mysql update column with value from another table
- The used SELECT statements have a different number of columns
- How to delete from multiple tables in MySQL?
- MySQL: Can’t create table (errno: 150)
- How to copy a row and insert in same table with a autoincrement field in MySQL?
- Join vs. sub-query
- Alternative to except in MySQL
- ROW_NUMBER() in MySQ
- MySQL OPTIMIZE all tables?
- MySQL INSERT INTO table VALUES.. vs INSERT INTO table SET
- MySQL – Get row number on select
- MySQL error: Unknown column in ‘where clause’
- How to truncate the text returned for a column in a MySQL query
- Using union and order by clause in mysql
- MySQL LIKE IN()?
- how to fix oracle ORA-01722 invalid number error
- What’s the difference between INNER JOIN, LEFT JOIN, RIGHT JOIN and FULL JOIN? [duplicate]
- SQL SELECT WHERE field contains words
- NOT IN vs NOT EXISTS
- ORA-00979 not a group by expression
- T-SQL split string based on delimiter
- Finding duplicate values in a SQL table
- How do I restore a dump file from mysqldump?
- Difference between JOIN and INNER JOIN
- What is the difference between JOIN and UNION?
- “CASE” statement within “WHERE” clause in SQL Server 2008
- Column ‘user_id’ in field list is ambiguous
- 1052: Column ‘id’ in field list is ambiguous
- Oracle – ORA-01489: result of string concatenation is too long [duplicate]
- SQL Server WITH statement
- Bulk load data conversion error (truncation)
- PostgreSQL create table if not exists
- Arithmetic overflow error converting varchar to data type numeric. ’10’ <= 9.00
- Difference between EXISTS and IN in SQL?
- What does * mean in sql?
- Is there a way to list all used/unused WP templates?
- Optimize WordPress Query that take 5 seconds to execute
- How to make WordPress plugin check for database changes and then do something?
- SQL query equivalent to WP User Query
- Moving database with phpMyAdmin
- Size article thumbnails and retrieve them directly from database
- Best Way to Merge a Dev and Live Site to Become a Staging Site?
- Migrating to WordPress Recipe Plugin and Some SQL Issues
- How I can change the condition or compare operator for WP_Query in pre_get_posts
- What does the $posts_join filter join to?
- WP Query – grouping posts by same meta key, adding together values from another key
- Analog category_and (WP) in sql query
- $wpdb post type and term query only works when there are no dashes or spaces in the term slug and title
- get_results() query not working only when entering strings
- export individual posts to text files or a single csv file
- How to get the sum of each post with the same date
- How to dump a Microsoft SQL Server database to a SQL script?