Java J2ME JSP J2EE Servlet Android

Oracle Basic: default value to a column

There are three ways in oracle of how you can specify default value to a column in oracle. That means if you insert null value to that column it will take the default value.
First, at time time of creation of the table specify the default value of the column.
Second, add a new column and specify its default value by ALTER TABLE ... ADD statement.
Third, modify the column by specifying dafault vlue by ALTER TABLE ... MODIFY statement.

1. At table creation
====================

SQL>CREATE TABLE test (name VARCHAR2(10), score NUMBER DEFAULT 0);

CREATE TABLE succeeded.

SQL>INSERT INTO test(name,score) VALUES('John','12');

1 rows inserted

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

1 rows inserted

SQL>SELECT * FROM test;

NAME SCORE
---------- ----------------------
John 12
Rina 0

2 rows selected

2. At add new column to table
=============================

SQL>ALTER TABLE test ADD min_score NUMBER DEFAULT 0;

ALTER TABLE test succeeded.

SQL>INSERT INTO test(name,score) VALUES('Nisha',11);

1 rows inserted

SQL>SELECT * FROM test;

NAME SCORE MIN_SCORE
---------- ---------------------- ----------------------
John 12 0
Rina 0 0
Nisha 11 0

3 rows selected

3. At modify an existing column
===============================

SQL>ALTER TABLE test ADD max_score NUMBER;

ALTER TABLE test succeeded.

SQL>ALTER TABLE test MODIFY max_score DEFAULT 100;

ALTER TABLE test succeeded.

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

1 rows inserted

SQL>SELECT * FROM test;

NAME SCORE MIN_SCORE MAX_SCORE
---------- ---------------------- ---------------------- ----------------------
John 12 0
Rina 0 0
Nisha 11 0
Asad 0 0 100

4 rows selected

Cook PHP: Finding the numbers of occurrence of a string in another string..

Lets consider a String

$str = "PHP is what PHP is and PHP is not what PHP is not";

Now lets try to find out the no of occurrence of the word 'PHP' in above string..


$cnt = count(explode("PHP",$str))-1;
echo $cnt;


This will print 4.

There are many alternative option to do the same this in php..