Thursday, May 27, 2010

LEARN SQL PLUS WITH ARS (A VERY SIMPLE & COMPREHENSIVE LECTUER

IN THIS LECTURE WE GONNA LEARN ABOUT SQL + IN VERY EASY WAY JUST HAVE A LOOK AND IMPLEMENT ON THIS

Basic Introduction to SQL*PLUS

The SQL*PLUS (pronounced "sequel plus") program allows you to store and retrieve data in the relational database management system ORACLE. Databases consists of tables which can be manipulated by structured query language (SQL) commands.
A table is made up of columns (vertical) and rows (horizontal).
A row is made up of fields which contain a data value at the intersection of a row and a column.
Be aware that SQL*PLUS is a program and not a standard query language.

Getting Started

It is a prerequisite that users are registered for ORACLE, an ORACLE account is needed.
On Unix platforms you must start the script oraenv to set the ORACLE environment. Enter the command . oraenv and press <Return;>.
Don't forget to type a blanc between the dot and oraenv.

If you are working with a PC using MS Windows, simply use Netinstall to install the product. You can find the software in the database folder.
Enter sqlplus on unix systems or run it on Windows from the start menue. Answer the displayed prompts by entering your ORACLE user-name and password.
The SQL*PLUS command prompt SQL > indicates that you are ready to work.

Some elementary Commands

alter user user identified by new passwordenables user to change the password
help accesses the SQL*PLUS help system
exit, quit terminates SQL*PLUS
ho[st] leads to the operating system without leaving SQL*PLUS
ho[st] command executes a host operating system command
ho[st] oerr accesses the ORACLE error help for unix

Editing and Executing

All entered input is stored as a single SQL*PLUS statement in the command buffer. Pressing the <Return> key while editing will either open a new numbered line or, if the previous line ends with a semicolon or consists of a single slash, will execute the SQL*PLUS command. Opening new numbered lines allows you to structure statements and enables you to refer to particular lines by later using edit functions.

l[ist] lists command buffer (the current line is marked with a star)
ln or n makes line n the current line and lists it
ln m lists lines n through m
a text appends text to current line
c/oldstring/newstring changes oldstring to newstring in current line
i inserts a line after current line
del deletes the current line
r[un] runs and lists command buffer
/ runs command buffer
; lists command buffer


If you use substitution variables, like &variable, instead of values or names in your SQL statement, SQL*PLUS will prompt you and substitute the entered value. A substitution variable is a user variable name preceded by an ampersand.

Working with Command Files

You can use command files to save complex commands. After creating a command file you can retrieve, edit, and run it. The default file extension is .sql . If you use other file extensions you must write the full file name like name.extension.

ed[it] overwrites a scratch file with the contents of the command buffer

edit enables you to edit this file with the defined host operating system

editor. The name of the scratch file is afiedt.buf .

After leaving the editor the buffer is listed and you can execute it.
ed[it] filename enables you to edit an existing or new file filename.sql
sav[e] filename creates file filename and stores the command buffer into it
sav[e] filename [option] stores command buffer into file filename

Possible options are cre[ate], app[end], rep[lace].
get filename loads the host operating system file filename into the command buffer
sta[rt] filename [arg1 arg2 ..] executes file filename

arg1 arg2 .. are arguments you wish to pass to the command file


If you run a command file in which a substitution variable like &1 is used, you will be prompted for that value. You can avoid being prompted by passing an argument to the command file.

Queries and Subqueries

Retrieving data from the database is the most common SQL operation. A query is an SQL command (specifically a select) that retrieves information from one or more tables. A subquery is a select which is nested in another SQL command.

The Describe Command

desc[ribe] name lists the column definition for table or view name

Basic Select Commands

The basic select command consists of two parts, called clauses: select some data from table.
Examples

select * from tabname selects all columns and rows from table tabname
select distinct col from tabname selects column col from table tabname

and returns only one copy of duplicate rows
select col1, col2 ... from tabname selects specified columns from table tabname
select col1, col2*3 from tabname selects col1,col2 from table tabname

and lists col1, col2 multiplied by 3
select 2*3 from dual calculates 2*3 and will display the result

Selecting Rows and Ordering

To retrieve specific rows from a table you need to add a where clause. A where clause consists of one or more search conditions which can be connected by logical operators. To display the retrieved data in a specific order you need to add an order by clause.
Examples
select col1,col2 from tabname
where col1 < col2 and col2 !=0
order by col2
Columns col1, col2 are selected from table tabname and all rows where col2 is not equal to zero and col1 is less than col2 are displayed in an ascending order (ordered by col2).
select col1,col2 from tabname
where col1 like '_A%' or col1 like '+++'
order by col2 desc
Columns col1,col2 are selected from table tabname and all rows where col1 is equal to '+++' or where the second letter in col1 is an 'A' are displayed in a descending order.
In this example two different escape characters are used. The underscore matches exactly one character whereas the percent sign can match zero or more characters.
select col1,col2 from tabname
where col1 in ( value1,value2 )
Columns col1,col2 are selected from table tabname and all rows where col1 is equal to value1 or to value2 are displayed.
select col1,col2 from tabname
where col1 not between value1 and value2
Columns col1,col2 are selected from table tabname and all rows where col1 is not in the range between value1 and value2 are displayed.

Using Set Operator

Set operators combine the results of two queries into a single result. If a statement contains multiple set operators, they will be evaluated from left to right.

set operator
union returns all distinct rows selected by either query
union all returns all rows selected by either query, including all duplicates
intersect returns all distinct rows selected by both queries
minus returns all distinct rows selected by the first query but not the second


Example
select * from table1
union all
select * from table2
This will combine all rows, columns of table1 and table2.

Querying Multiple Tables

If you want to retrieve information from different tables, you can do this by issuing different queries or a single JOIN query. In a JOIN query, you list the names of the tables you are querying in the from clause and the names of the linking columns in the where clause. The omission of the linking where clause causes a cartesian product of both tables. A JOIN combines rows from two or more tables where columns which the tables have in common match. If a column name is not unique, you must use a prefix to make clear which column from which table you want to select (e.g. tablename.columnname).

Simple Join

select col1,tab1.col2,col3 from tab1,tab2
where tab1.col2=tab2.col2
This is the most common type of join. It returns rows from two tables based on an equality condition, therefore it is also called an equi-join.

Non-Equi Join

select tab1.col1,tab2.col2 from tab1,tab2
where tab1.col1 between lowval and highval
Since this join doesn't return rows based on a equality condition, it is called a non-equi join.

Self Join

select alias1.col1,alias2.col1 "Header 2" from tabname alias1,tabname alias2
where alias1.col2=alias2.col3
In this example the table tabname is joined with itself. Using of two different alias names for the same table allows you to refer to it twice. Since the names of the resulting columns in this example are the same, the second column gets a new header.

Outer Join

select col1,col2 from tab1,tab2
where tab1.col1=tab2.col2(+)
Suppose you want to retrieve information from two tables where not all rows match but the result should contain all values from one or more columns. A simple join will select only matching rows whereas the outer join extends the result. All matching rows will be selected and when you append the outer join operator (+) to a column name, those rows which do not match will also be selected. In the example the number of rows which are selected is the number of rows in table tab2. If rows match, the outer join works as a simple join, if not, the values from tab2.col2 and a NULL value for the non existing value of tab1.col1 will be selected.

Data Definition Language DDL

DDL commands allow you to create, alter and delete objects (e.g tables, views) and also to grant and revoke privileges.
create table tabname (col1 type1,col2 type2,...) creates table tabname
col1 ... coln are the column names, type1,type2.. specifies the datatype of a column which can be number, date, char, varchar.
number(p,s) specifies a fixed point number having precision p (total number of digits) and scale s (number of digits to the right of the decimal point).
number(p) specifies a fixed point number.
number specifies a floating point number.
char(size) specifies fixed length (max 255) character data of length size.
varchar2(size) specifies variable length (max 2000) character string having a maximum length of size bytes.

create table tabname as subquery creates table tabname
subquery inserts rows into the table upon its creation. A subquery is a form of the select command which enables you to select columns from an existing table.

create view viewname as subquery creates view viewname
A view is a logical table based on one or more tables.

drop table tabname removes table tabname from the database
alter table tabname add (col1 type1,col2 type2,...) adds columns to table tabname
alter table tabname modify (col1 type1,col2 type2,...) modifies column definitions
rename oldname to newname renames table oldname
alter user user identified by newpassword;enables user to change the password

to newpassword
grant privilege on object to usergrants a privilege to user
revoke privilege on object from user revokes a privilege from user

Data Manipulation Language DML

DML commands manipulate and query data in existing tables. These commands do not commit current actions.

insert into tabname (col1,col2...) values (val1,val 2...) inserts rows into table tabname
insert into tabname subquery inserts rows(selected by a subquery) into
&table tabname
update tabname set col1=expr1,col2=expr2... where condupdates rows in table tabname

columns are set to values of expressions if

condition cond is true
update tabname set (col1,col2...)=(subquery) where condupdates rows in table tabname

columns are set to selected values if

condition cond is true
delete from tabname [where cond] either deletes all rows from table tabname

or rows where cond is true

Schema

When you select data from a table or you insert data into a table then this object has to be in your own schema. In other words, you must be the owner.
If you are not the owner of the object, but the owner granted some privileges to you, you have to specify schema.tabname.
Example
select * from scott.emp

Transaction Control Commands

Transaction Control Commands manage changes made by Data Manipulation Language commands. A transaction (or logical unit of work) is a sequence of SQL statements that ORACLE treats as a single unit. A transaction ends with a commit, rollback , exit, or any DDL statement which issues an implicit commit. In most cases transactions are implicitly controlled.

commit makes all changes since the beginning of a transaction permanent
rollback rolls back (undoes) all changes since the beginning of a transaction
rollback to savepoint savep rolls back to savepoint savep
savepoint savep defines savepoint savep

Monday, May 24, 2010

S.D.L.C. Software Development Life Cycle & itz different models



THIS IS VERY IMPORTANT LESSON FOR A EVERY SOFTWARE DEVELOPER ,
IN THIS LESSON WE GONNA LEARN HOW TO MAKE A SDLC MODELS OF A SOFTWARE PROJECTS
WE WILL BE USING DIFFERENT METHODS AND MODELS IN THIS LESSON

Software Development Life Cycle Models

I was asked to put together this high-level and traditional software life cycle information as a favor for a friend of a friend, so I thought I might as well share it with everybody.

The General Model

Software life cycle models describe phases of the software cycle and the order in which those phases are executed. There are tons of models, and many companies adopt their own, but all have very similar patterns. The general, basic model is shown below:

General Life Cycle Model


Each phase produces deliverables required by the next phase in the life cycle. Requirements are translated into design. Code is produced during implementation that is driven by the design. Testing verifies the deliverable of the implementation phase against requirements.

Requirements
Business requirements are gathered in this phase. This phase is the main focus of the project managers and stake holders. Meetings with managers, stake holders and users are held in order to determine the requirements. Who is going to use the system? How will they use the system? What data should be input into the system? What data should be output by the system? These are general questions that get answered during a requirements gathering phase. This produces a nice big list of functionality that the system should provide, which describes functions the system should perform, business logic that processes data, what data is stored and used by the system, and how the user interface should work. The overall result is the system as a whole and how it performs, not how it is actually going to do it.

Design
The software system design is produced from the results of the requirements phase. Architects have the ball in their court during this phase and this is the phase in which their focus lies. This is where the details on how the system will work is produced. Architecture, including hardware and software, communication, software design (UML is produced here) are all part of the deliverables of a design phase.

Implementation
Code is produced from the deliverables of the design phase during implementation, and this is the longest phase of the software development life cycle. For a developer, this is the main focus of the life cycle because this is where the code is produced. Implementation my overlap with both the design and testing phases. Many tools exists (CASE tools) to actually automate the production of code using information gathered and produced during the design phase.

Testing
During testing, the implementation is tested against the requirements to make sure that the product is actually solving the needs addressed and gathered during the requirements phase. Unit tests and system/acceptance tests are done during this phase. Unit tests act on a specific component of the system, while system tests act on the system as a whole.
So in a nutshell, that is a very basic overview of the general software development life cycle model. Now lets delve into some of the traditional and widely used variations.

Waterfall Model

This is the most common and classic of life cycle models, also referred to as a linear-sequential life cycle model. It is very simple to understand and use. In a waterfall model, each phase must be completed in its entirety before the next phase can begin. At the end of each phase, a review takes place to determine if the project is on the right path and whether or not to continue or discard the project. Unlike what I mentioned in the general model, phases do not overlap in a waterfall model.
Waterfall Life Cycle Model


Advantages
• Simple and easy to use.
• Easy to manage due to the rigidity of the model – each phase has specific deliverables and a review process.
• Phases are processed and completed one at a time.
• Works well for smaller projects where requirements are very well understood.
Disadvantages
• Adjusting scope during the life cycle can kill a project
• No working software is produced until late during the life cycle.
• High amounts of risk and uncertainty.
• Poor model for complex and object-oriented projects.
• Poor model for long and ongoing projects.
• Poor model where requirements are at a moderate to high risk of changing.

V-Shaped Model

Just like the waterfall model, the V-Shaped life cycle is a sequential path of execution of processes. Each phase must be completed before the next phase begins. Testing is emphasized in this model more so than the waterfall model though. The testing procedures are developed early in the life cycle before any coding is done, during each of the phases preceding implementation.
Requirements begin the life cycle model just like the waterfall model. Before development is started, a system test plan is created. The test plan focuses on meeting the functionality specified in the requirements gathering.
The high-level design phase focuses on system architecture and design. An integration test plan is created in this phase as well in order to test the pieces of the software systems ability to work together.
The low-level design phase is where the actual software components are designed, and unit tests are created in this phase as well.
The implementation phase is, again, where all coding takes place. Once coding is complete, the path of execution continues up the right side of the V where the test plans developed earlier are now put to use.
V-Shaped Life Cycle Model

Advantages
• Simple and easy to use.
• Each phase has specific deliverables.
• Higher chance of success over the waterfall model due to the development of test plans early on during the life cycle.
• Works well for small projects where requirements are easily understood.
Disadvantages
• Very rigid, like the waterfall model.
• Little flexibility and adjusting scope is difficult and expensive.
• Software is developed during the implementation phase, so no early prototypes of the software are produced.
• Model doesn’t provide a clear path for problems found during testing phases.

Incremental Model

The incremental model is an intuitive approach to the waterfall model. Multiple development cycles take place here, making the life cycle a “multi-waterfall” cycle. Cycles are divided up into smaller, more easily managed iterations. Each iteration passes through the requirements, design, implementation and testing phases.
A working version of software is produced during the first iteration, so you have working software early on during the software life cycle. Subsequent iterations build on the initial software produced during the first iteration.
Incremental Life Cycle Model




Advantages
• Generates working software quickly and early during the software life cycle.
• More flexible – less costly to change scope and requirements.
• Easier to test and debug during a smaller iteration.
• Easier to manage risk because risky pieces are identified and handled during its iteration.
• Each iteration is an easily managed milestone.
Disadvantages
• Each phase of an iteration is rigid and do not overlap each other.
• Problems may arise pertaining to system architecture because not all requirements are gathered up front for the entire software life cycle.

Spiral Model

The spiral model is similar to the incremental model, with more emphases placed on risk analysis. The spiral model has four phases: Planning, Risk Analysis, Engineering and Evaluation. A software project repeatedly passes through these phases in iterations (called Spirals in this model). The baseline spiral, starting in the planning phase, requirements are gathered and risk is assessed. Each subsequent spirals builds on the baseline spiral.
Requirements are gathered during the planning phase. In the risk analysis phase, a process is undertaken to identify risk and alternate solutions. A prototype is produced at the end of the risk analysis phase.
Software is produced in the engineering phase, along with testing at the end of the phase. The evaluation phase allows the customer to evaluate the output of the project to date before the project continues to the next spiral.
In the spiral model, the angular component represents progress, and the radius of the spiral represents cost.
Spiral Life Cycle Model


Advantages
• High amount of risk analysis
• Good for large and mission-critical projects.
• Software is produced early in the software life cycle.
Disadvantages
• Can be a costly model to use.
• Risk analysis requires highly specific expertise.
• Project’s success is highly dependent on the risk analysis phase.
• Doesn’t work well for smaller projects.

And that’s it. If you have any input, especially your views on advantages and disadvantages of any particular model, feel free to leave them in the comments and I can add them to my copy.

Sunday, April 18, 2010

BASICS OF PL

IN THIS LESSON YOU WILL JUST GONA LEARN OR UNDERSTAND THE SCALAR VARIABLES
BELOW ARE NOT THE PROGRAMMED THEY ARE JUST THE SMALL ANONYMOUS BLOCK OR SMALL PROGRAME JUST TO MAKE A SENSE TO BEGINNERS THAT WHAT IS VARIABLES AND HOW THEY BEHAVE IN PL .

CREATING VARIABLES---

THERE ARE 4 TYPES OF VARIABLES IN PL----
USING 1ST TYPE SCALR VARIABLE-----
-------------------------------------------------------------------------------------
MAKE A ANONYMOUS BLOCK WHICH TAKE INPUT NAME , AND SHOW THE RESULT ..DEPT NO. SAL , AND JOb


DECLARE
MN VARCHAR2(50):='&NAME';
MDEPT NUMBER;
MSAL NUMBER;
MJOB VARCHAR2(50);
BEGIN
SELECT DEPTNO,SAL,JOB INTO MDEPT,MSAL,MJOB FROM EMP WHERE ENAME=MN;
&D(MN||' '||MDEPT||' '||MSAL||' '||MJOB);
END;
-------------------------------------------------------------------------------------
--FIND DATA FROM MULTIPLE TABLE BUT RESULT SHULD B IN SINGLE ROW ---

DECLARE
MN VARCHAR2(50):=UPPER('&NAME');
MJ VARCHAR2(50);
MSAL NUMBER;
MDN VARCHAR2(50);
MLOC VARCHAR2(50);
BEGIN
SELECT JOB,SAL,DNAME,LOC INTO MJ,MSAL,MDN,MLOC FROM EMP NATURAL JOIN DEPT WHERE ENAME=MN;
&D(MN||' '||MJ||' '||MSAL||' '||MDN||' '||MLOC);
END;

-------------------------------------------------------------------------------------
NOW MAKING A PROGRAME USING SCALAR VARIABLE WHICH INSERT RECORDS IN TABLE---
NOW IN SCLAR VARALBE WE GONA USE %TYPE IN THIS PROGRAME---
-------------------------------------------------------------------------------------
%TYPE TAKE THE SAME DATA TYPE WHICH USE IN THAT PARTICULAR CLOUMN IN TABLE---
USING %TYPE(PERCENTTYPE) VARIABLE--

DECLARE
EMID EMP.EMPNO%TYPE:='&EMPLOYEE_ID';
MEN EMP.ENAME%TYPE:=('&NAME');
MJ EMP.JOB%TYPE:='&JOB';
MSAL EMP.SAL%TYPE:=&SALERY;
BEGIN
INSERT INTO EMP(EMPNO,ENAME,JOB,SAL)VALUES(EMID,MEN,MJ,MSAL);
&D('YOUR RECORD INSERTS SUCESSFULLY');
END;
-------------------------------------------------------------------------------------
--NOW MAKE A PROGRAME IN WHICH YOU GONA UPDATE RECORDS IN TABLE USING %TYPE---


DECLARE
MEN EMP.ENAME%TYPE:=UPPER('&NAME');
MSAL EMP.SAL%TYPE:=&SALERY;
BEGIN
UPDATE EMP SET SAL=MSAL WHERE ENAME=MEN;
&D('YOUR RECORD UPDATED SUCESSFULLY');
END;
------------------------------------------------------------------------------------
-MAKE A PROGRAME TO DELETE RECORDS FROM TABLE USING %TYPE

DECLARE
MN EMP.ENAME%TYPE:=UPPER('&NAME');
BEGIN
DELETE FROM EMP WHERE ENAME=MN;
&D('YOUR RECORD HAS BEEN DELETED ');
END;



---SO WE WAS USING SCALAR VARIABLE WHICH HOLDS SINGLE VALUE AND DEPEND ON VARIABLE DATATYPE AS U SEE IN PREVIOUS PROGRAMME----

Saturday, April 17, 2010

oracle programming

SALAM N HELLO TO ALL
THIS IS MY BLOG FOR ALL PROGRAMMERS ...
IN THIS U WILL FIND EVERY SOLUTION AND LEARN NEW THINGS AS WELL



REGARDS,

MUHAMMAD ARSALAN HASHMI

SOFTWARE DEVELOPER

(ACTION SCRIPT,HTML,XMLSCRIPT,PL/SQL,SQL,ORACLE FORMS 10G, ORACLE REPORTS 10G)

ORACLE UNIVERSITY