Home » SQL & PL/SQL » SQL & PL/SQL » ORA-00997: illegal use of LONG datatype (merged 2) (Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production)
ORA-00997: illegal use of LONG datatype (merged 2) [message #546075] Mon, 05 March 2012 04:05 Go to next message
rahulvb
Messages: 924
Registered: October 2009
Location: Somewhere Near Equator.
Senior Member
I need to find all the partition names below or equal given value.

select  
      partition_name
from
      user_tab_partitions
  where
       table_name = 'RB' and 
       HIGH_VALUE <= 1234


Above Query is giving error "ORA-00997: illegal use of LONG datatype"

Any other alternative ? (I know its because of LONG Datatype of HIGH_VALUE ) ...


Regards,
-RB
Re: ORA-00997: illegal use of LONG datatype (merged 2) [message #546082 is a reply to message #546075] Mon, 05 March 2012 04:38 Go to previous messageGo to next message
Michel Cadot
Messages: 68776
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
I already told you: you have to create a PL/SQL procedure that returns the value as a VARCHAR2.

Regards
Michel
Re: ORA-00997: illegal use of LONG datatype (merged 2) [message #546086 is a reply to message #546082] Mon, 05 March 2012 04:41 Go to previous messageGo to next message
rahulvb
Messages: 924
Registered: October 2009
Location: Somewhere Near Equator.
Senior Member
Michel Cadot wrote on Mon, 05 March 2012 04:38
I already told you: you have to create a PL/SQL procedure that returns the value as a VARCHAR2.

Regards
Michel


When ? am I missing something Michel !!
Re: ORA-00997: illegal use of LONG datatype (merged 2) [message #546089 is a reply to message #546086] Mon, 05 March 2012 04:52 Go to previous messageGo to next message
Michel Cadot
Messages: 68776
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
If it was not you, it was someone else that recently ask for the same thing and then the answer is there. Wink

Something like that:
SQL> create or replace function high_value 
  2    (p_table in varchar2, p_part in varchar2)
  3  return varchar2
  4  is
  5    hv varchar2(32767);
  6  begin
  7    select high_value into hv 
  8    from user_tab_partitions 
  9    where table_name = p_table
 10      and partition_name = p_part;
 11    return hv;
 12  end;
 13  /

Function created.

SQL> col table_name format a18
SQL> col partition_name format a17
SQL> col high_value format a40 trunc
SQL> select table_name, partition_name, 
  2         high_value(table_name, partition_name) high_value
  3  from user_tab_partitions
  4  order by 1, 2
  5  /

TABLE_NAME         PARTITION_NAME    HIGH_VALUE
------------------ ----------------- ----------------------------------------
COMPOSITE_RNG_HASH SALES_2005        TO_DATE(' 2006-01-01 00:00:00', 'SYYYY-M
COMPOSITE_RNG_HASH SALES_2006        TO_DATE(' 2007-01-01 00:00:00', 'SYYYY-M
COMPOSITE_RNG_HASH SALES_2007        TO_DATE(' 2008-01-01 00:00:00', 'SYYYY-M
COMPOSITE_RNG_HASH SALES_2008        TO_DATE(' 2009-01-01 00:00:00', 'SYYYY-M
COMPOSITE_RNG_HASH SALES_FUTURE      MAXVALUE
COMPOSITE_RNG_HASH SALES_PRE05       TO_DATE(' 2005-01-01 00:00:00', 'SYYYY-M
SYSTEMLOG          HIGHTIME          MAXVALUE
SYSTEMLOG          OCT2007_07        20071007
SYSTEMLOG          OCT2007_14        20071014
SYSTEMLOG          OCT2007_21        20071021
SYSTEMLOG          OCT2007_28        20071027
T                  P1                100
T                  P2                MAXVALUE
TB_HXL_LIST_PART   P_1               1
TB_HXL_USER_SPLIT  HXL_USER_20111001 TO_DATE(' 2011-10-02 00:00:00', 'SYYYY-M

Regards
Michel
Re: ORA-00997: illegal use of LONG datatype (merged 2) [message #546241 is a reply to message #546089] Mon, 05 March 2012 22:36 Go to previous messageGo to next message
rahulvb
Messages: 924
Registered: October 2009
Location: Somewhere Near Equator.
Senior Member
Thanks Michel

As I need to use this in procedure and I need to have the high value in where clause I came up with following Approach.



CREATE GLOBAL TEMPORARY TABLE GTT_COMMON (ATTR1 VARCHAR2(100), ATTR2 VARCHAR2(4000));

   FOR a in (  SELECT  partition_name, HIGH_VALUE from user_tab_partitions  where table_name = 'XYZ')
    LOOP
      insert into GTT_COMMON values(a.partition_name, A.HIGH_VALUE );
   END LOOP;
   END;
  /

ATTR1        ATTR2
------------ --------------
P_MAX        MAXVALUE
P_20120305   1330961409000
P_20120302   1330702209000
P_20120301   1330615811000
P_20120229   1330529409000
P_20120228   1330443009000
P_20120227   1330356610000
P_20120224   1330097411000
P_20120223   1330011010000
P_20120222   1329924609000
P_20120221   1329838210000
P_20110516   1305545402000
P_20110211   1297420202000
P_20100719   1279497600000


   SELECT ATTR1,TO_NUMBER(DECODE(RTRIM(ATTR2),'MAXVALUE' , NULL,RTRIM(ATTR2))) HIGH_VALUE 
FROM GTT_COMMON
 WHERE TO_NUMBER(DECODE(RTRIM(ATTR2),'MAXVALUE' , NULL,RTRIM(ATTR2))) <= [b]1330529409000[/b]

SQL> /

ATTR1                            HIGH_VALUE
-------------------------------------------
P_20120229                    1330529409000
P_20120228                    1330443009000
P_20120227                    1330356610000
P_20120224                    1330097411000
P_20120223                    1330011010000
P_20120222                    1329924609000
P_20120221                    1329838210000
P_20110516                    1305545402000
P_20110211                    1297420202000
P_20100719                    1279497600000

10 rows selected.


[Updated on: Tue, 06 March 2012 01:15] by Moderator

Report message to a moderator

Re: ORA-00997: illegal use of LONG datatype (merged 2) [message #546243 is a reply to message #546241] Mon, 05 March 2012 22:58 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
why do you require the GTT?
why not just combine the two SELECT statements?

WITH gtt_common 
     AS (SELECT partition_name attr1, 
                high_value     attr2 
         FROM   user_tab_partitions 
         WHERE  table_name = 'XYZ') 
SELECT attr1, 
       To_number(Decode(Rtrim(attr2), 'MAXVALUE', NULL, 
                                      Rtrim(attr2))) high_value 
FROM   gtt_common 
WHERE  To_number(Decode(Rtrim(attr2), 'MAXVALUE', NULL, 
                                      Rtrim(attr2))) <= 1330529409000 
Re: ORA-00997: illegal use of LONG datatype (merged 2) [message #546248 is a reply to message #546241] Mon, 05 March 2012 23:19 Go to previous messageGo to next message
Michel Cadot
Messages: 68776
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
Quote:
As I need to use this in procedure and I need to have the high value in where clause I came up with following Approach.


You can use my function where you want:
SQL> select table_name, partition_name
  2  from user_tab_partitions
  3  where high_value(table_name, partition_name) = 'MAXVALUE'
  4  order by 1, 2
  5  /
TABLE_NAME                     PARTITION_NAME
------------------------------ ------------------------------
COMPOSITE_RNG_HASH             SALES_FUTURE
T                              P2


Regards
Michel

Re: ORA-00997: illegal use of LONG datatype (merged 2) [message #546249 is a reply to message #546248] Mon, 05 March 2012 23:34 Go to previous messageGo to next message
rahulvb
Messages: 924
Registered: October 2009
Location: Somewhere Near Equator.
Senior Member
Smile Both Approaches are so Simple now me confused which to use.
icon14.gif  Re: ORA-00997: illegal use of LONG datatype (merged 2) [message #546253 is a reply to message #546249] Tue, 06 March 2012 00:02 Go to previous messageGo to next message
rahulvb
Messages: 924
Registered: October 2009
Location: Somewhere Near Equator.
Senior Member
Final Fix :

1/ Created the function on global level and use it in cursor.

I tried to put this function as local to procedure but did NOT worked got the following error while compile


---------Code in procedure------


FOR curs in (
                         select
                           table_name ,
                           partition_name
                         from
                           user_tab_partitions
                         where
high_value(table_name, partition_name)  <= to_char(my_value) and table_name = UPPER(v_master_table)
                    )
LOOP
......................
......................
END LOOP;
--------------------------------



LINE/COL ERROR
-------- -----------------------------------------------------------------
182/26   PL/SQL: SQL Statement ignored
188/27   PL/SQL: ORA-00904: : invalid identifier
188/27   PLS-00231: function 'HIGH_VALUE' may not be used in SQL

[Updated on: Tue, 06 March 2012 01:14] by Moderator

Report message to a moderator

Re: ORA-00997: illegal use of LONG datatype (merged 2) [message #546269 is a reply to message #546253] Tue, 06 March 2012 01:16 Go to previous message
Michel Cadot
Messages: 68776
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
A local function (a function defined inside another procedure) is not visible from SQL.
Do it in a package.

Regards
Michel
Previous Topic: send SMS via Oracle 10g
Next Topic: rowtype in oracle 10g
Goto Forum:
  


Current Time: Fri May 01 16:31:10 CDT 2026