You may be running Oracle 10g Release 2, but the applications you're supporting may have been written much earlier. Tables developed in versions of Oracle prior to 8i often used the LONG datatype to store large amounts of text.

With the introduction of Large Object (LOB) datatypes, the LONG and LONG RAW datatypes were deprecated. If you need to make a copy of a table that uses LONG, the CREATE TABLE AS SELECT syntax won't work; you'll get this error: ORA-00997: illegal use of LONG datatype.

You could export the table and import it, but that's a lot of work. The COPY command in SQL*Plus can still copy such a table with a single command. Here is the format of COPY (note the use of the continuation character, -, to break up the line):

COPY FROM user/pw@dblink TO user/pw@dblink CREATE tablename -

USING select-statement;

Be sure to use SET LONG first to cover the length of the data in the LONG column and avoid truncated data.

The downside is that the COPY command was frozen in functionality at version 8.0 of Oracle. It can only copy tables consisting of the following datatypes: CHAR, DATE, LONG, NUMBER, and VARCHAR2. New datatypes added in versions 8i and later are not supported. This is purely a legacy solution.

The code below shows the CREATE TABLE error and the successful COPY command.

SQL> CREATE TABLE my_views AS
  2     SELECT * FROM user_views;
   SELECT * FROM user_views
          *
ERROR at line 2:
ORA-00997: illegal use of LONG datatype



SQL> SET LONG 100000
SQL> COPY FROM hr/hr@orcl CREATE my_views -
>USING select * from user_views;

Array fetch/bind size is 15. (arraysize is 15)
Will commit when done. (copycommit is 0)
Maximum long size is 100000. (long is 100000)
Table MY_VIEWS created.

   1 rows selected from hr@orcl.
   1 rows inserted into MY_VIEWS.
   1 rows committed into MY_VIEWS at DEFAULT HOST connection.

SQL> descmy_views;
 Name                                      Null?    Type
 ----------------------------------------- -------- ----------------------------
 VIEW_NAME                                 NOT NULL VARCHAR2(30)
 TEXT_LENGTH                                        NUMBER(38)
 TEXT                                               LONG
 TYPE_TEXT_LENGTH                                   NUMBER(38)
 TYPE_TEXT                                          VARCHAR2(4000)
 OID_TEXT_LENGTH                                    NUMBER(38)
 OID_TEXT                                           VARCHAR2(4000)
 VIEW_TYPE_OWNER                                    VARCHAR2(30)
 VIEW_TYPE                                          VARCHAR2(30)
 SUPERVIEW_NAME                                     VARCHAR2(30)

SQL> spool off

Database Jumping This was published in Database Jumping, check every Thursday for more stories

Comments

1

sushil.raman - 01/02/09

Really it very good for us .thiat mean's for student

» Report offensive content

2

OWOADE NIHINLOLA - 20/02/09

IN FACT, YOU PEOPLE ARE WONDERFUL.

» Report offensive content

Leave a comment

You must read and type the 6 chars within 0..9 and A..F

* indicates mandatory fields.

2

OWOADE NIHINLOLA - 20/02/09

IN FACT, YOU PEOPLE ARE WONDERFUL. ... more

1

sushil.raman - 02/01/09

Really it very good for us .thiat mean's for student ... more

Log in


Sign up | Forgot your password?

  • Staff Aussies to pay more for Win 7

    If you are looking to make some money in these troubled times, perhaps importing copies of Windows 7 could be for you. Read more »

    -- posted by Staff

  • Staff Firefox: Greens want it, 3.5rc2 not up to par

    This week's roundup looks at the situation surrounding a campaign to change Outlook HTML renderer, a Greens MP wants to install Firefox but is restricted and all the photos from the iPhone 3GS launch. Read more »

    -- posted by Staff

  • Chris Duckett Microsoft misses the Outlook point

    Ask designers which mail program is the bane of their existence, and you'll find that Outlook tops the list. The reason why the most popular email reader is also the most painful is simple: it uses Word to render HTML emails. Read more »

    -- posted by Chris Duckett

What's on?