SQL

Sunday, 18 June 2017

Create Entity and View Controller



In this tutorial I will demonstrate how we can insert data into the database. For this purpose I have used the HR Schema. We will create a new application called HumanResource. We will automate the process to create all entity and view. There will be approximately 20 steps to follow.







 Model is the Business components of your application. You can put any name here.





After successfully create the model and view controller your projects will look like similar to this: 





Your application overview page should be open as soon as you create your projects Model and View Controller. Now Here we have option to create connection for the database and also Build the business services.



Make sure before you follow up the tutorial you have oracle database installed and have a database which has the HR Schema.


You can provide any Connection name as you like. Please provide HR user name and its password correctly. Also SID is the database name that contain your HR Schema. Don't forget to test connection before going to the next step. 


In the next step, we will configure our Business Services. Go to the Sup steps:


Make sure you select model in the pop up



Here it will ask again to configure the database which we already did previous step.


When you come up to this point press the Query button to get all the tables.


Select tables according to your needs and click the blue arrow to put them from left to right. You can also Name the entity as you like 



We are not creating any Query based view object here so skip to the next step


Rename the Application module if you like:


                                  You can create a diagram if you like but that's not required

Before you finalize these process you will have an option to see the summery



After successfully create the model and View controller projects, your application will look like the following:




Download: HumanResource.zip




Friday, 16 June 2017

Entity Object 1

Entity Object:

An Entity Object provides an Object Oriented representation of a row of a Database Table or a View.
It exposes access methods for its attributes that correspond to a table or view to access and manipulate the data. Attributes are simply the field or column of a table or a view. The ADF business components base class that implements the default entity behavior is EntityImpl.

<Entity> Impl

The Entity Implementation class (EntityImpl) class allows developer to expose typed attribute setter and getter methods , create attribute validations methods, access child collection in a master detail relation , retrieve the entity object key or modify the entity create and DML behavior.

<Entity> DefImpl

This class exposes methods to create new entity instances, find existinf entity instances and access entity properties.

Lets show an example:



Here EmployeeId is the primary key and it has a custom property CreateSequence which refers to database sequence EMPLOYEE_SEQ. If we intent to work with this property than <Entity>Impl may have following procedure to follow:




Saturday, 27 May 2017

SQL 5: Join and Sub Queries Part 1


For this tutorial I will use the well known HR Schema of Oracle.There are several ways we can proceed to get the results. But here I am not showing the efficiency but the technique. This is a open question for the readers to find the more efficient result. The tricky part about Sub Queries and join are to figure that out which part will be on the sub query.
Scenario:

Find All employee and their job id and title.

Using Natural Join:

A NATURAL JOIN is a JOIN operation that creates an implicit join clause for you based on the common columns in the two tables being joined. Common columns are columns that have the same name in both tables.






Using Sub Query inside from. When we use sub query inside from then the fields are virtually becomes table name.




As we have seen some of the sub query. Let's try another one:

Scenario:

What about to find the Max Salary of all department?





Scenario:

Find First name, Last Name, department name and salary of all employees Descending order



Scenario:

Find Employee id, department name, Employee First name and the city where the department belongs.









SQL 4: Meta Data

Get the table name, owner and table space name beside user ="MITHUN"



Get all table name , owner and table space from a database






Saturday, 20 February 2016

PL/SQL Excercise 2


6. The Following PL/SQL will provide you all table name from a user table




SP

S

P






TOO MANY ROWS





TOO MANY ROWS





0 ROW NO DATA FOUND







JONES
SMITH

Statement processed.

PL/SQL Excercise 1







ADAMS

Statement processed.





11 Suppliers selected



The above Example also can be written as follows:



This Example canbe witten using a cursor as well.





S1 SMITH 20 LONDON
S2 JONES 10 PARIS
S3 BLAKE 30 PARIS
S4 CLARK 20 LONDON
S5 ADAMS 30 ATHENS





Number of suppliers in LONDON = 2





S1 SMITH 20 LONDON
S4 CLARK 20 LONDON

Statement processed.

PL/SQL







ADAMS

Statement processed.





11 Suppliers selected



The above Example also can be written as follows:



This Example canbe witten using a cursor as well.





S1 SMITH 20 LONDON
S2 JONES 10 PARIS
S3 BLAKE 30 PARIS
S4 CLARK 20 LONDON
S5 ADAMS 30 ATHENS





Number of suppliers in LONDON = 2