Skip to main content

Posts

Showing posts from April, 2014

Useful SQL queries and tips

1 How to find all indexes associated with a table in Oracle select index_name, table_name from all_indexes where lower(TABLE_NAME)=lower(<your_table_name>) and OWNER='<owner>' 2 How to view DDL for any index in Oracle select dbms_metadata.get_ddl('INDEX',<index_name> ','<owner>') from dual; 3 How to view DDL for any view in Oracle select dbms_metadata.get_ddl('VIEW',<view_name>,'<owner>') from dual; 4 What to do when sqlplus is not displaying all lines in output Run below on sqlplus prompt: set heading off; set echo off; Set pages 999; set long 90000;  5 How to edit a sql you previously ran on sqlplus prompt Type ‘ed’ on prompt SQL> ed This will open a vi editor with your last sql query. Edit it and save and exit Type ‘r’ on prompt SQL> r This will run the updated sql. 6 H

Filesystem is full, but can't find space being used - Solaris

I saw a strange issue once  where the  /staging filesystem is almost full, but I can't find where the space is being used.  'df -h' command shows that the filesystem is 100% used as below. ==> df -h Filesystem             size   used  avail capacity  Mounted on /staging                  99G   99G   0K     100%      /staging But 'du -h' command says that only 3.7G out of 99G is used. ==> pwd /staging ==> du -h | grep "\.$" 3.7G . This is strange , now how will you find which files are consuming remaining 95.3G of disk space. The unix command which can be used here is 'lsof' - l ist o f o pen f iles. ==>  lsof | grep -i /staging cat        4723  user1 txt   VREG     270,28001          50028743680      15496 /staging (/dev/vx/dsk/staging) cat        4723  user1 3r  VREG     270,28001          50028743680      15496 /staging (/dev/vx/dsk/staging) sed        4724  user1 1w  VREG     270,28001      

JAXB - Marshalling and Unmarshalling object in Java

JAXB, stands for Java Architecture for XML Binding, which can be used to convert a Java object to XML file or a XML document to corresponding Java Object. Given below are the two terminologies used in Java for the conversions. Marshalling - Convert a Java object to XML file Unmarshalling - Convert a XML file to Java object. Here we have a class called Car which contains object of another class called Wheel. The UML diagram is as below. First we will need to write  the class Car as follows. import javax.xml.bind.annotation.XmlRootElement; @XmlRootElement // This annotation is required to indicate that this is the top level class public class Car { Wheel wheel; String color; public Wheel getWheel() { return wheel; } public void setWheel(Wheel wheel) { this.wheel = wheel; } public String getColor() { return color; } public void setColor(String color) {

Java - getting Date without time

Java Calender and Date object is always confusing for a beginner and one of the typical situation is to create a Date object with no time information from a Calender or another Date object. One of the typical usage is when we need to compare Date with one stored in a database in say 'dd-MMM-yy' format. Calendar calendar = Calendar.getInstance(); calendar.add(Calendar.DATE, offset); SimpleDateFormat dayMonthYear = new SimpleDateFormat("dd-MMM-yy"); String newDate=dayMonthYear.format(calendar.getTime()); Date fmtDate=null; try { fmtDate = dayMonthYear.parse(newDate); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } System.out.println("Time in getDate" + fmtDate);