Wednesday, September 27, 2017

FIXED! ORA-01654: Unable to Extend Index in Tablespace

The problem in Oracle is that when you delete a record, Oracle will leave it blank. That’s a real waste of space when you delete thousands of records. So deleting records will not help to solve this problem.

Here's an example:

Adding 6 records:
[1][2][3][4][5][6]

After deleting records 2 and 3:
[1][][][4][5][6]

After adding value 7 and 8:
[1][][][4][5][6][7][8]

Fortunately, there is a solution to fix this. You can shrink your tables. By shrinking your tables, Oracle will remove all blank records. To shrink a table, use the following SQL statement.

alter table <mytable> enable row movement;
alter table <mytable> shrink space;
alter table <mytable> disable row movement;

analyze table <mytable> compute statistics;
commit;

If that doesn’t work for you, then you have not enough disk space left. Adding some disk space will solve your problem too.

Source: http://laurenthinoul.com/how-to-fix-ora-01654-unable-to-extend-index-in-tablespace/

Thursday, September 7, 2017

CSS: Fixed Header and Footer


footer{
background: #666666;
color: #B2D1D1;
font-weight: bold;
position: fixed;
Width: 100%;
text-align: center;
bottom: 0;
height: 2em;
padding-top: 2em;
}

header{
background: #666666;
color: #B2D1D1;
font-weight: bold;
font-family: voxBOX;
text-align: center;
font-size: 1em;
top: 0;
position: fixed;
Width: 100%;
height: 3em;
padding-top: 1em;
z-index: 1;
box-shadow: 0px 3px 7px #000000;  <--Just to put shadows on your header. Try it! It's cool :)
}

Sample Ouput:
Look at the scrollbar, header and footer didn't moved. :)

Thursday, February 23, 2017

Oracle/PLSQL: Function to get duration in years/months/days/hours/minutes

Below function is ready to use :)
Happy coding... ^^
Note: This should be paste inside the package body.


FUNCTION FUNC_GET_DURATION(VR_FDATE VARCHAR2) RETURN VARCHAR2
  IS
    VR_DURATION VARCHAR2(500);
  BEGIN
  
    SELECT  '~ '
          || TRUNC(MONTH_DIFF/12) || ' years, '
          || TRUNC(MOD(MONTH_DIFF, 12)) || ' months, '
          || TRUNC(31*(MONTH_DIFF - TRUNC(MONTH_DIFF))) || ' days, '
          || TRUNC(24*MOD(VR_TDATE-VR_FDATE,1)) || ' hours, '
          || TRUNC(MOD(MOD(VR_TDATE-VR_FDATE,1)*24,1)*60) || ' minutes'
        INTO VR_DURATION
    FROM (SELECT CAST(TO_TIMESTAMP(VR_FDATE, 'Mon DD, RR HH24:MI:SS') AS DATE) VR_FDATE
                ,SYSDATE VR_TDATE
                ,MONTHS_BETWEEN(SYSDATE,TO_TIMESTAMP(VR_FDATE, 'Mon DD, RR HH24:MI:SS')) as MONTH_DIFF
          FROM DUAL);
          
    RETURN VR_DURATION;
    
  END FUNC_GET_DURATION;


//


Execution:
SELECT PackageName.FUNC_GET_DURATION('JAN 02, 2015 10:00:00 AM');

Output:
~ 2 years, 1 months, 22 days, 2 hours, 56 minutes

Grant SELECT on all tables in Oracle/PLSQL

Execute the anonymous block below:

DECLARE
  STMT VARCHAR2(100);
BEGIN
FOR x IN (SELECT TABLE_NAME FROM user_tables)
LOOP
  STMT := 'GRANT SELECT ON ' || x.TABLE_NAME || ' TO <user>';
  EXECUTE IMMEDIATE STMT;
END LOOP;
END;