WP Remix
Learning and Technology never Cease to Change

Programming

23
May
We create many tables in a schema with lot of Constraints among them. The linking constraint Foreign Key which exists among tables will sometime create spaghetti schema. Consider a schema with 4 tables as show in the ER diagram below. (You can download the script for creating these tables and constrains)

It may be some times required to fetch the foreign key relationship between tables to identify the Parent-Child relationship. To identify those you can use the following queries will be handy for you. This query uses the sys user’s constraint definition tables for the database.
To Identify the Tables referencing the Given Table:


select ro.name table_name,
substr(initcap(cc.column_name), 1, 30) column_name, cc.position,
cn.name constraint_name, ru.name owner
from sys.obj$ o, sys.user$ u, sys.con$ cn, sys.cdef$ c, sys.obj$ ro,
dba_cons_columns cc, sys.con$ rcn, sys.user$ ru
where o.owner# = u.user#
and u.name = ‘&&SCHEMANAME’
and o.name = ‘&&TABLENAME’
and c.robj# = o.obj#
and c.con# = cn.con#
and ro.obj# = c.obj#
and cc.owner = u.name
and cc.table_name = o.name
and rcn.con# = c.rcon#
and cn.owner# = ru.user#
and c.type# = 4
and cc.constraint_name = rcn.name
order by u.name, ro.name, cn.name, cc.position;

To Identify the Tables referred by the Given Table:


select a.table_name, initcap(b.column_name) column_name, b.position,
a.constraint_name, a.owner
from (select ao.name table_name,
au.name owner,
bcn.name constraint_name,
decode(ac.type#, 4,
decode(ac.refact, 1, ‘CASCADE’, 2, ‘SET NULL’, ‘NO ACTION’),
null) delete_rule,
bo.name tn
from sys.cdef$ bc, sys.con$ bcn, sys.obj$ bo, sys.user$ bu,
sys.con$ brc, sys.user$ bru, sys.obj$ bro,
sys.cdef$ ac, sys.con$ acn, sys.obj$ ao, sys.user$ au
where bc.con# = bcn.con#
and bc.obj# = bo.obj#
and bo.owner# = bu.user#
and bu.name = ‘&&SCHEMANAME’
and bo.name = ‘&&TABLENAME’
and bc.rcon# = brc.con#(+)
and brc.owner# = bru.user#(+)
and bc.robj# = bro.obj#(+)
and ac.con# = bc.rcon#
and ac.con# = acn.con#
and ao.obj# = ac.obj#
and ao.owner# = au.user#
and ac.type# in (2,3)) a,
dba_cons_columns b
where b.table_name = a.tn
and b.constraint_name = a.constraint_name
order by a.table_name, a.constraint_name, b.position;

Hope this is useful for you at times :)

Category : Programming | Blog
21
May
After a long time, let me write a bit of Oracle this week. Improve the performance of multi-row SQL operations with bulk/array processing in PL/SQL. For code snippets of the form


cursor emp_cur is
select employee_id
from employee where department_id = dept_in;

begin
for rec in emp_cur loop
update employee set salary = salary + 1000
where employee_id = rec.employee_id;
end loop;
end;

Bulk processing of PL/SQL can be used to improve its performance to greater levels. Use the FORALL and BULKCOLLECT of PL/SQL that will scale the application. The code snippet can be changed to

select employee_id
bulk collect into collection_var
from employee where department_id = dept_in;

begin
forall i in collection_var.first .. collection_var.last
update employee set salary = salary + 1000
where employee_id = collection_var(i);
end;

The context switch happening in executing PL/SQL and SQL code is reduced in this. The Save Exceptions and SQL%BULK_EXCEPTION is another good introduction on excellent exception handling on these bulk processing.
Category : Programming | Blog
9
May
As a programmer, I feel every one who program must have their own commitment in job to the maximum. There are people like this not only as contractor but also as experience professionals who add up their experience profile always and update their technologies knowledge profile with whatever technology the project has instead of what they work on. They merely try to exist in the new assignment, by the time their Incompetency strips they are already on their way to be as senior tech lead or architect in any one of the numerous software startups.

After all this ending up as senior software architect like this in some big Servicing companies. Finally the developer’s will be put in an impression that the architect has coded more than millions of lines. I did not stick to the point that all architects must sit and write programs, they must have some relevant knowledge on programming, which will really help them in giving better solution, and sure they can get efficient work from developers.

Category : Programming | Blog
4
May

Generating CSV files from tables is a task which we do many a times. But as I said Oracle 10g gives many features , this is really cool, simple solution using xml and regular expressions in a single query.

Withouth specifying the column names is the good point to note :)

Category : Programming | Blog
3
May

I am in a Oracle 10g developer’s workshop. In these two days some interesting things in Oracle 10g which I found are,

  • Automatic SQL Tuning in Oracle Database 10g using the DBMS_SQLTUNE. On good illustrations you can use this.
  • Resumable timeout, this really saves most of the time in redoing things due to a small mistake we failed to notice. At least for me it will save loads of time on schema imports. You must have a deep look into this.
  • File Transfers, using oracle this will really make database programming stronger.
  • Conditional Compilation will really make debugging easier (Inherits A ‘C’ Language #ifdef Feature).
  • Pattern Matching, this regular expression will give some Java edge.

To try out new features of 10g, you can always request a workspace from oracle at this place.

Category : Programming | Blog
19
April
Once in my post I mentioned about Software Versioning, which is real need in Software Industry. Programming is only a first step, and we don’t work in the stone age of programming where only one person programs the complete requirement.

Today collaborated programming is what in practices. We work as a team for developing a same requirement. To effectively maintain the programs written by different people version control systems like Clearcase , SourceSafe came into use.These configuration management tools came to make programmers life easier.

But every action has an opposite reaction; a new problem came up on integration of VCS usage with the programming. Whenever we make changes, it required a check-out and check-in. Since editors were not convenient to program where we are bound to make typographical errors on function names and syntax, then raised the IDEs and RCPs as the assistants with inbuilt dynamic help features, compilers and debuggers in it.

The IDEs also incorporated the features to use the VCS more effectively. Checkouts on touch of the file, Check-in on save and many more features to make our life simpler in programming, to concentrate only on logic. But there exists still configuration management problem in many places as head aches of the projects like the build break-up mentioned in this post.

I started of with this post, because of a discussion which I had sometime back on having database only for storing data, in which I felt the ease of use in IDEs had made them take some wrong design decisions. Allured by the new fancy frameworks we leave out designs. Frameworks and IDEs alone will not solve scalability and performance problems. Design of the application will solve that.

Frameworks helps in rendering a good application with a structured and organized code, but if a simple search page will take 3–4 minutes what good the framework does. Even unorganized codes give a better performance, which one would we choose. Since hard-coding is required in some places we make the code very complex instead of a simple code. So giving importance to a good design is very important and we should not get carried away with new up coming technologies. Looking for solutions which would suit our need is important, rather than making our Application change according to new technology or frame work.

Category : Programming | Blog
12
April
Today, I was doing the so called load testing, along with my colleagues in my project. But this screen turned me off. Why cant applications be compatible with all kind of browsers. The basic work done by Netscape or an IE or fire-fox in fetching pages will be same.

Why can’t then application use features common across browsers, as many things are getting standardized day-by- day. These basic things must be kept in mind while developing a web application.

I think every on must have a look on developing application simpler , but effective one.

Category : Programming | Blog
3
April
Learning with passion is what I wanted to do. In the past ten months in programming with SQL and PL/SQL, I spend sometime always for AskTom, Steven Feuerstein’s Oracle PL/SQL programmming, Oracle-Base by Tim and other Oracle Ace Blogs.

Last week I came across this post by Tim in his oracle-base blog. I realized many things on that when yesterday i was trying an Insert statement in oracle for inserting in more than one table. When i Googled my requirement of inserting in more than one table, the Oracle Documentation just banged in right front of me as topmost search result. The multi-table insert where lucidly explained in the documentation. Though I always like reading out for many advance concepts in oracle it was something very basic which I have missed, which was given right in the first page.

Now My Commandment is : “Thou shall not miss reading the Oracle Documentation”

Category : Programming | Blog
26
March
I stumbled today on this term ‘Ad Hominem’ argument. It was quite interesting, since most of the time we face this in our work environments in the form Design reviewer or as code reviewer or finally as appraiser. They try to attack the person rather than on the subject where it started.. they some time divert from reviewing the code to reviewing the coder….

That was rightly pointed in Jeff Atwood blog on the Top 10 Commandments of Egoless Programming , it was really interesting…you can shell some time on it..I am sure you will enjoy it..

Critique code instead of people— be kind to the coder, not to the code.

Program and Programmer are different…!

Category : Programming | Blog
9
March

Though I work with Oracle DB for the past nine months religiously this is my first post anywhere related to oracle. Its high time , I thought to give some post on Oracle ,which are though not something which was never found by any other people but it was quite interesting for me when I first tried it. Though there are many virtuosos on oracle blogging around the world vigorously on oracle, I also wanted to be a small part on this big knowledge sharing base.
Concatenating the rows of the table will always be required when you are working with database. At those time the following query would be handy for you.

hari9ir2@GENEVART>create table t(
2 name varchar2(20));
Table created.
hari9ir2@GENEVART>
INSERT INTO t VALUES(’Hari’);
1 row created.
hari9ir2@GENEVART>
INSERT INTO t VALUES(’Haran’);
1 row created.
hari9ir2@GENEVART>
INSERT INTO t VALUES(’Ragunathan’);
1 row created.

SELECT LTRIM(MAX(
SYS_CONNECT_BY_PATH(NAME , ‘ ‘)),’ ‘)AS Full_Name
FROM (SELECT NAME , ROWNUM rn FROM t)
START WITH rn = 1
CONNECT BY PRIOR rn = rn -1;

FULL_NAME
————————
Hari Haran Ragunathan

To know more on the this refer this column in oracle magazine - On Favorites and Connect by .
Hope this tip could be useful for you.

Category : Programming | Blog