Archive for the ‘Solve Problems’ Category

Designing the Data Mart – Part 2

Continuing from Part 1.

So now we have our transactional model and a basic user story:

Our first request from the business for our data mart is that they want to be able to query all of the orders by date, by customer and/or by region (state, city or country). They want to be able to aggregate (sum and average) across those items.

The first thing we need to do is talk to the business and find out exactly what that request means. Do the users want to see information about daily orders in general?

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

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 »

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 »

Calculating Business Days and Business Days Between

From the Database Geek.

I recently had a requirement to populate the day dimension of a data mart (I won’t put all of the code here as it’s pretty large). That’s not that big deal but part of the requirement was to set several columns: BUSINESS_DAY_FLAG, BUSINESS_DAY_NO and BUSINESS_DAYS_REMAINING_NO.

  • The BUSINESS_DAY_FLAG is Y is the date is MON-FRI and N is the date is SAT or SUN.
  • BUSINESS_DAY_NO is the business day of the month. There are 5 business days per week so if the month started on a monday, the second monday would be business day 6.
  • BUSINESS_DAYS_REMAINING_NO is the number of business days remaining in the month.

Click to continue reading “Calculating Business Days and Business Days Between”

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 »

View PDFs on a BlackBerry

I have been in search of a good PDF viewer for my BlackBerry. I tried out several different readers and even use MobiPocket to convert them. I wrote up my experiences in Mobile PDFs – 4 Way to Read PDFs on your BlackBerry.

In that post, I am review 3 native PDF viewers for the BlackBerry: PDF to Go, Repligo Reader and BeamReader. I am also review the MobiPocket mobile ebook reader. While it doesn’t do PDF, it does convert from PDF to its native format. Finally, I review ShortCovers, a new ebook social network/service.

pdf2go-about Repligo-about

beamreader-about Mobi-loading

Summary

For PDF viewing, I found that BeamReader has some shortcomings.

Click to continue reading “View PDFs on a BlackBerry”

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 »

Oracle Advanced Replication: A Definition in Plain English

What is Replication?

According to Webster’s Online, the definition we mean is: 3 a : COPY, REPRODUCTION b : the action or process of reproducing

Replication is simply copying data from one database to another. This could be a subset of the data or a complete copy.

I’m going to use insert for my examples but any DML can be replicated.

If you create an insert trigger on a table and push data across a database link every time a record gets inserted, you’ve performed replication. Call that the poor man’s SYNCHRONOUS replication.

Click to continue reading “Oracle Advanced Replication: A Definition in Plain English”

Read the rest of this entry »

Comment by Bob on Manually creating a Logical Change Record (LCR)

That was excellent!

I was having a little trouble when I was setting p_table_owner to a schema other than my own (I even have DBA and the select on all_tab_columns was successful).

Statement:

v_lcr.set_value(’new’, ‘first_name’…

was throwing that ‘first_name’ did not exist in the LCR.

Once I copied the table to my own schema, works great!

Good for now – exactly what I needed – trying to develop the DML_Handlers before Streams is up and running.

Click to continue reading “Comment by Bob on Manually creating a Logical Change Record (LCR)”

Read the rest of this entry »

Comment by Bob on Manually creating a Logical Change Record (LCR)

That was excellent!

I was having a little trouble when I was setting p_table_owner to a schema other than my own (I even have DBA and the select on all_tab_columns was successful).

Statement:

v_lcr.set_value(’new’, ‘first_name’…

was throwing that ‘first_name’ did not exist in the LCR.

Once I copied the table to my own schema, works great!

Good for now – exactly what I needed – trying to develop the DML_Handlers before Streams is up and running.

Click to continue reading “Comment by Bob on Manually creating a Logical Change Record (LCR)”

Read the rest of this entry »

Comment by Udgith Mankad on Oracle Streams Configuration: Change Data Capture

Hi Lewis,

I have created emp_dml_handler using the procedure here. I have also run the streams_hc_11GR1.sql available on metalink to make sure that there are no errors in my streams configuration.

I am simply trying to insert data into employee table and expect employee_audit and streams_monitor get updated based on the emp_dml_handler procedure.

Please let me know how to enable trace/debugging so that I know whether the DML handler is invoked correctly.

Click to continue reading “Comment by Udgith Mankad on Oracle Streams Configuration: Change Data Capture”

Read the rest of this entry »

Comment by zhaque on Oracle Streams Configuration: Change Data Capture

To stream two or more tables, do I need to add

add_table_rules both in capture and apply processes?

thanks,

!***! Entry Link: Oracle Streams Configuration: Change Data Capture!***!

Click to continue reading “Comment by zhaque on Oracle Streams Configuration: Change Data Capture”

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 3

In Part 1 of this series, we talked about how Oracle objects compare to Java and how to create Oracle Objects. In Part 2, I covered we covered object comparison and type inheritance. Today, we’ll talk about polymorphism and type evolution.

Like parts 1 and 2, this will be a technical discussion.

Polymorphism

First a definition. What is Polymorphism and why is it important? One of the best definitions I have found is this link at OnJava. You can skip the part about object serialization. Not really that important to Oracle’s OO as you’re already in the database.

Let’s go back to our (most basic) calculator example.

CREATE OR REPLACE TYPE Calculator AS OBJECT (
  value NUMBER,
  MEMBER PROCEDURE print,
  MEMBER PROCEDURE add1( p_amt IN NUMBER ),
  MEMBER PROCEDURE subtract( p_amt IN NUMBER )
  )
  NOT FINAL;
/

CREATE OR REPLACE TYPE BODY Calculator AS
  MEMBER PROCEDURE print IS
  BEGIN
    DBMS_OUTPUT.PUT_LINE( TO_CHAR( value ) );
  END;

  MEMBER PROCEDURE add1( p_amt IN NUMBER )  IS
  BEGIN
    value := value + p_amt;
  END;

  MEMBER PROCEDURE subtract( p_amt IN NUMBER )  IS
  BEGIN
    value := value - p_amt;
  END;

END;
/

And our Advanced Calculator:

CREATE OR REPLACE TYPE AdvancedCalculator UNDER Calculator (
  pi FLOAT,
  CONSTRUCTOR FUNCTION AdvancedCalculator
     RETURN SELF AS RESULT ,
  MEMBER PROCEDURE multiply( p_amt IN NUMBER ),
  MEMBER PROCEDURE divide( p_amt IN NUMBER ),
  OVERRIDING MEMBER PROCEDURE print
   )
NOT FINAL;
/

This isn’t exactly the same AdvancedCalculator.

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

Read the rest of this entry »

Oracle Objects, Types and Collections: Part 2

This is a continuation of Object Orientation in Oracle. I guess I should have called it the Sorcerer of OOO. This is a technical entry.

Anyway, in part 1 I covered the basics of creating an Oracle object type and showing how it compared to a Java class. Today I’m going to cover the concepts of comparing objects and Inheritance. In part 3, I will cover type evolution and Polymorphism and in part 4 I will cover Object Views and Object Tables.

Comparing Objects

Many times, you will be working with multiple instances of the same object.

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

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 »

Oracle Security: A Definition in Plain English, Part 3

Regardless of any regulations you are required to meet you can implement a security and audit scheme that will cover you for most, if not all, eventualities. Having good security and auditability should be desirable regardless of regulations. It protects your business.

In parts 1 and 2, I covered the security side of it. So what do I mean by Audit? Well, auditing is knowing what’s going on in your environment. Future research requirements, accountability, error correction, etc are all covered by audit.

So how does Oracle implement audit? There are several ways you can do it: Standard Audit, Fine Grained Audit and Trigger Based Audit.

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

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 »

Eight Steps on the Collaborative Way

Here is an entry from a Project Manager blog called: Eight Steps on the Collaborative Way. I found it to be a very interesting article and very true. I haven’t seen this list before but it’s contain items that I try to include in my development projects, whether I’m working in a project manager role or not. Definately worth a read.

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