msgbartop
News, views, tips and tricks on Oracle and other fun stuff
msgbarbottom

Did You Know That About PL/SQL Variables?

In his latest post titled Less is More, More or Less, John Russell, the man behind tahiti.oracle.com, reveals a very interesting fact about the space needed to store PL/SQL variables of varchar2 datatype. He writes:

If you don’t know exactly how much space is needed for a PL/SQL variable, the most space-efficient thing you can do is counter intuitive: declare a gigantic variable… Once you go above 2000 characters, the variable stops being statically allocated to accommodate its maximum size, and starts being dynamically allocated every time it’s assigned, based on the exact size that’s really needed.

He gives an example:

– Rest of 512 characters are wasted empty space
email_address varchar2(512) := ‘someone@example.com’;
– Although declared with length 32000, only 24 characters are allocated
email_address varchar2(32000) := ‘someone_else@example.com’;

I know that, using DUMP, you can return the length of a variable in bytes, but the question is how do you really calculate the total space allocated to a certain PL/SQL variable?

John also gives an additional tip:

When you want a variable to hold the contents of a table column, there is a simple way to match the right length: var1 my_table.my_column%type;

Using anchored type declarations is one of PL/SQL’s best practices. But, what if you have a variable that is a concatenation of two or more table columns? Here is the trick:

declare
cursor my_cursor is select col1 || col2 concatenated from my_table;
var2 my_cursor.concatenated%type;

We let Oracle figure out the maximum length of the concatenated columns, then piggyback on that result to make a variable of the same type.

John always has interesting tips. Here are 3 Useful SQL*Plus Tips I found on his blog a few weeks ago.

Filed in Oracle, Tips with 6 Comments | Tags: ,


5 Links from Around the Web (2007-05-25)

More from my bookmarks on del.icio.us

Filed in Links with 4 Comments | Tags: , ,


New Oracle Security Videos and Blog

Alexander Kornbrust of Red-Database-Security has started a new Oracle security blog (just added to OraNa.info). He also posted new Oracle security videos, 10 as of today.

Filed in Oracle, Security with Comments Off | Tags:


Infinite Scrolling at OraNA.info and New Oracle Bloggers Group

Aggregated by OraNA OraNA.info, the unofficial Oracle news and blogs aggregator, has a new look and cool new features:

  • OraNA now runs on WordPress, which means that, unlike the older version, OraNA is no more limited to showing only the latest 20 posts. It is still a River of News style aggregator, but the river has become as long as the Nile.

  • OraNA now supports infinite scrolling. You scroll and scroll and scroll infinitely. Basically, as soon as you get near the bottom of the page it automatically adds more posts (AJAX is so cool). No more “Next Page” and “Previous Page”, it’s virtually endless. Quick tip: use the space bar to scroll down and shift+space bar to scroll up.

  • OraNA has a cleaner look. Posts are clearly separated and authors are displayed below post titles.

  • OraNA now aggregates more Oracle blogs than ever, over 266 Oracle employee and non-employee blogs as of today.

If your blog is aggregated by OraNA.info you may:

  • add the “Aggregate by OraNA” button to your blog. Just copy the following HTML Code and paste it to your blog’s sidebar:

Google Groups
Subscribe to OraBloggers
Email:

The OraBloggers group is not really new. It was created back in January 2006 and currently has a few members. Maybe it’s time to revive it and use it as a public place to discuss the current affairs in the Oracle blogosphere or each others’ posts as Paul suggests, or whatever you like, you decide.

Filed in Oracle, WordPress with 6 Comments | Tags: , , ,


Guess Who Has a Trolley in His House

Larry Ellison Mansion Picture

This is one of uncle Larry‘s homes. He owns 12 properties in Malibu alone, with a total value of $180 million. This one is only $20 million. It has a cable railway that acts as a shuttle between the mansion and the pool. Impressive!

Source: Haute Living. Via: Valleywag.

Filed in Interesting Stuff, Oracle with 4 Comments | Tags: ,


Oracle Technology Network (OTN) is the Largest Developer Community

According to this SDA Asia Magazine article:

OTN has reportedly bumped pass the four hundred thousand member point making it the largest developer community for Oracle in the Asia Pacific region and second largest worldwide… OTN’s new position in the India market also translates to an increase in Oracle’s total online community in the country – comprising customers, partners, students, developers, technical specialists among others – to almost seven hundred thousand members.

Even though the article does not list the source for this information, judging from the increase in the number of Oracle related websites and blogs, the online Oracle community is indeed expanding.

By the way, is MSDN the largest developer community?

Filed in Oracle, Technology with 2 Comments | Tags:


The Easy Way to Generate an RSS Feed from Your Forum Posts

I stumbled upon Paul Gallagher’s blog from the OTN TechBlog. Paul created a Perl script that scrapes the HTML of an Oracle forum user profile web page and generates an RSS feed from that user’s most recent posts.

When I saw “HTML scraping” I immediately thought of Dapper. I have used Dapper before to generate a feed for only new questions posted on AskTom.

It took me just 5 minutes to create a new Dapper application that takes an Oracle forum user ID as an input and generates an RSS feed for the most recent posts from that user as output, without writing a single line of code (I’m lazy). You can get the user id from the user’s profile page. For example here is the feed for user ID 66 (Justin Cave):

http://www.dapper.net/transform.php?dappName=OraForumsByAuthor&transformer=RSS…variableArg_0=66

Just change 66 to the user ID of your choice to generate a feed for this user.

In addition to RSS, Dapper allows you to transform the data to other formats such as XML, Google Gadgets, Netvibes Modules, PageFlake, Google Maps, Email, CSV, JSON… But most interesting is a Flash widget that you can create and put on your blog or website:

 Add to your site powered by Dapper 

Cool! Check out the OraForumsByAuthor dapper homepage.

Filed in Oracle with 3 Comments | Tags:


Top Oracle Blogs Ranked by Technorati Authority

Recently, Technorati introduced the Technorati Authority. It is the number of blogs (not links) linking to a website in the last six months. The higher the number, the more Technorati Authority the blog has.

In addition to Authority, there is also the Technorati Rank. It is calculated based on how far you are from the top. The blog with the hightest Technorati Authority is the #1 ranked blog. The smaller your Technorati Rank, the closer you are to the top.

So, who is currently the most authoritative blogger in the Oracle blogosphere? To answer this question, which somehow I had a feeling to who that would be, I have compiled a list of blogs that are aggregated by OraNA.info and that have a Technorati Authority of 2 or more. I then sorted the list by Technorati Authority in a descending order.

Obviously, blogs that are not aggregated by OraNA.info or that do not have an authority yet are not included in the list. Without further ado, here is the list: (more…)

Filed in Oracle with 24 Comments | Tags: ,


5 Links from Around the Web (2007-05-04)

More from my bookmarks on del.icio.us…

Filed in Links with Comments Off | Tags:


Back to basics: anti-joins and semi-joins

I almost forgot that the Oracle Joins series is not complete yet. So here is the last episode, a quick and easy anti-join and semi-join refresher.

Anti-joins:
Anti-joins are written using the NOT EXISTS or NOT IN constructs. An anti-join between two tables returns rows from the first table for which there are no corresponding rows in the second table. In other words, it returns rows that fail to match the sub-query on the right side.

Suppose you want a list of departments with no employees. You could write a query like this:

SELECT   d.department_name
    FROM departments d
MINUS
SELECT   d.department_name
    FROM departments d, employees e
   WHERE d.department_id = e.department_id
ORDER BY department_name;

The above query will give the desired results, but it might be clearer to write the query using an anti-join:

SELECT   d.department_name
    FROM departments d
   WHERE NOT EXISTS (SELECT NULL
                       FROM employees e
                      WHERE e.department_id = d.department_id)
ORDER BY d.department_name;

Semi-joins:
Semi-joins are written using the EXISTS or IN constructs. A semi-join between two tables returns rows from the first table where one or more matches are found in the second table. The difference between a semi-join and a conventional join is that rows in the first table will be returned at most once.

Suppose you want a list of departments with at least one employee. You could write the query like this:

SELECT   d.department_name
    FROM departments d, employees e
   WHERE d.department_id = e.department_id
ORDER BY department_name;

The department name in the query result will appear as many times as the number of employees in it. So, for example if a department has 30 employees then that department will appear in the query output 30 times.

To eliminate the duplicate rows, you could use the DISTINCT or GROUP BY keywords. A more elegant solution is to use a semi-join between the departments and employees tables instead of a conventional join:

SELECT   d.department_name
    FROM departments d
   WHERE EXISTS (SELECT NULL
                   FROM employees e
                  WHERE e.department_id = d.department_id)
ORDER BY d.department_name;

The above query will list the departments that have at least one employee. The department will appear only once in the query output no matter how many employees it has.

Sources and Resources:

Filed in Joins, Oracle with 2 Comments | Tags: ,