SQL Equivalent in Berkeley DB

Hi,
In SQL, we can create a table from the result of a select statement as follows:
CREATE TABLE table3 AS SELECT * FROM table1, table2 WHERE ...
which is called a "materialized view" because the results of the query are not processed on the fly, but are stored in database table for further processing.
I would like to do something equivalent in Berkeley DB, where the I have some databases that already exist, and I want to perform some processing on them (joins, filters, etc), and instead of getting a cursor, I would like to store the result in a new database (table in SQL terminology). Is there a way to do so? I have Key/Data Java class definitions for the base tables only (table1 and table2 in the SQL example).
Thanks,
Walaa.

I understand now, thanks. Now I realize that you're not generating bindings, you have fixed hand-coded bindings for the base table.
The general question you're asking is: How can I store data in BDB without knowing the schema in advance?
Since you are already using Java serialization, this is not too difficult. For the generated database, you could use a TupleSerial binding as you're already doing. This has two parts of course, the key and the data.
I'm not sure what the key should be, perhaps a sequence number? It's up to you.
Because you're using a a TupleSerial binding, the data can be any serialized object. For the serialized data, you could store a List or Map containing the fields that are defined at runtime by the query. A List<Object> may be appropriate if the fields are identified by their order, or a Map<String,Object> if the fields are identified by name. This should work fairly well as long as the List or Map data fields are primitives.
Does this answer your question?
--mark                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

Similar Messages

  • T-SQL Equivalent For Group_Concat() Function

    Hello, I am looking for a way to do the MSSQL T-SQL equivalent of the MySQL aggregate function: group_concat().
    We are running SQL 2005 Express. Is there a pure T-SQL way to do this, or if not, a way to create a new custom aggregate function?
    EX:
    SELECT GROUP_CONCAT(FIRST_NAME) AS STUDENT_LIST FROM STUDENTS GROUP BY TEACHER
    OUTPUT:
    JOSH,JOEY,MARK,LINDA,PAM,BILL,MIKE,JUSTIN

    Can anyone help me with MS SQL equivalent code for below MySQL statement.
    select group_concat
    (Col1
    order
    by field(Col2,8,13,15,53,55,6,73,75,3,42,41,45,44))
    as FinalColumn from TestTable
    Any help is greatly appriciated... thanks in advance...

  • SQL equivalent of if-statement

    What would be really useful would be if I could do an SQL equivalent of an if-statement. I'm just making the following up to show what I mean:
    SELECT CASE
              WHEN(det.user_entity_name = 'PO Header')
                 THEN (SELECT pha.segment1
                         FROM po.po_headers_all pha
                        WHERE pha.po_header_id = ad.pk1_value)
              WHEN(det.user_entity_name = 'PO Line')
                 THEN (SELECT pha.segment1
                         FROM po.po_headers_all pha
                            , po.po_lines_all pla
                        WHERE pha.po_header_id = pla.po_header_id
                          AND pla.po_line_id = ad.pk1_value)
              ELSE 'UNDEFINED'
           END doc_num
         , ad.seq_num
         , fu.description created_by
         , dt.description
         , det.user_entity_name
         , ad.creation_date
         , ad.entity_name
         , ad.pk1_value
         if dat.user_name = 'Short Text' then
         dst.short_text
         elseif dat.user_name = 'Long Text' then
         dlt.long_text
         end if
      FROM applsys.fnd_document_datatypes dat
         , applsys.fnd_document_entities_tl det
         , applsys.fnd_documents_tl dt
         , applsys.fnd_documents d
         , applsys.fnd_document_categories_tl dct
         , applsys.fnd_attached_documents ad
         if dat.user_name = 'Short Text' then
    , applsys.fnd_documents_short_text dst
         elseif dat.user_name = 'Long Text' then
         , applsys.fnd_documents_long_text dlt
         end if            
         , applsys.fnd_user fu
    WHERE d.document_id = ad.document_id
       AND dt.document_id = d.document_id
       AND dct.category_id = d.category_id
       AND d.datatype_id = dat.datatype_id
       AND ad.entity_name = det.data_object_code
         if dat.user_name = 'Short Text' then
    AND dt.media_id = dst.media_id(+)
         elseif dat.user_name = 'Long Text' then
    AND dt.media_id = dlt.media_id(+)
         end if  
       AND ad.created_by = fu.user_id
       AND d.creation_date > '01-OCT-2007'
         if dat.user_name = 'Short Text' then
    AND dat.user_name = 'Short Text'
         elseif dat.user_name = 'Long Text' then
    AND dat.user_name = 'Long Text'
         end if     
       AND dct.user_name = 'To Supplier';Is that possible, or am I just talking a load of nonsense?
    Thanks

    How to do IF in SQL:
    1) CASE
    2) DECODE
    3) UNION, UNION ALL, MINUS, INTERSECT
    4) AND + OR + ()
    5) stored functions
    6) ...
    which is best just depends on the situation. For your example I would use decode in the select clause and some UNION ALL for the from/where clauses.

  • PL/SQL equivalent for networkdays function

    Hi,
    Is anyone aware of a PL/SQL equivalent for the Excel "networkdays" function, that returns the number of whole workdays between 2 dates?
    Thanks!
    Phil

    To calculate the number of days between january 1st and today, use the following.
    1* select trunc(sysdate) - trunc(to_date('01-jan-05')) from dual
    SQL> /
    TRUNC(SYSDATE)-TRUNC(TO_DATE('01-JAN-05'))
    58

  • MS SQL equivalent query

    Hi,
    I need to show the hierarchy of account types. The parent child relationship is stored in account type table. For eg,
    acc1 child is acc2 and acc3, acc2 child is acc4. So the children for acc1 is acc2,acc3,acc4.
    I am able to do so in oracle db using below query:
    select connect_by_root(account_type_id) root_id, account_type_name,account_type_id, parent_type_id
    from account_types
    connect by prior account_type_id = parent_type_id
    I am not able to create the query for MS SQL, can anyone help me to convert above oracle query to MS SQL equivalent?

    1. It is not MS SQL forum. Most of people here does not know MS SQL.
    2. little googling helps: Recursive Queries Using Common Table Expressions http://msdn.microsoft.com/en-us/library/ms186243%28v=sql.105%29.aspx

  • Equivalent Analytical SQL equivalent

    DB version: 10Gr2
    Is there any analytical SQL equivalent of the below ANSI SQL
    select schemaname, count(*)
    from v$session
    group by schemaname
    order by count(*) desc

    Hi,
    Sure.
    It's less efficient than GROUP BY, but here's one way to do it:
    SELECT DISTINCT     schemaname
    ,          COUNT (*) OVER (PARTITION BY schemaname)     AS cnt
    FROM          v$session
    GROUP BY     schemaname
    ORDER BY     cnt          DESC
    ;"GROUP BY scemaname" produces one row per value of schemaname; without GROUP BY, you need SELECT DISTINCT .
    Almost all the aggregate functions (like COUNT) have analytic versions.
    PARTITION BY is the analytic counterpart to the aggregate GROUP BY.

  • PL/SQL Equivalent for TAB in SQL

    What is the equivalent of a TAB in SQL to use with a REPLACE function?
    <CR><LF> = CHR(13)||CHAR(10))
    what is
    <TAB> = ???????
    Miller

    select ascii('tab') tab_val from dual ;I think we get the ascii value of 't'
    Which version you are using??

  • PL/SQL equivalent of T-SQL - "group function is not allowed here"

    Hi all, hope someone can give me a hand as I'm pretty stuck! I have been trying to convert some MS SQL Server T-SQL statements into Oracle PL/SQL and am stuck on the below one:
    SELECT
    CA.AssessmentID,
    (SELECT ProductName + ISNULL(' - ' + PrincipalBenefit,'')
    FROM rptPolicySnapshot WHERE PolicyID = MAX(CA.PolicyID)
    AND SnapshotID = 1),
    MAX(CA.PolicyID)
    FROM rptClaimInvoiceLineSnapshot CIL
    INNER JOIN rptClaimAssessmentSnapshot CA
    ON CIL.AssessmentID = CA.AssessmentID
    AND CIL.SnapshotID = CA.SnapshotID
    WHERE CIL.SnapshotID = 1
    GROUP BY CA.AssessmentID
    This works fine in MSSQL but returns the below error in Oracle:
    'ORA-00934: group function is not allowed here'
    If I take out the subquery the query works fine.
    Any ideas as to the syntax? I am new to Oracle so not sure as to how I should go about writing this.
    Thanks in advance!
    Leo

    WITH x AS (SELECT   ca.assessmentid,
                        MAX (ca.policyid) policy_id
               FROM rptclaiminvoicelinesnapshot cil
                    INNER JOIN rptclaimassessmentsnapshot ca
                        ON cil.assessmentid = ca.assessmentid
                       AND cil.snapshotid = ca.snapshotid
               WHERE cil.snapshotid = 1
               GROUP BY ca.assessmentid
    SELECT x.assessment_id,
           x.policy_id,
           productname + decode(principalbenefit,null,null,' - ' || principalbenefit ) prodname
    FROM   rptpolicysnapshot, x
    WHERE  policyid = x.policy_id
    AND    snapshotid = 1I think that's in the neighbourhood.

  • PL/SQL equivalent of working T-SQL Query

    Hi All,
    I am new to Oracle and trying to port some select statements written in MS SQL Server over to Oracle but I am having a few difficulties with one of them.
    The following query works OK in MS SQL Server:
    UPDATE rptPolicySnapshot
    SET NoOfLivesTotal=
    SELECT (SELECT COUNT(DISTINCT EntityID)
    FROM PolicyBeneficiary
    WHERE InfoId = 55
    AND PolicyId=P.PolicyID
    AND PolEffDate = P.EffectiveDate)
    (SELECT COUNT(DISTINCT EntityID)
    FROM PolicyBeneficiary
    WHERE InfoId = 57
    AND PolicyId=P.PolicyID
    AND PolEffDate = P.EffectiveDate)
    FROM rptPolicySnapshot P WHERE P.PolicyType = 1
    I basically want to update each individual row in the table rptPolicySnapshot with the correct information as calculated for that row (the key being PolicyID and EffectiveDate in all the tables) within the inner query, i.e. matching on PolicyID and EffectiveDate.
    As I said this works fine in SQL Server, but I cannot work out how to do this in Oracle. If I run the above query in Oracle I get the following error:
    'ORA-00923: FROM keyword not found where expected'
    Any help would be much appreciated, thanks!

    Try
    UPDATE rptPolicySnapshot P
      SET NoOfLivesTotal=
         (SELECT COUNT(DISTINCT EntityID)
          FROM PolicyBeneficiary
          WHERE InfoId = 55
          AND PolicyId=P.PolicyID
          AND PolEffDate = P.EffectiveDate)
         (SELECT COUNT(DISTINCT EntityID)
          FROM PolicyBeneficiary
          WHERE InfoId = 57
          AND PolicyId=P.PolicyID
          AND PolEffDate = P.EffectiveDate)
    WHERE P.PolicyType = 1Message was edited by:
    ascheffer

  • SQL Equivalent of Show Tablespace Contents.

    Through Enterprise Manager, pointing to a particular tablespace, there is an action titled: Show Tablespace Content, that gives a KB report for each table/index/LOBSEGMENT, etc on a particular Tablespace.
    I currently have a Database that I am for various reasons, unable to use with Enterprise Manager or GRID, is there a script that can give me the equivalant of the above action? It doesn't have to be pretty, but I need it prior to a performance test tomorrow.
    Thanks!

    Never mind, I found this post:
    command for knowing the size of the table and its index
    And modified it for my purposes as such:
    SELECT sum(bytes)/1048576 Megs, segment_name
    FROM dba_extents
    WHERE owner = 'ORABPEL'
    GROUP BY segment_name
    order by MEGS
    Thanks!

  • PL/SQL Equivalent to the condition "No inline validation errors displayed"

    Hello,
    I've seen this on another thread but can't find it. I need two conditions to be true to show a region: a value is not null and no inline validation errors are showing. Does anyone know the PL/SQL (API call?) to retrieve the number of errors being displayed on screen?

    Malcom,
    You can use the global variable wwv_flow.g_inline_validation_error_cnt for your access.
    So your region displayed condition could be a pl/sql function that would return true or false...like this....
    DECLARE
       l_number_of_errors number := 0;
    BEGIN
       l_number_of_errors := wwv_flow.g_inline_validation_error_cnt;
       If (:P1_test_item is NULL or  l_number_of_errors>0 ) then
             return FALSE;
       else
            return TRUE;
       end if;
    END;So, if the item is null, or there is any inline validation error, the region will not be displayed...

  • Oracle equivalent to SQL Server Table Variables ?

    Does Oracle have anything equivalent to SQL Server table variables, that can be used in the JOIN clause of a select statement ?
    What I want to do is execute a query to retrieve a two-column result, into some form of temporary storage (a collection ?), and then re-use that common data in many other queries inside a PL/SQL block. I could use temporary tables, but I'd like to avoid having to create new tables in the database, if possible. If I was doing this in SQL Server, I could use a table variable to do this, but is there anything similar in Oracle ? SQL Server example:
    use Northwind
    DECLARE @myVar TABLE(CustomerID nchar(5), CompanyName nvarchar(40))
    INSERT INTO @myVar(CustomerID, CompanyName)
    select CustomerID, CompanyName
    from Customers
    --Join the variable onto a table in the database
    SELECT *
    FROM @myVar mv join Customers
    on mv.CompanyName = Customers.CompanyName
    The closest I've found in Oracle is to use CREATE TYPE to create new types in the database, and use TABLE and CAST to convert the collection to a table, as shown below. I can't see anyway without creating new types in the database.
    CREATE TYPE IDMap_obj AS Object(OldID number(15), NewID number(15));
    CREATE TYPE IDMap_TAB IS TABLE OF IDMap_obj;
    DECLARE
    v_Count Number(10) := 0;
    --Initialize empty collection
    SourceIDMap IDMap_TAB := IDMap_TAB();
    BEGIN
    --Populate our SourceIDMap variable (dummy select statement for now).
    FOR cur_row IN (select ID As OldID, ID + 10000000 As NewID From SomeTable) LOOP
    SourceIDMap.extend;
    SourceIDMap(SourceIDMap.Last) := IDMap_obj(cur_row.OldId, cur_row.NewId);
    END LOOP;
    --Print out contents of collection
    FOR cur_row IN 1 .. SourceIDMap.Count LOOP
    DBMS_OUTPUT.put_line(SourceIDMap(cur_row).OldId || ' ' || SourceIDMap(cur_row).NewId);
    END LOOP;
    --OK, can we now use our collection in a JOIN statement ?
    SELECT COUNT(SM.NewID)
    INTO v_Count
    FROM SomeTable ST JOIN
    TABLE(CAST(SourceIDMap As IDMap_TAB)) SM
    ON ST.ID = SM.OldID;
    DBMS_OUTPUT.put_line(' ' );
    DBMS_OUTPUT.put_line('v_Count is ' || v_Count);
    END;

    Hi, got this from our plsql guys:
    The term "table function" is a bit confusing here. In Oracle-speak, it means a function that can be used in the from list of a select statement thus:
    select * from Table(My_Table_Function()),..
    where...
    The function's return type must be a collection that SQL understands. So for the interesting case -- mimicking a function with more than one column -- this would be a nested table of ADTs where both the ADT and the nested table are defined at schema level. PL/SQL -- by virtue of some clever footwork -- allows you to declare the type as a nested table of records where both these types are declared in a package spec. This alternative is generally preferred, especially because the nested table can be of Some_Table%rowtype (or Some_Cursor%rowtype if you prefer).
    As I understand it from our man on the ANSI committee, our use terminology follows the standard.
    The construct below seems to be a bit different (though there are similarities) because it appears from your code sample that it's usable only within procedural code. And the object from which you select is a variable rather than a function.
    So, after that preamble... the answer would be:
    No, we don't have any constructs to let you "declare" something that looks like a regular schema-level table as a PL/SQL variable -- and then use (static) SQL on it just as if it were a schema-level table.
    But yes, you can use PL/SQL's pipelined table function to achieve much of the same effect.
    Look at the attached Table_Function.sql.
    It shows that you can populate a collection of records using ordinary PL/SQL code. You can't use SQL for insert, update, or delete on such a collection. I see that SQL Server lets you do
    insert into Program_Variable_Table select... from Schema_Level_Table
    The PL/SQL equivalent would be
    select...
    bulk collect into Program_Variable_Collection
    from Schema_Level_Table
    The attached shows that once you have populated your collection, then you can then query it with regular SQL -- both from inside PL/SQL code and from naked SQL.
    and the code is here
    CONNECT System/p
    -- Drop and re-create "ordinary" user Usr
    EXECUTE d.u
    CONNECT Usr/p
    create table Schema_Things(ID number, Description Varchar2(80))
    create package Pkg is
    subtype Thing_t is Schema_Things%rowtype;
    type Things_t is table of Thing_t; -- index by pls_integer
    Things Things_t;
    -- PLS-00630: pipelined functions must have
    -- a supported collection return type
    -- for "type Things_t is table of Thing_t index by pls_integer".
    function Computed_Things return Things_t pipelined;
    procedure Insert_Schema_Things(No_Of_Rows in pls_integer);
    end Pkg;
    create package body Pkg is
    function Computed_Things return Things_t pipelined is
    Idx pls_integer;
    Thing Thing_t;
    begin
    Idx := Things.First();
    while Idx is not null loop
    pipe row (Things(Idx));
    Idx := Things.Next(Idx);
    end loop;
    end Computed_Things;
    procedure Insert_Schema_Things(No_Of_Rows in pls_integer) is
    begin
    Things := Things_t();
    Things.Extend(No_Of_Rows);
    for j in 1..No_Of_Rows loop
    Things(j).ID := j;
    Things(j).Description := To_Char(j, '00009');
    end loop;
    insert into Schema_Things
    select * from Table(Pkg.Computed_Things());
    end Insert_Schema_Things;
    end Pkg;
    -- Test 1.
    begin Pkg.Insert_Schema_Things(100); end;
    select * from Schema_Things
    -- Test 2.
    begin
    Pkg.Things := Pkg.Things_t();
    Pkg.Things.Extend(20);
    for j in 1..20 loop
    Pkg.Things(j).ID := j;
    Pkg.Things(j).Description := To_Char(j, '00009');
    end loop;
    for j in 1..5 loop
    Pkg.Things.Delete(5 +2*j);
    end loop;
    end;
    select * from Table(Pkg.Computed_Things())
    /

  • Pl/sql parameter portlet - need some help/advice - how to create

    I want to create a pl/sql portlet that accepts a parameter and on submit passes the parameter to other portlets (sql reports) these are then automatically run to display the new data.
    E.g.
    parameter portlet = deptno
    On submit
    Sql reports then refreshed using the parameter
    I am aware, and have tried the mycompnay demo, which works exactly as I want but the parameter portlet cannot be amended and is written in Java.
    I need a pl/sql equivalent so I can tailor the code.
    Any advice examples or guidance would be really appreciated.
    Thanks in anticipation.
    SD

    Hi,
    You can use a form portlet to accept parameters and then call a report in the success procedure of the form. In this example it calls a report with the value in the flightno field.
    declare
    flightno number;
    blk varchar2(10) := 'DEFAULT';
    begin
    flightno := p_session.get_value_as_varchar2(
    p_block_name => blk,
    p_attribute_name => 'A_FLIGHT_NO');
    call('SJDEMO30.report1.show?p_arg_names=flightno&p_arg_values='||
    flightno);
    end;
    Thanks,
    Sharmila

  • Using MapViewer from PL/SQL vs Java

    Hi group!
    The MapViewer User's Guide has this to say about using MapViewer from PL/SQL:
    "The usage model for the SDO_MVCLIENT package is almost identical to that of
    MapViewer JavaBean-based API" etc etc .. "For usage and reference information about specific functions or procedures, see the description of the associated JavaBean-Based API. methods and interfaces in Chapter 4"
    If I don't misunderstand the basic concept, in a Java Web App (using the MapViewer Bean) you create a MapViewer object for each HTTP-user-session, like so:
    MapViewer mv = new MapViewer("http://my_corp.com:8888/mapviewer/omserver");
    ... which you would then store in the user's session object, so that the MapViewer Bean conveniently holds the map's state on the user's behalf.
    To do the equivalent in PL/SQL, the User's Guide suggests:
    "connect scott/tiger
    call sdo_mvclient.createmapviewerclient(
    'http://www.mycorp.com:8888/mapviewer/omserver') ;
    The preceding example creates, in the current session, a unique MapViewer client
    handle to the MapViewer service URL"
    Does "current session" refer to the HTTP-user-session? While I've used PL/SQL before, I've not used the PL/SQL Web Toolkit. Is the session handling implicit here (and invisible?) or should the sdo_mvclient be subsequently stored in the PL/SQL equivalent of a (J2EE) HttpSession object?
    YT

    Part of the answer will depend on how you plan to deploy the application. If you have a few, local clients you could go with the traditional client/server model. If you have a lot of clients and/or they are spread out over a relatively large area (like a campus setting), a web front-end will save you a lot of hassels down the road when it comes time to upgrade.
    Regardless of the the front end, I can tell you that I have been greatly impressed with the throughput you can get by moving most of the code to PL/SQL packages. A few years ago we reworked a VB/Oracle app by moving a lot of the code out of VB and into packages, leaving the client to essentially call procedures and format the output. We had more than a 3x performance increase on the same hardware and our network utilization decreased noticably.
    I am now in the process of replacing the client code with Java servlets/JSP, primarily because of the maintenance hassles I mentioned earlier. There are some limitations with an HTML page but most of these have been cosmetic so far.
    We are still relying heavily on PL/SQL packages. The servlet code basically gets a request, calls a package to get the data, then hands the results to a JSP page. The JSP then formats the output and sends it to the client. We are little more than halfway through the re-write, but it appears performance will increase again. Not as noticably as before, but I will take what I can get. As you have seen, once something is rolled out it always ends up getting used more than you anticipated. Better to over-engineer now than have to patch it once it is live.
    HTH

  • Converting SQL Server Stored Procedure to Oracle

    Hi there,
    I tried to use SwisSQL to convert my SQL Server stored procedure to Orcale without much success.
    Is there anyone who could help me out with this?
    My SQL Server Stored Procedure is:
    CREATE PROCEDURE [dbo].[SP_BackgroundCheckRequest]
         --MASTER Table
         @MASTER_ID int,
         @PERSONNEL_ID int = NULL,
    @DATE_OF_BIRTH datetime = NULL,
         @GENDER varchar(1) = NULL,
         @COUNTRY_OF_BIRTH varchar(3) = NULL,
    @TOWN_OF_BIRTH varchar(100) = NULL,
         @STATE_OF_BIRTH varchar(50) = NULL,
         @CHECK_CATEGORY varchar(10) = NULL,
         @CHECK_TYPE varchar(10) = NULL,
         @PRIORITY varchar(10) = NULL,
         @PRIORITY_REASON varchar(100) = NULL,
         @SCREENING_LEVEL nchar(1) = NULL,
         @POSITION nchar(50) = NULL,
         @REQUEST_SOURCE varchar(60) = NULL,
         --NAME_TYPE Table
         @NAME_TYPE varchar(5) = NULL,
         @FAMILY_NAME varchar(50) = NULL,
         @FIRST_NAME varchar(50) = NULL,
         @MIDDLE_NAME varchar(50) = NULL,
         @TITLE varchar(10) = NULL,
         @PREFFERED_NAME varchar(40) = NULL,
         @PREVIOUS_NAME varchar(140) = NULL,
         --ADDRESS_TYPE Table
         @ADDRESS_TYPE varchar(10) = NULL,
         @ADDRESS_LINE_1 varchar(30) = NULL,
         @ADDRESS_LINE_2 varchar(30) = NULL,
         @ADDRESS_LINE_3 varchar(30) = NULL,
         @COUNTRY varchar(3) = NULL,
         @SUBURB varchar(50) = NULL,
         @STATE varchar(50) = NULL,
         @POSTCODE varchar(15) = NULL,
         @START_DATE varchar(10) = NULL,
         @END_DATE varchar(10) = NULL,
         --LICENSE_TYPE Table
         @LICENSE_TYPE varchar(5) = NULL,
         @LICENSE_AGENCY varchar(15) = NULL,
         @LICENSE_NUMBER varchar(100) = NULL,
         @LICENSE_SIGHTED varchar(1) = NULL,
         --PHONE_TYPE Table
         @TELEPHONE_TYPE varchar(5) = NULL,
         @TELEPHONE_NUMBER varchar(20) = NULL,
         @MOBILE_TYPE varchar(5) = NULL,
         @MOBILE_NUMBER varchar(20) = NULL,
         @EXTENSION_TYPE varchar(5) = NULL,
         @EXTENSION_NUMBER varchar(20) = NULL,
         --PASSPORT_TYPE Table
         @PASSPORT_TYPE varchar(5) = NULL,
         @PASSPORT_NUMBER varchar(50) = NULL,
         @PASSPORT_COUNTRY varchar(3) = NULL,
         @PASSPORT_SIGHTED varchar(1) = NULL
    AS
    BEGIN TRANSACTION
    INSERT into MASTER (MASTER_ID, PERSONNEL_ID, DATE_OF_BIRTH, GENDER, COUNTRY_OF_BIRTH,
         TOWN_OF_BIRTH, STATE_OF_BIRTH, CHECK_CATEGORY, CHECK_TYPE, PRIORITY, PRIORITY_REASON,
         SCREENING_LEVEL, POSITION, REQUEST_SOURCE)
         VALUES (@MASTER_ID, @PERSONNEL_ID, @DATE_OF_BIRTH, @GENDER, @COUNTRY_OF_BIRTH,
         @TOWN_OF_BIRTH, @STATE_OF_BIRTH, @CHECK_CATEGORY, @CHECK_TYPE, @PRIORITY, @PRIORITY_REASON,
         @SCREENING_LEVEL, @POSITION, @REQUEST_SOURCE)
    IF @@ERROR <> 0
    BEGIN
         ROLLBACK
         RAISERROR ('Error inserting values into MASTER table!', 16, 1)
         RETURN
    END
    INSERT into NAME_TYPE (MASTER_ID,NAME_TYPE,FAMILY_NAME,FIRST_NAME,MIDDLE_NAME,TITLE)
         VALUES (@MASTER_ID,@NAME_TYPE,@FAMILY_NAME,@FIRST_NAME,@MIDDLE_NAME,@TITLE)
    IF @@ERROR <> 0
    BEGIN
         ROLLBACK
         RAISERROR ('Error inserting values into NAME_TYPE table!', 16, 1)
         RETURN
    END
    INSERT into ADDRESS_TYPE (MASTER_ID,TYPE,ADDRESS_LINE_1,ADDRESS_LINE_2,ADDRESS_LINE_3,
              COUNTRY,SUBURB,STATE,POSTCODE,START_DATE,END_DATE)
         VALUES (@MASTER_ID,@ADDRESS_TYPE,@ADDRESS_LINE_1,@ADDRESS_LINE_2,@ADDRESS_LINE_3,
              @COUNTRY,@SUBURB,@STATE,@POSTCODE,@START_DATE,@END_DATE)
    IF @@ERROR <> 0
    BEGIN
         ROLLBACK
         RAISERROR ('Error inserting values into ADDRESS_TYPE table!', 16, 1)
         RETURN
    END
    INSERT into LICENSE_TYPE (MASTER_ID,TYPE,AGENCY,NUMBER,SIGHTED_YN)
         VALUES (@MASTER_ID,@LICENSE_TYPE,@LICENSE_AGENCY,@LICENSE_NUMBER,@LICENSE_SIGHTED)
    IF @@ERROR <> 0
    BEGIN
         ROLLBACK
         RAISERROR ('Error inserting values into LICENSE_TYPE table!', 16, 1)
         RETURN
    END
    INSERT into PHONE_TYPE (MASTER_ID,TYPE,NUMBER)
         VALUES (@MASTER_ID,@TELEPHONE_TYPE,@TELEPHONE_NUMBER)
    IF @@ERROR <> 0
    BEGIN
         ROLLBACK
         RAISERROR ('Error inserting Telephone number into PHONE_TYPE table!', 16, 1)
         RETURN
    END
    IF ((@MOBILE_TYPE <> NULL) AND (@MOBILE_NUMBER <> NULL))
    BEGIN
         INSERT into PHONE_TYPE (MASTER_ID,TYPE,NUMBER)
              VALUES (@MASTER_ID,@MOBILE_TYPE,@MOBILE_NUMBER)
         IF @@ERROR <> 0
         BEGIN
              ROLLBACK
              RAISERROR ('Error inserting Mobile number into PHONE_TYPE table!', 16, 1)
              RETURN
         END
    END
    IF ((@EXTENSION_TYPE <> NULL) AND (@EXTENSION_NUMBER <> NULL))
    BEGIN
         INSERT into PHONE_TYPE (MASTER_ID,TYPE,NUMBER)
              VALUES (@MASTER_ID,@EXTENSION_TYPE,@EXTENSION_NUMBER)
         IF @@ERROR <> 0
         BEGIN
              ROLLBACK
              RAISERROR ('Error inserting Extension number into PHONE_TYPE table!', 16, 1)
              RETURN
         END
    END
    INSERT into PASSPORT_TYPE (MASTER_ID,NUMBER,COUNTRY,SIGHTED_YN)
         VALUES (@MASTER_ID,@PASSPORT_NUMBER,@PASSPORT_COUNTRY,@PASSPORT_SIGHTED)
    IF @@ERROR <> 0
    BEGIN
         ROLLBACK
         RAISERROR ('Error inserting values into PASSPORT_TYPE table!', 16, 1)
         RETURN
    END
    COMMIT

    First, a basic concept. That also illustrates how different Oracle is (and PL/SQL) from SQL-Server (and T-SQL).
    PL/SQL integrates two different languages. The PL language. The SQL language. It allows you to code SQL source code natively inside the PL language. The PL compiler is clever enough to do the rest - make calls to the SQL engine to create SQL cursors, bind PL variable values to bind variables in the SQL code. Etc.
    PL is a "proper" programming language. It is much like Pascal (it is based on Ada, a close family member of Pascal). It is nothing at all like T-SQL.
    Okay, now for the very basic rule for Oracle development.
    Maximize SQL. This means using the SQL language to crunch data. It is the "closest" to the data. It is designed and optimised for dealing with data. Do your data processing using SQL.
    Minimize PL/SQL. This means using the PL language not to crunch data, but to provide the conditional logic. Implement business rules. And then have the SQL language crunch the data as the data processing language.
    Attempting to directly translate T-SQL code into PL/SQL is flawed. It is like trying to make coffee with teabags. Yeah, the tea may have caffeine it, but it is not coffee.
    To do what that T-SQL script does, insert a row into a table, a typical PL/SQL equivalent will look as follows:
    create or replace procedure InsertMaster( masterRow master%rowtype ) authid definer is
    .. types and variables declared here
    begin
      -- masterRow is a record structure that matches the actual MASTER table
      .. apply business rules and validation to the data.. raising user exceptions as needed
      -- e.g. the POSITION column must be upper case
      masterRow.position := upper(masterRow.position);
      -- after the business logic and data validation we can add the row to the table
      -- (PL will make the INSERT call to the SQL engine)
      insert into master values masterRow;
    end;No commit. The caller does the business transaction. It needs to decide when to commit to maintain the integrity of the data in the database. It may need to do several more calls, before committing.
    With this approach, we can give the application schema (the caller) execute privs on this procedure. This procedure is defined with definer rights. This means it runs with the privs of owner of that procedure and MASTER table. It is trusted code. It does all the correct stuff to add a valid and checked row to the MASTER table. So we give the app schema execute privs on the procedure and no insert priv on the MASTER table.
    The only way the caller can add row to the MASTER table is via this trusted procedure of ours.
    And this is a typical approach in Oracle - using the PL/SQL (both PL language and SQL language) code to create an interface to a logical database in Oracle. Abstracting the complexities of SQL from the caller. Moving business and validation into PL. Allowing us the flexibility of modifying business and validation logic, without touching a single byte of caller/client code. Allowing us to manage and tune SQL performance without dealing with (badly designed and coded) SQL from a client - as the SQL resides in PL/SQL packages and procedures and functions.

Maybe you are looking for

  • Problem with values of some components per card in CardLayout

    in card 1 i ask the user to enter the numbers (say the user entered, 55.3,62.5,73.2,86.7) parsed it, count the observations.. now in card 2, i have a JComboBox of sample sizes from the numbers the user entered. (in the example, the JComboBox should s

  • Calculations on new server is taking a very long time

    Hello, We are upgrading from a 9.2 to 9.3 system. The 9.3 system is on completely different servers than the 9.2 system. We have migrated a couple of applications and the calcs on the 9.3 system are taking a very long time. For instance a calc that w

  • ARD admin password

    ARD is is password protected. If I open up ARD it automatically bypasses this password entry window so I never have to enter it. (via Keychain I presume) If I open up my Keychain I can view the password. However if I try to change the password via: P

  • How to greate price agreements with scales

    Hi, at the moment I have problems to create price agreements incl. different scales in CRM 4.0. I don´t know which bapi or function module is the correct one. In the last hours I used following function modules: - CRM_PRICE_AGRMNTS_MAINTAIN_OW - /SAP

  • Issues gnerating MD5 ecnoded password in OWSM

    Hi, I am trying to generate a MD5 encoded password while implementing File based authentication in OWSM. However I am not able to generate the MD50 encoded password using the below command D:\oracle\product\orasoa\owsm\bin>wsmadmin md5encode soauser