So with a little help from Tim Hall [ blog | twitter ], I shall do a quick example.
I'm trying to integrate these 2 posts, PL/SQL: Split URL Parameters and PL/SQL: Split Key-Value Pairs. I don't want to store the parsed response or request string just yet, just the string. But in the off chance I want it parsed, I don't want to load it up into excel or something and begin the arduous task of breaking it down. I will (just remembered) have to parse the response string when I receive it though to figure out whether or not the transactions was Approved or Declined.
Let's start with the types:
CREATE OR REPLACE TYPE r_key_value_record IS OBJECTThe simple function, just for demonstration purposes:
(
orderof NUMBER(5),
key_string VARCHAR2(1000),
value_string VARCHAR2(1000)
)
/
CREATE OR REPLACE TYPE t_key_value_table AS TABLE OF R_KEY_VALUE_RECORD
/
CREATE OR REPLACEThis will definitely be expanded in the days to come to include those previous posts mentioned above. I will post the final result and link it up here as well.
FUNCTION get_key_value_pairs RETURN T_KEY_VALUE_TABLE PIPELINED
IS
BEGIN
FOR i IN 1..10 LOOP
PIPE ROW ( R_KEY_VALUE_RECORD( i, i, i ) );
END LOOP;
RETURN;
END get_key_value_pairs;
/
show errors
I had some fun writing Pipelined Functions at my last job. These were used to implement Dynamic Search capability for a large OLTP application hitting a bunch of legacy oracle systems. They worked out very slick and were easy for the Java developers to call as they were just SELECT statements. As I recall, they performed quite well, also.
ReplyDeleteWhat are you doing writing PL/SQL? ;)
ReplyDeleteI like them, but I haven't used them enough to know if they are just a "shiny new object" or something. Just seems like a cool thing to do.
OK, not just the cool thing, there is a practical purpose.
New to pipelined functions?
ReplyDeleteYou need to read these articles by Adrian Billington:
http://www.oracle-developer.net/display.php?id=207
http://www.oracle-developer.net/display.php?id=427
This is cool dude.. This is what i need.. ^^ This is clear version of using pipeline..
ReplyDeleteHow about some try to explain how/why/where a pipelined function is needed over a regular function.. And (this is always left out of explanations), how to call the pipelined function and handle it's multiple fields...
ReplyDeleteYou can handle pipelined functions using TABLE.
ReplyDeleteFrom this example:
SELECT *
FROM TABLE( get_key_value_pairs )
I'm looking for another example I think I did somewhere, will post it when I find it.