Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Issue with MySQL VIEW column size

Posted on 2009-04-13
6
384 Views
Last Modified: 2013-12-12
Hi,

I have Product table with columns prod_id int(11),category_id int(11),prod_name varchar(255) and prod_quantity varchar(255).
I am creating VIEW in MySQL using above table  and following syntax:

CREATE OR REPLACE VIEW product_view AS
SELECT
 category_id,
 CONCAT("#",GROUP_CONCAT(CONCAT_WS('=',prod_name,prod_quantity) SEPARATOR '#'),"#") AS product_quantity_values

FROM
 product
GROUP BY category_id

Now when i describe VIEW then the column size of VIEW COLUMN "product_quantity_values" shows varchar(343). So this view only allow me to store 343 characters in COLUMN "product_quantity_values" . More than that are truncated.

Is there any way to avoid such behavior? I want the VIEW COLUMN "product_quantity_values" should store more characters.

0
Comment
Question by:teenashah
  • 3
  • 3
6 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 24128586
please try this:
CREATE OR REPLACE VIEW product_view AS
SELECT
 category_id,
 cast(CONCAT("#",GROUP_CONCAT(CONCAT_WS('=',prod_name,prod_quantity) SEPARATOR '#'),"#") AS product_quantity_values as VARCHAR(65000)) 
FROM 
 product 
GROUP BY category_id

Open in new window

0
 

Author Comment

by:teenashah
ID: 24128719
Hi angelIII,

Its giving a error:

Error Code : 1064
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AS fproduct_quantity_values as VARCHAR(65000))

BTW: I am using MySQL 5
0
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 24128828
sorry,...
CREATE OR REPLACE VIEW product_view AS
SELECT
 category_id,
 cast(CONCAT("#",GROUP_CONCAT(CONCAT_WS('=',prod_name,prod_quantity) SEPARATOR '#'),"#") as VARCHAR(65000))  AS product_quantity_values 
FROM  product 
GROUP BY category_id

Open in new window

0
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 

Author Comment

by:teenashah
ID: 24129011
Sorry angelIII,

Same error again.

Error Code : 1064
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'VARCHAR(65000)) AS
0
 

Author Comment

by:teenashah
ID: 24135661
Hi,

Above issue has been resolved.

MySQL 5 CAST function allows type as CHAR Not VARCHAR.

But thanks for giving way to tackle situation.
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 24136813
I see, glad I could help.
so, please, close the question.
a3
0

Featured Post

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
Creating and Managing Databases with phpMyAdmin in cPanel.
This video shows how to Export data from an Oracle database using the Original Export Utility.  The corresponding Import utility, which works the same way is referenced, but not demonstrated.
This video shows how to configure and send email from and Oracle database using both UTL_SMTP and UTL_MAIL, as well as comparing UTL_SMTP to a manual SMTP conversation with a mail server.

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question