Home » RDBMS Server » Server Administration » How do I insert data into LONG column
How do I insert data into LONG column [message #370611] Thu, 06 January 2000 14:15 Go to next message
Chris
Messages: 128
Registered: November 1998
Senior Member
I have a table with 2 columns (ID and DESCRIPTION). Description is a Long column. When I do the following SQL command I get an error:

INSERT into cr_description values (29, 'really long string');

The 'really long string' is about 6MB and more than 2000 characters. When I execute this SQL statement I get oracle error: ORA-01704: string literal too long
The help on this error says that INSERT can only have 2000 characters. Is there a way to INSERT more than 2000 characters into a table?
Re: How do I insert data into LONG column [message #370612 is a reply to message #370611] Thu, 06 January 2000 16:47 Go to previous messageGo to next message
jaramill
Messages: 10
Registered: January 2000
Location: Glendale, AZ
Junior Member
You can't do this in a "naked" SQL statement. It has to be done inside/wrapped in a PL/SQL procedure or anonymous block. Here's the code to do it. Hope it helps.

CREATE OR REPLACE PROCEDURE Insert_Long AS

v_SQLCODE PLS_INTEGER;
v_SQLERRM VARCHAR2(512);

v_ID PLS_INTEGER DEFAULT 29;

-- The maxsize for a VARCHAR2 is 32767
-- which ironically is bigger than PL/SQL
-- variable of type LONG

v_description VARCHAR2(32767) := 'really long text';

BEGIN

INSERT INTO cr_description
VALUES (v_ID, v_description);

COMMIT WORK;

EXCEPTION

WHEN OTHERS THEN

v_SQLCODE := SQLCODE;
v_SQLERRM := SQLERRM(v_SQLCODE);

DBMS_OUTPUT.PUT_LINE('OTHER ERROR');
DBMS_OUTPUT.PUT_LINE(v_SQLERRM);

END Insert_Long;

Re: How do I insert data into LONG column [message #370613 is a reply to message #370612] Thu, 06 January 2000 16:52 Go to previous messageGo to next message
jaramill
Messages: 10
Registered: January 2000
Location: Glendale, AZ
Junior Member
Chris:

Also you don't have to declare the PL/SQL variable of type LONG. VARCHAR2 is bigger as I mentioned before. This will work with UPDATES as well. Now you can't go backwards with LONG. Meaning you can't retrieve data in column of type LONG in a table, INTO a PL/SQL variable of type LONG. Simply because a database table column of type LONG can hold gigabytes of data, as opposed to a PL/SQL variable of the same type that can only hold kilobytes of data.

How do I execute pro*C program from pl/sql block [message #371158 is a reply to message #370611] Sat, 09 September 2000 03:13 Go to previous messageGo to next message
Archana Ramamurthy
Messages: 1
Registered: September 2000
Junior Member
How do I execute pro*C program from pl/sql block
Re: How do I execute pro*C program from pl/sql block [message #371602 is a reply to message #370611] Mon, 13 November 2000 00:14 Go to previous message
Bhagat Singh
Messages: 2
Registered: November 2000
Junior Member
Hi Archana Try this one.

/***************************************************************************
* extproc.c Frank Naude, (c) 1999
* Call operating system commands from PL/SQL. www.orafaq.org
***************************************************************************
* Setup:
* 1. Compile this program: cc -G extproc.c -o extproc.so
* 2. SQL> create library shell_lib as '/app/oracle/local/extproc.so';
* 3. SQL> create or replace function sysrun (syscomm in varchar2)
* return binary_integer
* as language C -- Use "as external" in older releases
* name "sysrun"
* library shell_lib
* parameters(syscomm string);
* /
* 4. Run $ORACLE_HOME/bin/extproc to make sure it is executable.
* 5. Define TNSNAMES.ORA entry:
* EXTPROC_CONNECTION_DATA = (DESCRIPTION =
* (ADDRESS=(PROTOCOL=IPC)(KEY=extproc))
* (CONNECT_DATA=(SID=extproc)))
* 6. Define LISTENER.ORA entry and reload listener:
* EXTERNAL_PROCEDURE_LISTENER =
* (ADDRESS_LIST=(ADDRESS=(PROTOCOL=IPC)(KEY=extproc)))
* SID_LIST_EXTERNAL_PROCEDURE_LISTENER =
* (SID_LIST=(SID_DESC=(SID_NAME=extproc)
* (ORACLE_HOME=/app/oracle/ORA815)(PROGRAM=extproc)))
* 7. Execure an OS command:
* PL/SQL> declare
* rc number;
* begin
* rc := sysrun('/bin/ls -l');
* dbms_output.put_line('Return Code='||rc);
* end;
* /
*
* Notes:
* 1. When running shell-scripts, it will have very few variables defined
* (like cron). Remember to set everything - $PATH, etc.
* 2. Rewrite this program unsing C Piping to capture command output.
* See popen() function.
* 3. Steps to make the Oracle provided examples:
* $ cd $ORACLE_HOME/plsql/demo
* $ make -f demo_plsql.mk extproc.so
*
*/

int sysrun(char *command)
{
return system(command);
}


Previous Topic: Find maximum value without using max function
Next Topic: DBMS_JOB
Goto Forum:
  


Current Time: Thu May 02 17:15:35 CDT 2024