Thursday, April 19, 2018

Oracle 11g basics,part 1,Oracle Teacher Sourav,Kolkata 09748184075

set ORACLE_SID=sysdba


set ORACLE_HOME=E:\app\sourav\product\11.2.0\dbhome_1


Now connect to oracle

start sqlplus

sqlplus /nolog

connect as sysdba

connect / as sysdba;

run a sample query and find the name of the databse you are connected to

select name from v$database;

to see the instance name which you are connected with

select * from global_name;


Now we like to use the sql developer


shut down the database

log in as sysdba

shutdown immediate;


start the database

log in as sysdba


Data types supported by oracle

User Defined data types


Find the number of rows in a table

select count(*) from dba_tablespaces;

(dba_tablespaces give information about tablespaces,during the installation oracle create some tablespaces by default,those tablespaces hold all the data)
to find all the tablespaces currently existing in the database

select * from dba_tablespaces;

we can select particular columns using select such as


we can also change the order by changing the name of columns


to know the structure of the table use describe

describe dba_tablespaces;

desc dba_tablespaces;


to find the total number of rows in a table

select count(*) from dba_tablespaces;


filtering data using where clause

select * from dba_roles where role='CONNECT';


To make your pc faster

go to services.msc

and change these services startup from automatic to manual as written below

(My oracle instance name is sysdba instead of orcl)





you have to start these services manually every time you want to use oracle


Find the user list for your oracle database;

select username from dba_users;

let's see if the user scott is enabled or disabled

SELECT username, account_status   from dba_users;

if you find the username scott is locked let's try to enable/unlock that user

alter user scott account unlock;

let's logout and try to use scott


sqlplus /nolog

if you use this command to connect connect using scott and the password tiger it
will prompt you to change the password as it is expired

you could also change the user status and password in a same line such as

alter user hr identified by 123456 account unlock;

after loggin in you can verify it by using this sql command

select * from global_name

then go to sql developer and create another connect using hr and password 123456 and see the tables created for the hr schema


directly login as scott

sqlplus scott/tiger@orcl

show the date


login as sysdba and run the storeschema.sql

To end SQL*Plus, you enter EXIT. To reconnect to the store schema
in SQL*Plus, you enter store as the user name with a password
of store_password.

connect using sqlplus like this

sqlplus store@sysdba

enter the password


creating the database user


If you want the user to be able to work in the database, the user must be granted the
necessary permissions to do that work. In the case of store, this user must be able to log onto
the database (which requires the connect permission) and create items like database tables
(which requires the resource permission). Permissions are granted by a privileged user (for
example, the system user) using the GRANT statement.

GRANT connect, resource TO sourav;


Oracle data types explanation

Format Number Supplied Number Stored
NUMBER 1234.567 1234.567
NUMBER(6, 2) 123.4567 123.46
NUMBER(6, 2) 12345.67 Number exceeds the specified precision and
is therefore rejected by the database.

CHAR(length) Stores strings of a fixed length. The length parameter specifies
the length of the string. If a string of a smaller length is stored, it
is padded with spaces at the end. For example, CHAR(2) may
be used to store a fixed-length string of two characters; if 'C' is
stored in a CHAR(2), then a single space is added at the end;
'CA' is stored as is, with no padding.

VARCHAR2(length) Stores strings of a variable length. The length parameter specifies
the maximum length of the string. For example, VARCHAR2(20)
may be used to store a string of up to 20 characters in length. No
padding is used at the end of a smaller string.

DATE Stores dates and times. The DATE type stores the century, all four
digits of a year, the month, the day, the hour (in 24-hour format),
the minute, and the second. The DATE type may be used to store
dates and times between January 1, 4712 B.C. and December 31,
4712 A.D.

INTEGER Stores integers. An integer doesn’t contain a floating point: it is a
whole number, such as 1, 10, and 115.

Stores floating point numbers, but may also be used to store
integers. The precision is the maximum number of digits
(left and right of a decimal point, if used) that may be used for
the number. The maximum precision supported by the Oracle
database is 38. The scale is the maximum number of digits to
the right of a decimal point (if used). If neither precision nor
scale is specified, any number may be stored up to a precision
of 38 digits. Any attempt to store a number that exceeds the
precision is rejected by the database.

BINARY_FLOAT Introduced in Oracle Database 10g, stores a single precision
32-bit floating point number. You’ll learn more about BINARY_
FLOAT later in the section “The BINARY_FLOAT and BINARY_
DOUBLE Types.”

BINARY_DOUBLE Introduced in Oracle Database 10g, stores a double precision
64-bit floating point number.

using sql developer if you connect using store to enter the store schema you will see

The customers table holds the details of the customers. The
following items are held in this table:
First name
Last name
Date of birth (dob)
Phone number

to create a table like in this schema the sql command is this

CREATE TABLE customers (
customer_id INTEGER CONSTRAINT customers_pk PRIMARY KEY,
first_name VARCHAR2(10) NOT NULL,
last_name VARCHAR2(10) NOT NULL,
dob DATE,
phone VARCHAR2(12)

As you can see, the customers table contains five columns,

one for each item in the

previous list, and an extra column named customer_id. The columns are
customer_id Contains a unique integer for each row in the table. Each table should
have one or more columns that uniquely identifies each row; the column(s) are known as
the primary key. The CONSTRAINT clause indicates that the customer_id column is the
primary key. A CONSTRAINT clause restricts the values stored in a column, and, for the
customer_id column, the PRIMARY KEY keywords indicate that the customer_id
column must contain a unique value for each row. You can also attach an optional
name to a constraint, which must immediately follow the CONSTRAINT keyword—for
example, customers_pk. You should always name your primary key constraints, so
that when a constraint error occurs it is easy to spot where it happened.

first_name Contains the first name of the customer. You’ll notice the use of the NOT
NULL constraint for this column—this means that a value must be supplied for first_
name when adding or modifying a row. If a NOT NULL constraint is omitted, a user
doesn’t need to supply a value and the column can remain empty.

last_name Contains the last name of the customer. This column is NOT NULL, and
therefore a value must be supplied when adding or modifying a row.
dob Contains the date of birth for the customer. Notice that no NOT NULL constraint is
specified for this column; therefore, the default NULL is assumed, and a value is optional
when adding or modifying a row.

phone Contains the phone number of the customer. This is an optional value.

You can see the rows in the customers table for yourself by executing the following
SELECT statement using SQL*Plus:
SELECT * FROM customers;

The product_types table holds the names of the product
types sold by the store. This table is created by the store_schema.sql script using the
following CREATE TABLE statement:

CREATE TABLE product_types (
product_type_id INTEGER CONSTRAINT product_types_pk PRIMARY KEY,

The product_types table contains the following two columns:

product_type_id uniquely identifies each row in the table; the product_type_id
column is the primary key for this table. Each row in the product_types table must
have a unique integer value for the product_type_id column.

name contains the product type name. It is a NOT NULL column, and therefore a value
must be supplied when adding or modifying a row.

You can see the rows in the product_types table for yourself by executing the following
SELECT statement using SQL*Plus:

SELECT * FROM product_types;

The products Table The products table holds the products sold by the store. The
following pieces of information are held for each product:
Product type

The sql for creating the product table

CREATE TABLE products (
product_id INTEGER CONSTRAINT products_pk PRIMARY KEY,
product_type_id INTEGER
CONSTRAINT products_fk_product_types
REFERENCES product_types(product_type_id),
description VARCHAR2(50),
price NUMBER(5, 2)

The columns in this table are as follows:

product_id uniquely identifies each row in the table. This column is the primary key
of the table.

product_type_id associates each product with a product type. This column is a
reference to the product_type_id column in the product_types table; it is known
as a foreign key because it references a column in another table. The table containing
the foreign key (the products table) is known as the detail or child table, and the table
that is referenced (the product_types table) is known as the master or parent table.

This type of relationship is known as a master-detail or parent-child relationship. When
you add a new product, you associate that product with a type by supplying a matching
product_types.product_type_id value in the products.product_type_id
column .

name contains the product name, which must be specified, as the name column is

description contains an optional description of the product.

price contains an optional price for a product. This column is defined as NUMBER(5,
2)—the precision is 5, and therefore a maximum of 5 digits may be supplied for this
number. The scale is 2; therefore 2 of those maximum 5 digits may be to the right of the
decimal point.


Adding modifying and removing rows in a table

Adding a Row to a Table
You use the INSERT statement to add new rows to a table. You can specify the following
information in an INSERT statement:

The table into which the row is to be inserted
A list of columns for which you want to specify column values
A list of values to store in the specified columns
When inserting a row, you need to supply a value for the primary key and all other columns
that are defined as NOT NULL. You don’t have to specify values for the other columns if you don’t
want to; those columns will be automatically set to null if you omit values for them.
You can tell which columns are defined as NOT NULL using the SQL*Plus DESCRIBE
command. The following example DESCRIBEs the customers table:

SQL> DESCRIBE customers
Name Null? Type
----------------------------------------- -------- ------------

As you can see, the customer_id, first_name, and last_name columns are NOT NULL,
meaning that you must supply a value for these columns. The dob and phone columns don’t
require a value; you could omit the values if you wanted, and they would be automatically set to null.
Go ahead and run the following INSERT statement, which adds a row to the customers
table; notice that the order of values in the VALUES list matches the order in which the columns
are specified in the column list:

SQL> INSERT INTO customers (
 customer_id, first_name, last_name, dob, phone) VALUES ( 6, 'Fred', 'Brown', '01-JAN-1970', '800-555-1215' );

FROM customers;

will show the added row

Possible error when inserting

When a row is added to the customers table, a unique value for the customer_id column
must be given. The Oracle database will prevent you from adding a row with a primary key value
that already exists in the table; for example, the following INSERT statement causes an error
because a row with a customer_id of 1 already exists:
SQL> INSERT INTO customers (
2 customer_id, first_name, last_name, dob, phone
3 ) VALUES (
4 1, 'Lisa', 'Jones', '02-JAN-1971', '800-555-1225'
5 );
INSERT INTO customers (
ERROR at line 1:
ORA-00001: unique constraint (STORE.CUSTOMERS_PK) violated

Modifying an Existing Row in a Table

You use the UPDATE statement to change rows in a table. Normally, when you use the UPDATE
statement, you specify the following information:
The table containing the rows that are to be changed
A WHERE clause that specifies the rows that are to be changed
A list of column names, along with their new values, specified using the SET clause
You can change one or more rows using the same UPDATE statement. If more than one row is
specified, the same change will be made for all the rows. The following example updates customer
#2’s last_name to Orange:

UPDATE customers
SET last_name = 'Orange'
WHERE customer_id = 2;
1 row updated.
SQL*Plus confirms that one row was updated.

FROM customers
WHERE customer_id = 2;

Removing a Row from a Table

You use the DELETE statement to remove rows from a table. You typically use a WHERE clause to
limit the rows you wish to delete; if you don’t, all the rows will be deleted from the table.
The following DELETE statement removes customer #2:
DELETE FROM customers
WHERE customer_id = 2;
1 row deleted.
To undo the changes you’ve made to the rows, you use ROLLBACK:


show all the tables in your schema

log in as store

conn store@sysdba;

enter password

select TABLE_NAME from user_tables


To see the post number and the instance name of your oracle database

open this file in notepad



Saturday, March 10, 2018

Search and find a file in current working directory and it's subdirectories recursively and print it's characteristics using shell script,Linux Teacher Sourav,Kolkata 09748184075


 if [ $# -ne 1 ]; then
 echo "Usage: filechecker filename"
 echo " Will show various attributes of the file given."
exit 255

file_count=$(find . -name $1 | wc -l)
#echo $file_count

echo   $1

if [ "$file_count" -gt 1 ]; then
echo " has multiple version exists in the current directory and it's subdirectories,exiting."
# Leave script now
exit 2

if [ "$file_count" -eq 0 ]; then
 echo " does not exist,exiting."
 exit 1

# Leave script now

if [ -f $1 ] ; then
echo is a file.
 elif [ -d $1 ] ; then
 echo is a directory.


if [ -x $1 ] ; then
echo Is executable.

 if [ -r $1 ] ; then
 echo Is readable.

echo Is not readable.

 if [ -w $1 ] ; then
 echo Is writable.


if [ -s $1 ] ; then
echo Is not empty.
echo Is empty.

exit 0

Thursday, February 22, 2018

Alias command in Ubuntu 16,linux Teacher Sourav,Kolkata 09748184075

aliases can be any name other than reserved word ,it can even be same name as a command with different options,aliases can be applied on global basis or per user basis

for global basis we have to modify the file
called /etc/bashrc

for user basis the file is 

let's create a custom command

the alias command will show you the already set aliases

set a alias

alias ls='ls -l'

now using the alias command you will see 
the new alias set

when we use ls using the alias it will run 
ls -l

we can perform the same thing 

by changing df to df -h

alias df='df -h'

h is for human readable format,the output of df will be shown in human readable format by default from now instead of block sizes

now let's create a command which does not exist

alias delete='rm -i'

by defining the alias delete will be available to bash will also help in tab complition when typing delete

these aliases are also going to available to shell scripts

to remove the alias

unalias delete

to make these aliases permanenet we have to aliases to the /etc/bashrc(for parmanent) or /home/username/.bashrc for just the user

firefox or chrome can not run swf files solved on ubuntu 16,Linux Teacher Sourav,Kolkata 09748184075

Edit /usr/share/mime/packages/ as root and replace the following:


And then run:

sudo update-mime-database /usr/share/mime

Friday, February 2, 2018

Create a dynamic chart automatically and change it's va;ue dynamically when the original data is filtered or sorted using VBA,VBA Teacher Sourav,Kolkata 09748184075

Sub Macro1()

Dim ch As Shape

    Set ch = ActiveSheet.Shapes(1)
    ch.Name = "Chart 3"
    ActiveChart.ChartType = xlColumnClustered
    ActiveChart.SetSourceData Source:=Range("'(2)'!$B$12:$C$36")
    ActiveSheet.ChartObjects("Chart 3").Activate
    ch.Placement = xlFreeFloating
    ActiveSheet.Range("$B$12:$C$36").AutoFilter Field:=2, Criteria1:="5", _
    ActiveSheet.ChartObjects("Chart 3").Activate
    ActiveChart.Axes(xlCategory).CategoryType = xlCategoryScale
    ActiveWorkbook.Worksheets("(2)").AutoFilter.Sort.SortFields.Add Key:=Range( _
        "C19"), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:= _
    With ActiveWorkbook.Worksheets("(2)").AutoFilter.Sort
        .Header = xlYes
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
    End With
    ActiveSheet.ChartObjects("Chart 3").Activate
    ActiveChart.ChartGroups(1).VaryByCategories = True
End Sub