Apr 23, 2009

Packages in pl/sql



A simple example

package specification

SQL> create or replace package calculator
  2  as 
  3   procedure addition(n1 number,n2 number,add OUT number);
  4   procedure mul(no1 number,no2 number,product OUT number);
  5   end calculator;
  6  /

Package created.

package body

SQL> create or replace package body calculator
  2  is
  3  Procedure addition(n1 number,n2 number,add OUT number)
  4  as
  5  begin
  6  add := n1+n2;
  7  dbms_output.put_line(add);
  8  end addition;
  9  Procedure mul(no1 number,no2 number,product OUT number)
 10  as
 11  begin
 12  product := no1*no2;
 13  dbms_output.put_line(product);
 14  end mul;
 15  end calculator;
 16  /

Package body created.

SQL> var jose number;
SQL> exec calculator.addition(23,6,:jose);
29

PL/SQL procedure successfully completed.


Removing packages


Drop package package_name;

Drop package body package_name;



Bodiless package

SQL> CREATE OR REPLACE PACKAGE CONSTANTS
  2  IS
  3  PI NUMBER := 3.14;
  4  END CONSTANTS;
  5  /

SQL> EXEC DBMS_OUTPUT.PUT_LINE(CONSTANTS.PI);

3.14

To execute a package memeber


EXEC PACKAGE_NAME.function()[or procedure() or constant]




Method overloading possible inside package 

  1  create procedure B(a number)
  2  is
  3  begin
  4  dbms_output.put_line(a);
  5* end;
SQL> /

Procedure created.

SQL> create procedure B(a number,b number)
  2  is 
  3   begin
  4   dbms_output.put_line(a||b);
  5  end;
  6  /
create procedure B(a number,b number)
                 *
ERROR at line 1:
ORA-00955: name is already used by an existing object

But by using packages we can overload the above procedures...

Misc

SQL> create package pp
  2  as
  3  procedure pop(v varchar2);
  4  procedure pop(x varchar2);
  5  end;
  6  /

Package created.

To execute above use 

exec pp.pop(x=>’kar’);
exec.pp.pop(v=>’sel’):



One time only procedure

 It has no package body with in the package specification itself procedure definition is coded...Refer book

Advantages:


1.Security (Granting privileges)
2.Global access (Sharable objects)
3.Modularity (Grouping related objects)
4.Min disk space


points to remember:

The variables that are declared inside package specification are called public scope variables and those with in package body are called private.
Variables declared inside the package specification have NULL value if not initialized.
The public variables can be used or re initialized inside a package or in the exec statement.
We can invoke a function from a procedure inside the same package just by calling its name and appropriate parameter passing.
Package within another package not allowed.
Cursor variables cannot be declared inside package specification it can be used only inside pl-sql block.


Pragma restrict_references(funname,wnds,wnps,rnds,rnps)




Feb 20, 2009

SUN quiz

Here's your first look at a range of new and exciting benefits available only to Sun Developer Network members. Lots of free training being offered this quarter. Just another example of how your all access Backstage Pass from Sun is working for you.

SDN Quiz Sweepstakes — Test your NetBeans IDE Knowledge 
Take the SDN Quiz to see how much you know about NetBeans IDE. Answer the questions correctly for a chance to win one of 50 free service requests (single instance) through the Developer Expert Assistance Program (US $49) 
Take the quiz now! 

New Features in Project Kenai! 
We've been busy worker bees building additional features in Project Kenai. We're rolling out SCM support for a directory file system for your download area, and Atom feeds for your wikis. Use your SDN credentials to log in. Want to host an open source project at Kenai? Please send an invitation request e-mail to: kenai-admin@sun.com. Also look at auto insurance for teenagers

C ptrs

Ptr
Ptr2ptr
Void ptr
Fn ptr
Void ptr fn (not like void ptr)
Pointer to an array
Array of ptrs
 

 Int *p;

 There will be a memory space reserved for 2 bytes which can store address of integer type.

 &p represents address of the pointer variable. Mostly we won’t use this..

P = &somevariable

That Is P will gives the address of the variable it points to.

*p= some value , will make somevariable to assign some value.

 We can have **p ,***p,****p so on…

 Always p can hold some address of int type…

 Int in int *p implies the somwvariable value is of int type…

 Char in char *p implies somevariable value is of char type…

 Void in void *p implies the somevariable can be of any type.. it is known only at run time…

 We can also have pointer functions…

 Consider a function int p(int a) that returns ‘a’ value

Int (*ptf) (int) = &p; // the braces are mandatory…

 also we can call like ptf = p;

 We can invoke the function by 2 way..

 P(2);

(*ptf) (2);

 Both will return 2 as output.

 
these thing will work fine in laptop memory

sample program

# include

# include

 

 void func1(int (*a)[10][10])

{

printf("%d  ",a);

}

void func2(int a[][][])

{

printf("%d",a);

}

 

 

int main()

{

int a[10][10][10],b[10];

printf("%d   ",a);

func1(a);

func2(a);

 

getch();

return 0;

}

 




Feb 2, 2009

Discovering the best of Europe

Europe offers some of the world’s most exciting cities, romantic landscapes, outstanding museums, historic sights, culinary creations, and architectural wonders. You can sail past decaying palaces and sinking churches on Venice’s Grand Canal for the price of a bus ticket. You can drain creamy mugs of Guinness while clapping along to traditional Celtic music on a pub-crawl through Dublin. You can splurge on a 5-star meal in Paris, the Mecca of haute cuisine. Or you can wander through the Tower of London, ground

Zero for so much English history over the last 900 years. You may want to stare for hours at the famed scene of God Creating Adam on Michelangelo’s Sistine Chapel ceiling in Rome. Or sit atop Switzerland’s Schilthorn Mountain, surrounded by peaks covered with

snow and glacier-filled valleys, while eating breakfast in a revolving restaurant at 10,000 feet. Or enjoy a picnic lunch on the Greek island of SantorĂ­ni hundreds of feet above the Mediterranean amid the ruins of a Mycenaean city. Europe is yours to discover and experience. Dont ever forget to visit at extended stay hotels there...

Jan 12, 2009

Just for fun!!!

The local bar was so sure that its bartender was the strongest man around that they offered a standing $1,000.00 bet. The bartender would squeeze a lemon until all the juice ran into a glass, and hand the lemon to a patron. Anyone who could squeeze one more drop of juice out would win the money. Many people had tried over time (weightlifters, longshoremen, etc.) but nobody could do it.One day this scrawny little man came in, wearing thick glasses and a polyester suit, and said in a tiny, squeaky voice, "I'd like to try the bet."

After the laughter had died down, the bartender said OK, grabbed a lemon, and squeezed away. Then he handed the wrinkled remains of the rind to the little man. But the crowd's laughter turned to total silence as the man clenched his fist around the lemon and six drops fell into the glass.As the crowd cheered, the bartender paid the $1,000.00, and asked the little man, "what do you do for a living? Are you a lumberjack, a weightlifter, or what?"

The man replied, "I work for the las vegas hotel Income Tax Department."

Dec 21, 2008

Life insurance


Life insurance has become more important these days. It helps  when u are in desperate need. It's just like a saving for noble cause. That too of your family's cause. There are so many forums that guides u step by step procedure to avail for life insurance. Nearly hundreds of companies are offering so many policies. Really a difficult task to chose which is best ? The clear cut solution for this problem is life insurance rates. It tells u excatly what is behind a particualr policy. The forum members never trust in giving obscure data. They give unbiased reviews on various life insurance policies. Customer support is the prime aim of the organisation.I am sure u all will like it's service. 

 What for you waiting still ??? Just go and enroll today. Just spread the word to your friends.