?
Solved

Long data type

Posted on 2004-10-11
6
Medium Priority
?
2,377 Views
Last Modified: 2008-01-09
I'm reiterrating the same question one more time, since I didn't get the exact answer in a first place...
I've been advised to use clob datatype instead of long and I agree from the technical point, however, in my specific case I need to to generate Long field with at least 8mb for !!!testing purposes!!!

I'm trying to use pl/sql for data manipulation (reading input table and inserting/updating output tables)...
My issue is that there are differences in datatypes between  pl/sql "LONG"  and an Oracle table column.  The PL/SQL can hold up to 32760 bytes while long in oracl table allows to store 2gb.
Please reply with a working solution...
0
Comment
Question by:smena
[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
6 Comments
 
LVL 3

Expert Comment

by:jaramill
ID: 12282898
So let me understand what you want to do as your questions is vague and you're not asking for something specific.  You want to "read" from a database table that has a column of "LONG" type and want to manipulate at least 8MB of data within your PL/SQL code, then insert and update to another database table that has a column of "LONG" type.  Is this correct?

Gio
0
 

Author Comment

by:smena
ID: 12283099
Let me try to clarify what my case scenario should be:
1. I need to create a table where one of the column defined as LONG
2. I need to create a test data and insert 8mb data into this column
3. Read this table in PL/SQL, get this columns and try to a) update or b) search for some specific value


I may have the following scenario
input table1
col1-key integer
col2 varchar2
col3 varchar2
col4 long

col4 - should have at least one row with data 8mb

I have to update/insert table2 (output) using table1 that defined as
col1-key integer
col2  long

hopefully it helps.
thnak you
0
 
LVL 9

Accepted Solution

by:
konektor earned 60 total points
ID: 12284460
there are more differences between maximal length of datatypes in SQL and PL/SQL. eg.
raw and warchar can have length up to 2000/4000 in SQL (columns in tables may have max 2000/4000), but the same types in PL/SQL can have up to 32767 - this is better case, u can have more in pl/sql than sql :-)
but back to your question ...
convert long datatypes to lobs (blob, or clob). the easiest way how to do it is using :
insert into tmp_table (pk_colummn, clob_col) select pk_column, to_lob(long_col) from your_table
alter table your_table drop colum long_col
alter table your_table add new_col clob
ude dbms_lob.copy function to move content of clobs to original table
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 4

Assisted Solution

by:Vinay_dba
Vinay_dba earned 60 total points
ID: 12288150
You can use DBMS_SQL for this task.
Check the example.

CREATE TABLE emp
  2  (
  3    emp_id NUMBER CONSTRAINT emp_pk PRIMARY KEY,
  4    lname VARCHAR2(12),
  5    fname VARCHAR2(12),
  6    job_descr LONG
  7  );

CREATE OR REPLACE FUNCTION long_to_varchar2 (empID NUMBER)
  2  RETURN VARCHAR2 IS
  3  
  4     varcharVal VARCHAR2(4000);
  5     varcharLength NUMBER;
  6     cur PLS_INTEGER := DBMS_SQL.OPEN_CURSOR;
  7     fetchIt PLS_INTEGER;
  8  
  9  BEGIN
 10  
 11      DBMS_SQL.PARSE
 12         (cur,'SELECT job_descr FROM emp WHERE emp_id = '||empId, DBMS_SQL.NATIVE);
 13  
 14     DBMS_SQL.DEFINE_COLUMN_LONG(cur,1);
 15  
 16     fetchIt := DBMS_SQL.EXECUTE_AND_FETCH(cur);
 17  
 18     DBMS_SQL.COLUMN_VALUE_LONG(cur,1,4000,0,varcharVal,varcharLength);
 19  
 20     DBMS_SQL.CLOSE_CURSOR(cur);
 21  
 22     RETURN varcharVal;
 23  
 24  END;
 25  /
0
 
LVL 10

Assisted Solution

by:SDutta
SDutta earned 180 total points
ID: 12288313
You cannot insert long columns more than 32760 characters in PL/SQL - no way. To do that you would have to write a program in PRO*C or OCI. Long raw documents can also be loaded using IMPORT or SQL*LOADER.

Oracle has no built in functions or operators that handles LONG data and this datatype has been deprecated. Whatever you are trying to do with LONG can be done much more easily with a CLOB datatype, but I guess you already know that.

If it is just for testing you can test it with a 32K long, here is the code :

create table testlong(col1 number, col2 long);

set serveroutput on
declare
v_char varchar2(32767);
v_long long;
v_size number;
begin
for i in 1..32760 loop
v_char:=v_char||'X';
end loop;
dbms_output.put_line('Testing Long Insert');
v_long := v_char;
v_size := length(v_char);
insert into testlong values (v_size, v_long);
commit;
dbms_output.put_line('Wrote long record of size = ' || v_size);
end;
/
0

Featured Post

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them.

Question has a verified solution.

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

This article started out as an Experts-Exchange question, which then grew into a quick tip to go along with an IOUG presentation for the Collaborate confernce and then later grew again into a full blown article with expanded functionality and legacy…
This post first appeared at Oracleinaction  (http://oracleinaction.com/undo-and-redo-in-oracle/)by Anju Garg (Myself). I  will demonstrate that undo for DML’s is stored both in undo tablespace and online redo logs. Then, we will analyze the reaso…
Via a live example show how to connect to RMAN, make basic configuration settings changes and then take a backup of a demo database
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.
Suggested Courses

764 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