Posts Tagged ‘oracle’

We’ve had problems with that!

So what can I say? One of the phrases I hate most is “We’ve had problems with that.” I have seen that, or some form of that, question used as an excuse to not try new features, to not use best practices, keep a head in the sand, stick to Oracle7 features, etc.

As an example, in my early days with data modeling, I once created a new schema. It wasn’t a very big schema; probably 10 tables or less. I spent a lot of time doing the analysis to make sure I got the data structures correct. The ERD was sent around and got approval from everyone.

Click to continue reading “We’ve had problems with that!”

Read the rest of this entry »

Stupid Proc Tricks -The Weird and Wonderful Overload

When overloading a procedure or function it is the calling parameters that make the difference. The return type does not make a difference as far as the ability to overload. Generally, when talking about overloaded procedures, you will hear or read something like “You must change at least one of the parameter data types to overload it.” But that’s not really true.

Click to continue reading “Stupid Proc Tricks -The Weird and Wonderful Overload”

Read the rest of this entry »

Designing the Data Mart – Part 1

As I mentioned a while back (a loooong while back), I have been thinking about writing up how I design data marts. The problem with that is that it is a huge topic. Even converting an existing schema (which doesn’t always exist) to a data mart (star schema style), still takes plenty of behind the scenes data analysis and prepwork. Still, I am not going to take a shot at it.

I could start with a laundry list of requirements but I don’t think that would be interesting to very many people.

Click to continue reading “Designing the Data Mart – Part 1″

Read the rest of this entry »

PL/JSON v0.6.2 Released

It was pointed out to me that I had a few errors in the previous release.  Those have been fixed and the install should go a lot smoother now.  No additional functionality here, just bug fixes.  If you tweaked the previous release to install it, you don’t need this one.

As always, you can download the new code directly from the PL/JSON SourceForge page.

Change Log:

Version: 0.6.2
Fixed exit commands in various code files
Removed the “CREATE OR REPLACE” on the string_handler.printf function

Version: 0.6.1
Added missing string_handler package

Version: 0.6
Added support for creating JSON from text input

Version 0.5
Initial release
Includes a JSON data type
Can create tables and columns of JSON
Supports API creation of JSON data type

LewisC

Read the rest of this entry »

Oracle INFORMATION_SCHEMA

From the Database Geek.

Part of the ANSI SQL standard calls for an INFORMATION_SCHEMA. This schema contains a standardized data dictionary that is (or is supposed to be) common across various databases. Most database vendors offer a native data dictionary and a sub-set INFORMATION_SCHEMA (called info schema from this point on). Oracle is the only major database vendor (that I know of) that doesn’t even offer a subset of the info schema.

Oracle’s data dictionary (especially if you include the V$ views in that) is the most robust of all the databases I have used.

Click to continue reading “Oracle INFORMATION_SCHEMA”

Read the rest of this entry »

PL/JSON v0.6 Released to SourceForge

From the Database Geek.

PL/JSON v0.6.1 has now been released to Sourceforge.net. The reason for the .1 is that I forgot a dependency on the 0.6 release.

Anyway, PL/JSON can now create JSON via the API or through parsing a text string. The parser is implemented as a stand along package. That means you can write your own parser (or use an external procedure) if you don’t like mine. This will make it very extensible. I also plan to add PL/SQL callbacks to the parser at some point for custom processing.

Example of parsing:

SET SERVEROUTPUT ON

DECLARE
  v_json json;
  v_json2 VARCHAR2(32000) :=
   '{
      "abc": "dpkxvdvvcxz\"vxasasa   ",
      "def": 12345,
      "ghi":{"isit":true, "nope":false,"denada":true },
      "jkl": [1234, 45678.99, 121211, 21323232, 00000]
   }';
BEGIN

  v_json := json(v_json2);
  v_json.print;
END;
/

{
"abc":"dpkxvdvvcxz\"vxasasa   ",
"def":12345,
"ghi":{
"isit":true,
"nope":false,
"denada":true}
,
"jkl":[1234,45678.99,121211,21323232,0]}

Output from PL/JSON checks out on JSONLint.

Click to continue reading “PL/JSON v0.6 Released to SourceForge”

Read the rest of this entry »

Use a Pipelined Function to Select Source Code Arguments

From the Database Geek.

I recently needed to query all of the arguments to the various stored procedures, functions, packaged objects and types. Oracle provides all of this information in the data dictionary in the ALL_PROCEDURES and ALL_ARGUMENTS views. The problem with this is that it’s kind of kludgey to suck out all of the pertinent data.

One problem is that arguments for procedures and functions in packages is access differently than arguments for stand alone procedures and functions. What I did was combine the two calls into a single pipelined function that returned the data I needed.

Click to continue reading “Use a Pipelined Function to Select Source Code Arguments”

Read the rest of this entry »

Stupid Database Tricks – Shutdown the server from a stored procedure

From the Database Geek.

I’m not even going to try to explain why I wrote this. Let’s just say that it comes in handy on occasion.

What this very simple procedure does is use DBMS_SCHEDULER to execute a shutdown command in windows. This could easily be adapted to Unix and/or Linux.

Use at your own risk. By default you get a 30 or 60 second delay (depending on windows version, I think) before the shutdown/reboot.

If you pass FALSE in to the procedure, or don’t pass anything, the server will shutdown. If you pass in a TRUE, the server will reboot.

Click to continue reading “Stupid Database Tricks – Shutdown the server from a stored procedure”

Read the rest of this entry »

ORA_Tweet Now Does Short URLs

Paul Gallagher, of the Tardate blog, emailed me this morning (or I guess it was last night) and sent me some code to enhace ORA_Tweet.  He wrote a package to call out to an is.gd API to convert a long URL to a short URL.  The really cool thing is that he used a regular expression to find matches INSIDE the comment body.  That means that ANY URLs will be replaced with a short URL, you don’t have to call the API individually.

His API is easily called and can be used for projects other than just ORA_Tweet.  Check out his write up on the SHORTURL package:  Tweeting from your database with short urls

I updated the ora_tweet code so you can download the entire set of code if you would like.

Click to continue reading “ORA_Tweet Now Does Short URLs”

Read the rest of this entry »

Private vs Public Global Variables

Recently I posted an article about ORA_Tweet, an Oracle Twitter Client. I was asked by someone reading the code why I put several variables in the BODY of the package rather than the SPEC. The question was posed something like this:

Why not put the variables in the package spec where they are modifiable? That would involve less maintenance.

I specifically put them in the body so that they are not modifiable. I don’t see public global variables as a particularly good thing. To understand why, let’s take a look at the benefits of a package.

First, you can group logical functions and procedures together.

Click to continue reading “Private vs Public Global Variables”

Read the rest of this entry »

JSON In (and out) of Oracle – JSON Data Type

From the database geek.

Update March 29, 2009:  PL/JSON is now available as an open source project (MIT License).  Read the FAQ at http://oracleoss.com

Do you use JSON? Do you use Oracle? How would you like to use JSON in Oracle? How would you like to store it, generate it and read it? I am creating a new JSON data type that will work like XMLType.

I am assuming you are familiar with Oracle (or you probably wouldn’t be reading this blog). If you are not familiar with JSON it is JavaScript Object Notation, a lightweight data-interchange specification. Think of it as a replacement to XML.

Click to continue reading “JSON In (and out) of Oracle – JSON Data Type”

Read the rest of this entry »

Ora_Tweet – Tweet From Oracle, A PL/SQL Twitter API

Get the latest source from the ORA Tweet project page at sourceforge.

I had some free time this last Saturday night (after the family was all in bed) and I wanted to do a little mini-project. I don’t get to do enough PL/SQL anymore so I like to look for utilities and smaller fun things to code. While I was thinking about it, I was also following along on twitter to the posts that the people I follow had recently made.

I decided to put together a twitter procedure that would let me make posts from the database.

Click to continue reading “Ora_Tweet – Tweet From Oracle, A PL/SQL Twitter API”

Read the rest of this entry »

Oracle Data Types – 5 FAQs About Number

I get a lot of email, and comments on blog entries, asking questions about many different topics. I am going to try to answer some of the more common questions as FAQs. Today I am starting with some NUMBER FAQs. I am specifically talking about Oracle and I am specifically talking about the NUMBER data type, not numerics in general. I’ve written about NUMBERs before.

Q: What is the difference between an INTEGER and a NUMBER.

A: INTEGER is a subtype of NUMBER. INTEGER is declared as NUMBER(38,0). That means it is a “constrained” NUMBER.

Click to continue reading “Oracle Data Types – 5 FAQs About Number”

Read the rest of this entry »

Advanced Queues and Streams: A Definition in Plain English

A mathematician, an accountant and an economist apply for the same job. The interviewer calls in the mathematician and asks “What do two plus two equal?”

The mathematician replies “Four.”

The interviewer asks “Four, exactly?” The mathematician looks at the interviewer incredulously and says “Yes, four, exactly.”

Then the interviewer calls in the accountant and asks the same question “What do two plus two equal?” The accountant says “On average, four – give or take ten percent, but on average, four.”

Then the interviewer calls in the economist and poses the same question “What do two plus two equal?”

The economist gets up, locks the door, closes the shade, sits down next to the interviewer and says “What do you want it to equal?”

And now for something completely different:

What is AQ?

Advanced Queues, or AQ, is Oracle’s messaging solution.

Click to continue reading “Advanced Queues and Streams: A Definition in Plain English”

Read the rest of this entry »

My Introduction

Welcome to my blog. My name is Lewis R Cunningham and I’m an Oracle geek. I love playing with Oracle, working with Oracle and sharing what I know about Oracle. In my travels as a consultant and employee, I have found that, in the Oracle world at least, managers, project leads, etc. often have to make decisions regarding their projects, employees and day to day operations with very little, and/or erroneous, information. These decisions often negatively impact the business bottom line and ongoing projects. The lack of information can be caused by an incomplete team, a lack of communication inside the team or even ego or attitude problems.

My goal with this blog will be to remove some of the mystery surrounding Oracle technology and to describe ways to integrate that technology in various projects and business areas.

Click to continue reading “My Introduction”

Read the rest of this entry »

When WHEN OTHERS is Evil

From the Database Geek.

As regular readers of my blogs know, one of the things I am is a non-absolutist. I try to never say never or always. Take WHEN OTHERS. I have worked in places where using WHEN OTHERS was banned. I think that’s silly. Nothing wrong with a WHEN OTHERS that logs an error. Right?

We recently had a situation that did just that. The problem was that the exception handler logged the SQLCODE and the SQLERRM (no stack info). This is an old piece of code being updated for some new functionality. Not a complete re-write, just some changes.

Click to continue reading “When WHEN OTHERS is Evil”

Read the rest of this entry »

uCertify Oracle Certification Software Review

From the Database-Geek.

In addition to frequently being asked to recommend books for newbies to Oracle, I am also asked for guidance on certification. Basically, what materials are available and worth purchasing. I used Self Test software and the Sybex books when I was working on my certification. That was back in the 9i days. If you are working on 9i certification, I strongly recommend them. ;-)

However, I figure you are probably working on an 11g certification; 10g at least. In that case, I would guess that Sybex and Self Test are still good options, I just haven’t personally worked with the latest versions (software or books).

Click to continue reading “uCertify Oracle Certification Software Review”

Read the rest of this entry »

Building a PL/SQL Code Parser (using PL/SQL), Part 3

From the Database-Geek.

Continuing with the parser, begun week in PL/SQL Parser Part 1 and PL/SQL Parser Part 2, today I am going to modify the code to account for keywords, operators and data. By data, I don’t mean strings. I mean anything not a keyword, not a comment and not an operator. Data may be a quoted string (which we accounted for in Part 2), but it is also non-language functions and procedures. If you call a user defined procedure, that procedure call is considered data (at least it is here, for now).

In the code presented below, I have done several things.

Click to continue reading “Building a PL/SQL Code Parser (using PL/SQL), Part 3″

Read the rest of this entry »

Building a PL/SQL Code Parser (using PL/SQL), Part 2

From the Database-Geek.

Continuing with the parser, begun last week in Building a PL/SQL Code Parser Part 1, today I am going to modify the code to allow for comments. Rather than dive back into code already covered, I will discuss what I have added and then provide the full code below.

I changed my sample code and test proc to a new format:

declare

  v_string varchar2(32000) :=
  'CREATE OR REPLACE PROCEDURE yada' || chr(10)  ||
      ' AS ' || chr(10) ||
      ' /* This is a comment */  ' || chr(10) ||
     ' BEGIN' || chr(10) ||
     '   DBMS_OUTPUT.PUT_LINE(''string with a space'' ||' || chr(10) ||
     '   ''string with emb''''edd''''''''ed quotes'');' || chr(10) ||
     '   -- second_func(''test'');' || chr(10) ||
     ' END;' ;

begin

  v_string := lrc_plsql_parser.parse_line(v_string);

END;

Notice that in addition to the comments, I have added line feeds.

Click to continue reading “Building a PL/SQL Code Parser (using PL/SQL), Part 2″

Read the rest of this entry »

Group By Grouping Sets

Posted by the Database-Geek.

Summary Totals Using SQL

Have you ever needed to get totals for different combinations of columns in the same query? Did you ever want to create a nice little report from a simple SQL statement? Here’s a tip that can make your life a lot easier when you need it. The great thing about this is that you can use it in a ref cursor called from other programming languages and reduce the number of calls you need to make to the database.

Let’s say you are running queries against the Employees table of the sample HR schema provided by Oracle.

SQL> SELECT count(*) FROM Employees;

  COUNT(*)
----------
       107

Now, we want to get a total of salaries for each job in each department.

Click to continue reading “Group By Grouping Sets”

Read the rest of this entry »

Building a PL/SQL Code Parser (using PL/SQL), Part 1

LewisC’s An Expert’s Guide to Oracle Technology

Is it possible to build a PL/SQL parser using nothing but PL/SQL? To answer that question, I guess I need to define “PL/SQL parser”. What would be the intention of this parser?

I would like a way to parse a PL/SQL code block and let me determine some statistics: number of lines, number of keywords, number of DML statements. It would need to recognize comments. I also want to be able to format the code for pretty printing. I want to be able to apply user defined checks for adherence to coding standards.

Click to continue reading “Building a PL/SQL Code Parser (using PL/SQL), Part 1″

Read the rest of this entry »

PL/XML – XML Based Scripting for PL/SQL

I started working on a task for a project and decided that there were some very good properties that I could use to help me teach people PL/SQL and XML. I expanded a bit on the idea and ended up with a scripting language, implemented in XML, that can be passed into a PL/SQL procedure. The script can execute stored procedures, it has looping logic, conditional (CASE) logic, user defined variables, etc.

The nice thing about it is that it’s very easy to read and modify. The XML structure is also very easy to read.

Click to continue reading “PL/XML – XML Based Scripting for PL/SQL”

Read the rest of this entry »

XML in the Database: A Brief Overview

Oracle provides a lot of XML functionality in the database. This entry will cover the different tools Oracle provides and future entries will get into the details of each.

The three primary XML tools that oracle provides are: XML Developers Kit (XDK), XML DB and SQL Extensions for XML (SQLX and XMLType). Below is a definition of each.

XDK

The XDK is a complete XML development toolkit that was introduced for 8i. I think the first version was labeled XDK9i but the toolkit actually was available for 8i. I remember using the beta product.

Click to continue reading “XML in the Database: A Brief Overview”

Read the rest of this entry »

Oracle Objects, Types and Collections: Part 1

I could have called this OO In Oracle: A Techie’s View. But the Sorcerer of OO is a much cooler title. ;-) You have to pronounce OO as ooh! as in Ooh and Aah!

What is OO? OO stands for Object Oriented. OOD is OO Design, OOA is OO Analysis and OOP is Object Oriented Programming. Oracle is an ORDBMS, an Object Relational Database Management System. In this article, I am going to present a sample java class and show how you would implement the same class in Oracle. This is a technical article comparing Oracle objects with Java.

Click to continue reading “Oracle Objects, Types and Collections: Part 1″

Read the rest of this entry »

TOTD, What is a DBA?

Warning: Personal Soapbox Approaching.

I was reading a newsgroup discussion and the topic of DBAs and their usefulness/trivialization came up (yet again). This topic seems to show up at one time or another on every Oracle discussion board.

Whether I agree or not with any of the things said in the discussion doesn’t really matter. It got me thinking about the topic and I have a different perspective to the question. My personal soapbox on this issue is the definition of DBA. Are DBAs being trivialized in the enterprise?

Click to continue reading “TOTD, What is a DBA?”

Read the rest of this entry »

Oracle Security: A Definition in Plain English, Part 2

This is the second entry of a three part series. In part one of this series, I defined what security is and what the different aspects of security in Oracle entailed. In this entry, I am going to show the technical details of implementing security in Oracle. I will create a user, give that user access and then give an example implementation of row and column level security. In part three, I will add auditing to this mix and describe some security best practices, both to protect your data and to meet regulatory requirements.

I’m going into this level of detail because I think some people are not familiar with it and it seems mysterious.

Click to continue reading “Oracle Security: A Definition in Plain English, Part 2″

Read the rest of this entry »

Oracle PowerBrowser

I ran across this link while looking for something else. This is a discussion about Oracle PowerBrowser. Talk about a ride in the way back machine!

Lewis

Technorati : , , , , , ,

Read the rest of this entry »

Advanced Bash-Scripting Guide – Thought of the day, April 1, 2005

I’m going to start a new daily entry in addition to my other entries. I’ll call it the Thought of the Day. It will be an interesting link or thought or joke or just something I read somewhere. It will usually pertain, somehow, to Oracle but like today it might not.

Today’s thought is a link to the best Bash Shell Script guide I’ve ever seen. It’s a reference and a tutorial. I’m no Linux guru and certainly no scritping guru but I really like this guide.

Advanced Bash-Scripting Guide

Thanks,

Lewis

Oracle Designer 9i to 10g Upgrade

I know I said “A day with Ralph Kimball, Part 2″ would be next but I wanted to get this tech note out there while it was fresh in my mind. I’ll post items like this periodically as they occur to me to do so.

I upgraded our Oracle Designer repository from 9i to 10g. It looks like the little things that annoyed me in 9i will continue to do so in 10g, at least in the short term. I don’t see any dramatic changes and my problem child ERD still can’t be transformed to tables.

Click to continue reading “Oracle Designer 9i to 10g Upgrade”

Read the rest of this entry »