Solved

Copying data from varchar to blob field

Posted on 2003-12-11
6
1,285 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 130 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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Exchnage 2013 Database - Dirty Shutdown 4 101
sql views 3 55
SQL - Update field value based on two other fields in same table. 13 41
Access VBA for Search Engine 7 7
When table data gets too large to manage or queries take too long to execute the solution is often to buy bigger hardware or assign more CPUs and memory resources to the machine to solve the problem. However, the best, cheapest and most effective so…
When it comes to protecting Oracle Database servers and systems, there are a ton of myths out there. Here are the most common.
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…

734 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