Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Copying data from varchar to blob field

Posted on 2003-12-11
6
Medium Priority
?
1,321 Views
Last Modified: 2013-12-09
Hi,

I need to change a field's data type from varchar to blob, while retaining the data. I'm following the 6-step procedure (which I've also read from this site)

1. create temp varchar
2. copy data from original varchar to temp column
3. drop original varchar
4. create blob field
5. copy data from temp varchar to blob
6. drop temp varchar

I am having problem with step 5. Copying data from varchar to blob is not as straightforward as using an Update statement. I know I should be using blob cursor, and I've already gathered sql statements to create & insert record to blob field. But what's missing is how to iterate through all the records. And the sql statements are not executing successfully (I'm using IBExpert)

DECLARE blob_cur CURSOR FOR
INSERT BLOB description INTO pr_product;

OPEN blob_cur INTO description;

INSERT CURSOR blob_cur VALUES (temp_desc);

CLOSE blob_cur;


Thanks for your time,

estela : )
0
Comment
Question by:emayuga
[X]
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
  • 3
6 Comments
 
LVL 6

Accepted Solution

by:
BAlexandrov earned 520 total points
ID: 9926567
I feel that you need to read this article:

http://www.volny.cz/iprenosil/interbase/ip_ib_strings.htm

Best Regards
Bojidar Alexandrov
0
 
LVL 6

Expert Comment

by:BAlexandrov
ID: 9926657
If you use Firebird you can do directly
"update my_table set blob_collumn = varchar_collumn"
Next is an example of stored procedure that you can alter to your needs.
If we have this table:

CREATE TABLE NEW_TABLE (
    ID     INTEGER NOT NULL,
    PRICE  NUMERIC(15,2),
    CODE   INTEGER,
    BL     BLOB SUB_TYPE 2 SEGMENT SIZE 4096,
    VAR    VARCHAR(100)
);

ALTER TABLE NEW_TABLE ADD PRIMARY KEY (ID);

And you want to copy var collumn to bl collumn

CREATE PROCEDURE NEW_PROCEDURE
AS
  declare variable var_temp varchar(100);
  declare variable id int;
begin
  for Select id,var from new_table
  into :id,:var_temp
  do
  Begin
    update new_table set  bl = :var_temp where id = :id;
  end
end

Then execute it
0
 

Author Comment

by:emayuga
ID: 9927080
Unfortunately, I am just using IB6..
Thanks for the sample script : )
However, I am encountering an error in declaring a blob cursor. Maybe you can help with this one too..

I have a PR_PRODUCT table containing the ff. fields:
  ID  INTEGER NOT NULL,
  Description  BLOB,
  Temp_Desc VARCHAR(125),

Here's the procedure:

CREATE PROCEDURE Populate_Prod_Desc
AS
  declare variable var_temp varchar(125);
  declare variable id int;
  declare blob_cur cursor for
  insert blob description into pr_product;

begin
  open blob_cur into description;
  for Select id, temp_desc from pr_product
  into :id, :var_temp
  do
  Begin
    insert cursor blob_cur values (:var_temp) where id = :id;
  end
  close blob_cur;
end

I am encountering the error "Token Unknown - line 5, char 9. blob_cur" when executing this statement. There's probably something wrong with the syntax...?

Thanks,
estela : )
0
 
LVL 6

Expert Comment

by:BAlexandrov
ID: 9927180
I totally cannot understand what you are trying to do... :(


Plase read the manuals about working with cursors
0
 
LVL 10

Expert Comment

by:kacor
ID: 10341127
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area for this question:
       to accept BAlexandrov's answer
Please leave any comments here within the next four (4) days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

If you will get a useful answer to your newer question next time, please accept it after evaluating. By this way the experts will get sooner his expert points for supporting you. If you have question about, please look at  http://www.experts-exchange.com/help.jsp.

kacor
EE Cleanup Volunteer
0

Featured Post

Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

Question has a verified solution.

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

This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
In today's business world, data is more important than ever for informing marketing campaigns. Accessing and using data, however, may not come naturally to some creative marketing professionals. Here are four tips for adapting to wield data for insi…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

662 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