Solved

Copying data from varchar to blob field

Posted on 2003-12-11
6
1,204 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
  • 3
6 Comments
 
LVL 6

Accepted Solution

by:
BAlexandrov earned 130 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
This article explains all about SQL Server Piecemeal Restore with examples in step by step manner.
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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

744 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now