Solved

Long data type

Posted on 2004-10-11
6
2,365 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
6 Comments
 
LVL 3

Expert Comment

by:jaramill
Comment Utility
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
Comment Utility
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 20 total points
Comment Utility
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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 4

Assisted Solution

by:Vinay_dba
Vinay_dba earned 20 total points
Comment Utility
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 60 total points
Comment Utility
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
 
LVL 10

Expert Comment

by:SDutta
Comment Utility
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

Truncate is a DDL Command where as Delete is a DML Command. Both will delete data from table, but what is the difference between these below statements truncate table <table_name> ?? delete from <table_name> ?? The first command cannot be …
Cursors in Oracle: A cursor is used to process individual rows returned by database system for a query. In oracle every SQL statement executed by the oracle server has a private area. This area contains information about the SQL statement and the…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
This video explains what a user managed backup is and shows how to take one, providing a couple of simple example scripts.

763 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

14 Experts available now in Live!

Get 1:1 Help Now