Some Usefull Oracle Queries

0

The Number of Sessions the Database Was Configured to Allow

SELECT name, value FROM v$parameter
WHERE name = 'sessions'

The Number Of Sessions Currently Active

SELECT COUNT(*) FROM v$session

Show All User In Oracle Database

SELECT * FROM all_users;

Date Mask Text Field using only HTML,JavaScript

1

Placeholder
The placeholder attribute specifies a short hint that describes the expected value of an input field (e.g. a sample value or a short description of the expected format).

I have used Regular Expression.I am checking if 2 digits are entered if yes i have appened a slash.

<input 
	type="text" 
	name="date" 
	placeholder="dd/mm/yyyy" 
	onkeyup="
		var v = this.value;
		if (v.match(/^\d{2}$/) !== null) {
			this.value = v + '/';
		} else if (v.match(/^\d{2}\/\d{2}$/) !== null) {
			this.value = v + '/';
		}"
	maxlength="10"
>

Java DecimalFormat

0

 

DecimalFormat df = new DecimalFormat("0.000");
double num = 234.5698709;
System.out.println("Num: " + df.format(num));
System.out.println("Given Radius: " + df.format(radius));
System.out.println("Area: " + df.format(area));
System.out.println("Circumference: "+ df.format(circumference));

Set JAVA_HOME in a Windows Command Script

0

 

Apache Ant is a common tool for building Java applications, and most IDEs support building with Ant right from the IDE.  However, when you need to build your Java application outside of the IDE, it can be handy to have a script kick off Ant.

On Microsoft Windows the script needs to know the location of the JDK and Ant, which generally entails:

  • Relying on environment variables to be set correctly or
  • Hardcoding the path locations

Both approaches are brittle and likely to result in maintenance and support headaches down the road.  Additionally, hardcoding the paths assumes all the developers are running the same versions of the JDK and Ant.  These limitations are insignificant for a centrally managed commercial software organization, but they can be problematic for a distributed open source project.

DOS “for” Command
Fortunately, it’s easy to write a Command Script (.cmd) batch file using the DOS for command that automatically determines the path to the most current versions of the JDK and Ant.  To test out thefor command, try the following at the Windows Command Prompt.

Command Prompt Demonstration
C:\>for /d %i in ("\Program Files\Java\jdk*") do set JAVA_HOME=%i
C:\>set JAVA_HOME

You should see a result similar to:
JAVA_HOME=\Program Files\Java\jdk1.7.0_02

Command Script Solution
To make it easy to launch Ant, put the following build.cmd file into the same folder as yourbuild.xml Ant configuration file.

build.cmd File
@echo off
::::::::::::::::::::::::::::::::::::
:: build.cmd (v1.0)               ::
:: Microsoft Windows Build Script ::
::::::::::::::::::::::::::::::::::::

:: Set JAVA_HOME
for /d %%i in ("\Program Files\Java\jdk*") do set JAVA_HOME=%%i

:: set ANT_HOME
for /d %%i in ("\Apps\Ant\apache-ant*") do set ANT_HOME=%%i

:: Display Variables and Launch Ant
set JAVA_HOME
set ANT_HOME
call %ANT_HOME%\bin\ant build
pause
View/Download: build.cmd

Now to build your project, double-click the build.cmd file.

While the script does not hardcode the JDK and Ant versions, it does require that the JDK is installed into the default location and that Ant in installed (copied) into the \Apps\Ant folder.

Alternative Approach
If you prefer to be more robust in your detection of the JDK home, you can use the DOS reg querycommand to read the Windows Registry information to locate the JDK.  In the build.cmd file, replace the line that sets JAVA_HOME with the lines below.

Use Windows Registry to Set JAVA_HOME
:: Set JAVA_HOME
set KeyName=HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Development Kit
set Cmd=reg query "%KeyName%" /s
for /f "tokens=2*" %%i in ('%Cmd% ^| find "JavaHome"') do set JAVA_HOME=%%j
View/Download: set-java-home.cmd

The output of the reg query is piped through find to single out the desired key value.  The third token (represented by %%j) on the line is the path.

Simplify
By having build.cmd auto-detect the JDK and Ant, you can simplify the steps for new developers looking to contribute to your open source project.

Apple Mac OS X Shell Script
To kick off Ant on a Mac, you can use a short 2-line shell script.

build.sh.command File
#!/bin/sh
#############################
##  Mac OS X Build Script  ##
#############################

cd `dirname $0`
ant build
View/Download: build.sh.command

This script is simple because Mac OS X ships with Ant and automatically downloads Java (including the JDK) the first time you use it.

 

From : http://techdem.centerkey.com/2009/05/javahome-command-script.html

How To Create Auto Increment Columns In Oracle

0

First let’s create a simple table to play with.

SQL> CREATE TABLE test
(id NUMBER PRIMARY KEY,
name VARCHAR2(30));

Table created.

Now we’ll assume we want ID to be an auto increment field. First we need a sequence to grab values from.

SQL> CREATE SEQUENCE test_sequence
START WITH 1
INCREMENT BY 1;

Sequence created.

Now we can use that sequence in an BEFORE INSERT trigger on the table.

CREATE OR REPLACE TRIGGER test_trigger
BEFORE INSERT
ON test
REFERENCING NEW AS NEW
FOR EACH ROW
BEGIN
SELECT test_sequence.nextval INTO :NEW.ID FROM dual;
END;
/

Trigger created.

This trigger will automatically grab the next value from the sequence we just created and substitute it into the ID column before the insert is completed.

Now we’ll do some inserts:

SQL> INSERT INTO test (name) VALUES ('Jon');

1 row created.

SQL> INSERT INTO test (name) VALUES (’Bork’);

1 row created.

SQL> INSERT INTO test (name) VALUES (’Matt’);

1 row created.

SQL> SELECT * FROM test;

ID NAME
———- ——————————
1 Jon
2 Bork
3 Matt

Because the sequence is updated independent of the rows being committed there will be no conflict if multiple users are inserting into the same table simultaneously.

 

From : http://situsnya.wordpress.com/2008/09/02/how-to-create-auto-increment-columns-in-oracle/

Grant privileges to a user (or to a user role) Oracle

0

Grant privileges to a user (or to a user role)

Syntax:

Grant System-wide Privs:

   GRANT system_priv(s) TO grantee 
      [IDENTIFIED BY password] [WITH ADMIN OPTION]

   GRANT role TO grantee 
      [IDENTIFIED BY password] [WITH ADMIN OPTION]

   GRANT ALL PRIVILEGES TO grantee 
      [IDENTIFIED BY password] [WITH ADMIN OPTION]

grantee:
   user 
   role
   PUBLIC

system_privs:
   CREATE SESSION - Allows user to connect to the database
   UNLIMITED TABLESPACE  - Use an unlimited amount of any tablespace.
   SELECT ANY TABLE - Query tables, views, or mviews in any schema
   UPDATE ANY TABLE - Update rows in tables and views in any schema
   INSERT ANY TABLE - Insert rows into tables and views in any schema
   Also System Admin rights to CREATE, ALTER or DROP:
     cluster, context, database, link, dimension, directory, index,
     materialized view, operator, outline, procedure, profile, role,
     rollback segment, sequence, session, synonym, table, tablespace,
     trigger, type, user, view.

object_privs:
   SELECT, UPDATE, INSERT, DELETE, ALTER, DEBUG, EXECUTE, INDEX, REFERENCES 

roles:
   SYSDBA, SYSOPER, OSDBA, OSOPER, EXP_FULL_DATABASE, IMP_FULL_DATABASE
   SELECT_CATALOG_ROLE,  EXECUTE_CATALOG_ROLE, DELETE_CATALOG_ROLE
   AQ_USER_ROLE, AQ_ADMINISTRATOR_ROLE - advanced queuing
   SNMPAGENT - Enterprise Manager/Intelligent Agent.
   RECOVERY_CATALOG_OWNER - rman
   HS_ADMIN_ROLE - heterogeneous services

   plus any user defined roles you have available

3 Ways to Traverse a List – Java

0

There are primarily 3 ways I can think of to traverse a java.util.List:

Using a traditional for loop;
Using a simplified for loop, or “foreach” statement in JDK 5 ;
Using java.util.Iterator


public static void traverse(List data) {
    System.out.println("Using simplified for loop/foreach:");
    for(Object obj : data) {
        System.out.println(obj);
    }

    System.out.println("Using for loop:");
    for(int i = 0, n = data.size(); i < n; i++) {
        System.out.println(data.get(i));
    }

    System.out.println("Using Iterator:");
    for(Iterator it = data.iterator(); it.hasNext();) {
        System.out.println(it.next());
    }
}

How to Convert Character From Lowercase to Uppercase in C

0

In C programming language there are some excellent library function for processing character data. Text input or output, regardless of where it originates or where it goes to, is dealt with as streams of characters. A text stream is a sequence of character divided into lines; each line consists of zero or more characters followed by a newline character. The standard library provides several functions for reading or writing one character at a time and we show you the usability some of this function
It is very much easy to convert a character from lowercase to uppercase using C programming language. There are some library function which makes this more easier and we discuss this here in details. Here is a complete C program that reads in a lowercase character, converts it to uppercase and then display the uppercase equivalent.

#include <stdio.h>
#include <ctype.h>
int main()
{
      int lower, upper;
      lower = getchar();
      upper = toupper(lower);
      putchar(upper);
      return 0;
}

This program contains three library functions: getchar(), toupper() and putchar().

  • getchar() – returns a character that is entered from the keyboard.
  • toupper() – returns the uppercase equivalent of its argument.
  • putchar() – causes the value of the argument to be displayed.

Notice that the last two functions each have one argument but the first function does not have any arguments, as indicated by the empty parentheses.

Also notice that preprocessor statements which is highlighted appear at the start of the program. These statements cause the contents of the header file stdio.h and ctype.h to inserted into the program the compilation process begins. The information contains in these files is essential for the proper functioning of the library functions getchar(), putchar() and toupper().

I explain this program in details for the beginners to understand easily.

Now we write the same program without library function so that we can understand these library function more in depth. Hence, you should concentrate on the overall logic, and not worry about the details of each individual statement just yet.

Here is the complete program,

#include <stdio.h>
int main()
{
      char lower, upper;
      printf("Please input a lowercase character: ");
      scanf("%c", &lower);
      if(lower >= 'a' && lower <= 'z'){
            upper = ('A' + lower - 'a');
      }
      else{
            upper = lower;
      }
      printf("\nThe uppercase equivalent is: %c\n", upper);
      return 0;
}

You can also write this program using separate function like below

 

#include <stdio.h>
char lower_to_upper(char ch1)
{
      char ch2;
      if(ch1 >= 'a' && ch1 <= 'z'){
            ch2 = ('A' + ch1 - 'a');
            return ch2;
      }
      else{
            ch2 = ch1;
            return ch2;
      }
}
int main()
{
      char lower, upper;
      printf("Please input a lowercase character: ");
      scanf("%c", &lower);
      upper = lower_to_upper(lower);
      printf("\nThe uppercase equivalent is: %c\n", upper);
      return 0;
}

 

Here lower_to_upper() function carries out the actual character conversion. This function converts only lowercase letters; all other characters are returned intact. A lowercase letter is transferred into the function via the argument c1, and the uppercase equivalent , c2, is returned to the calling portion of the program ( to main) via the return statement.

Now consider the main function, which follows lower_to_upper(). This function reads in a character which may or may not be a lowercase letter and assigns it to the char-type variable lower. function main then call the function lower_to_upper(), transferring the lowercase character (lower) to lower_to_upper(), and receiving the equivalent uppercase character (upper) from lower_to_upper(). Notice that the variables lower and upper in main corresponds to the variables c1 and c2 within lower_to_upper().

I think you can understand this program. The highlighted part of the code above is the logical part. Here we use the ASCII value of each character the ASCII value of ‘a’ is 97 and ‘z’ is 122. Say we input ‘m’ as input whose ASCII value is 109, need to convert it into ‘M’ so put the value of these character into this logical line (‘A’ + lower – ‘a’). here lower=109 (ASCII value of ‘m’) so we get (65 + 109 – 97) = 77, which is the ASCII value of ‘M’ and thus the output will be ‘M’.

You will find here all the ASCII Character Set .

Source : http://www.blog.findsourcecode.com/c-programming/convert-character-from-lowercase-to-uppercase/