Copying data from varchar to blob field

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 : )
emayugaAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

BAlexandrovCommented:
I feel that you need to read this article:

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

Best Regards
Bojidar Alexandrov

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
BAlexandrovCommented:
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
emayugaAuthor Commented:
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 : )
BAlexandrovCommented:
I totally cannot understand what you are trying to do... :(


Plase read the manuals about working with cursors
kacorretiredCommented:
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Databases

From novice to tech pro — start learning today.