SET DEFINE OFF;
CREATE OR REPLACE AND COMPILE JAVA SOURCE NAMED LongToRowid AS
public class LongToRowid {

    private static final int ROWID_SIZE = 18;
           
    public static String getRowid(Long object_id, Long long_id){
		String row_id = longToRowId(object_id).substring(12,18) + longToRowId(long_id).substring(6,18);
        //System.out.println("Select * from <TABLE_NAME> where rowid = '" + row_id + "';");
        return row_id;
    }

    private static String longToRowId(long l) {
        long current = l;
        long nextnum;
        char nextchar;
        char[] result = new char[ROWID_SIZE];
        for (int i = ROWID_SIZE - 1; i >= 0; i--) {
            if (current == 0) {
                for (int j = 0; j <= i; j++) {
                    result[j] = 'A';
                }
                return new String(result);
            }
            nextnum = current & 63;
            //System.out.println("current: " + current + " l2ri nextnum: " + nextnum);

            if (nextnum < 26) {
                nextchar = (char) (65 + nextnum);
            } else if (nextnum < 52) {
                nextchar = (char) (71 + nextnum);
            } else if (nextnum < 62) {
                nextchar = (char) (nextnum - 4);
            } else if (nextnum == 62) {
                nextchar = '+';
            } else {
                nextchar = '/';
            }
            result[i] = nextchar;
            current /= 64;
        }
        return new String(result);
    }

};
/
CREATE OR REPLACE FUNCTION java_long_to_rowid(object_idi number, long_id number) RETURN VARCHAR2 AS
LANGUAGE JAVA NAME 'LongToRowid.getRowid(java.lang.Long,java.lang.Long ) return java.lang.String';
/
create or replace function long_to_rowid(p_table_name in varchar2, p_rid_as_long in number) 
return varchar2 as
    l_object_id pls_integer;
    l_row_id varchar2(18);
    l_sql varchar2(500);
    l_schema_name varchar2(32);
begin
    select sys_context('userenv','current_schema') into l_schema_name from dual;
    l_sql := 'select u.object_id from user_objects u where object_name = upper(:p_table_name)'; 
    execute immediate l_sql into l_object_id using p_table_name;
    if l_object_id is null then 
        return 'No such table as ' || p_table_name || ' founf in the current schema ' || l_schema_name ||'.';
    else
        l_row_id := java_long_to_rowid(l_object_id, p_rid_as_long);
        return l_row_id;
    end if;
end;
/
SET DEFINE ON;