PL/SQL help in Package

Hi all,
I have a block of code in a package that runs 3 times to spit out a Total.
I want to capture the 3 Totals and return the highest total..
so whats the best way to store those three values and select the highest Total from the same package....
Edited by: 874167 on Jul 26, 2011 2:35 PM

874167 wrote:
I want to capture the 3 Totals and return the highest total..
so whats the best way to store those three values and select the highest Total from the same package....Packages allow static variables to be created. The values can be stored as either private (defined in the package body/implementation section) or global (defined in package header/interface section) static variables.
The package function that returns the highest number can use the Greatest() function. E.g.
SQL> declare
  2     n       number;
  3  begin
  4     n := Greatest( 100, 123, 92, 81, 156 );
  5     dbms_output.put_line( 'max='||n );
  6* end;
SQL> /
max=156
PL/SQL procedure successfully completed.
SQL>

Similar Messages

  • SQL 2012 SSIS package runs from the command line (dtexec.exe) and completes right away ...

    Hi
    I’m upgrading our SSIS packages from SQL 2005 to SQL 2012 .
    Everything is working fine in Visual Studio, but when I’m submitting dtexec.exe it’s finishing right away in the command line (the actual execution takes long time). 
    It looks to me that as the return code doesn’t pass properly.
    As I have depending tasks how I can make sure all jobs will be executed in the proper order.
    (We never had this issue in SQL 2005)
    C:\Program Files (x86)\Microsoft SQL Server\110\DTS\Binn>dtexec.exe /ISSERVER "\"\SSISDB\Direct_Prod\Direct_SSIS_Package
    \DD_Load_Customer.dtsx\"" /SERVER TORSQLSIS01 /ENVREFERENCE 2
    Microsoft (R) SQL Server Execute Package Utility
    Version 11.0.2100.60 for 32-bit
    Copyright (C) Microsoft Corporation. All rights reserved.
    Started:  10:21:55 AM
    Execution ID: 21138.
    To view the details for the execution, right-click on the Integration Services Catalog, and open the [All Executions] report
    Started:  10:21:55 AM
    Finished: 10:21:56 AM
    Elapsed:  0.766 seconds

    As per MSDN /ENVREFERENCE argument is used only by SQL Server Agent
    see
    https://msdn.microsoft.com/en-us/library/hh231187.aspx
    below part is what it says
    /Env[Reference] environment reference ID
    (Optional). Specifies the environment reference (ID) that is used by the package execution, for a package that is deployed to the Integration Services server. The parameters configured to bind
    to variables will use the values of the variables that are contained in the environment.
    You use /Env[Reference] option together with the /ISServer and the /Server options.
    This parameter is used by SQL Server Agent.
    Please Mark This As Answer if it solved your issue
    Please Vote This As Helpful if it helps to solve your issue
    Visakh
    My Wiki User Page
    My MSDN Page
    My Personal Blog
    My Facebook Page

  • PIVOT sql help

    Hi again
    I need some PIVOT sql help
    In this query:
    SELECT
    SUM([RATES]) as RATES
    ,SUM([CONVERSION])as CONVERSION
    FROM REPORTING
    outputs
    RATES CONVERSION
    23 234
    How would change this query to display a table like:
    Name Amount
    RATES 23
    CONVERSION 234
    Keep up the good work !

    nikos101 wrote:
    > How would change this query to display a table like:
    Do you *HAVE* to change the query... you could just display
    it in the
    desired format if that it the ultimate and only goal.
    <table>
    <tr>
    <td>name</td>
    <td>amount</td>
    </tr>
    <cfoutput query="sumQry">
    <tr><td>Rates</td><td>#rates#</td></tr>
    <tr><td>Conversion</td><td>#conversion#</td></tr>
    </cfoutput>
    </table>

  • Execution of Immediate SQL in compiled package in two versions of SQL*PLUS

    A peculiar problem has risen in our database.
    Execution of Immediate SQL in compiled package in two versions of SQLPLUS gives different results
    We have a compiled package with two procedures that contain immediate SQL statements, and these are:
    +PROC_DELETE_ROWS+
    +     -- This immediate sql deletes unreferenced Document Types from the DOC_REF_TYPE table+
    +     delete from doc_ref_type t where exists (select 1 from PROARC_DOC_REF_TYPE_VW d where d.doc_ref_type = t.doc_ref_type)+
       +     and not exists (select 1 from doc_ref d where d.doc_ref_type = t.doc_ref_type)+
       +     and doc_ref_type not in (select doc_ref_type from eis_doc_ref_type)+
       +     and doc_ref_type not in (select eis_doc_ref_type from eis_doc_ref_type)+
    +PROC_ADD_NEW_ROWS+
    +     -- Drop the temporary table+
    +     drop table TMP_PROARC_DOC_REF_TYPE+
    +     -- Create a temporary table+
    +     create table tmp_PROARC_DOC_REF_TYPE as+
    +     select DOC_REF_TYPE, substr(DOC_REF_TYPE_DESC,1,100) as DOC_REF_TYPE_DESC+
    +     from PROARC_DOC_REF_TYPE_VW+
    +     -- Insert document types that do not exist in the DOC_REF_TYPE table+
    +     insert into doc_ref_type t (DOC_REF_TYPE, DOC_REF_TYPE_DESC)+
            +     select distinct DOC_REF_TYPE, DOC_REF_TYPE_DESC from tmp_PROARC_DOC_REF_TYPE s+
            +     where not exists (select 1 from doc_ref_type t where t.doc_ref_type = s.doc_ref_type)+
    I am using the following test script:
    +Exec mypackage.proc_delete_rows;+
    +Commit;+
    +Select count(*) from DOC_REF_TYPES;+
    +Exec mypackage.proc_add_new_rows;+
    +Commit;+
    +Select count(*) from DOC_REF_TYPES;+We have a Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - 64bit
    I am using SQL*Plus: Release 8.1.7.0.0
    The test script is working as expected.
    Count after delete =155
    Count after insert = 511
    but when I use another computer with SQL*Plus: Release 10.x
    The Test script returns the following
    Count after delete =155
    Count after insert =155
    The same is happening when I am running the scripts as a scheduled job.
    QUESTION:
    I believe I have found a fix for the problem though. By changing tmp_PROARC_DOC_REF_TYPE in the insert statement to all upper case, the script is running in both environments apparently. But how is this possible? I am executing a compiled package in the database. The session shell should have no impact on the behaveour of the procedure I am calling. What causes this?
    Edited by: Reon on Jun 16, 2011 4:44 AM

    1) I am using the same user (PANDORA)
    2) (PANDORA) for both
    3) I am actually not handling any errors. Just skipping any error altogether. I'll check to see what exceptions are raised, and come back.
    I have also noticed that SQL/PLUS is not the culprit here. If I use SQLTools 1.5 to run the script, the same thing happens. So it has to do something with the connection or session environment that is inheritet to both clients.
    The CODEZ:_
      procedure add_doc_types IS
      sqlstr     VARCHAR2(2000);
      begin
      BEGIN
           sqlstr := 'drop table TMP_PROARC_DOC_REF_TYPE';
         EXECUTE IMMEDIATE sqlstr;
        EXCEPTION
          WHEN OTHERS THEN
            null;
        END;
      BEGIN
           sqlstr := 'create table tmp_PROARC_DOC_REF_TYPE as select DOC_REF_TYPE, substr(DOC_REF_TYPE_DESC,1,100) as DOC_REF_TYPE_DESC from PROARC_DOC_REF_TYPE_VW';
         EXECUTE IMMEDIATE sqlstr;
        EXCEPTION
          WHEN OTHERS THEN
            null;
        END;
        BEGIN
            sqlstr := 'insert into doc_ref_type t (DOC_REF_TYPE, DOC_REF_TYPE_DESC)
                    select distinct DOC_REF_TYPE, DOC_REF_TYPE_DESC from TMP_PROARC_DOC_REF_TYPE s
                    where not exists (select 1 from doc_ref_type t where t.doc_ref_type = s.doc_ref_type)';
         EXECUTE IMMEDIATE sqlstr;
            sqlstr := 'update doc_ref_type t set DOC_REF_TYPE_DESC = (
                    select DOC_REF_TYPE_DESC from tmp_PROARC_DOC_REF_TYPE s
                    where t.doc_ref_type = s.doc_ref_type)
                    where exists (select 1 from tmp_PROARC_DOC_REF_TYPE s where t.doc_ref_type = s.doc_ref_type)';
         EXECUTE IMMEDIATE sqlstr;
        EXCEPTION
          WHEN OTHERS THEN
            null;
        END;
      end add_doc_types;
      procedure delete_doc_types IS
      sqlstr     VARCHAR2(2000);
       BEGIN
            sqlstr := 'delete from doc_ref_type t where exists (select 1 from PROARC_DOC_REF_TYPE_VW d where d.doc_ref_type = t.doc_ref_type)
            and not exists (select 1 from doc_ref d where d.doc_ref_type = t.doc_ref_type)
            and doc_ref_type not in (select doc_ref_type from eis_doc_ref_type)
            and doc_ref_type not in (select eis_doc_ref_type from eis_doc_ref_type)';
          EXECUTE IMMEDIATE sqlstr;
         EXCEPTION
           WHEN OTHERS THEN
             null;
      end delete_doc_types;Edited by: Reon on Jun 16, 2011 2:01 AM

  • Execute sql server dts package

    Does anyone have sample code for executing MS sql server dts package in java application?
    The following parameters are required for executing the package:
    DTS package name="tranfer"
    login="uid"
    password="password"
    Thank you very much!

    Does anyone have sample code for executing MS sql
    server dts package in java application?Google might.
    http://www.google.com/search?q=ms+sql+server+dts+package+java+sample+code&sourceid=opera&num=0&ie=utf-8&oe=utf-8

  • HELP ON PACKAGING

    Am new to LABVIEW. I need some vast help on packaging.
    I attached some blocks in my application. In the whole application, in those two areas only picture setup were there.
    The problem is VI file is running perfectly but when i build an exe file and running it the pictures didn't get displayed.
    Please give ur valuable suggestions.
    Earlier reply was much appreciated.
    Regards,
    Mathan
    Attachments:
    Doc14.doc ‏89 KB

    I tend to ask more questions on here than i answer.... but here goes....
    Is there not something about relative paths and having to strip an additional level when the VI is running as an executable?
    Think this thread will help.
    http://forums.ni.com/ni/board/message?board.id=170&message.id=93323&query.id=128427#M93323
    Derek

  • Migrating SQL Server SSIS package to Oracle

    Dear All,
    We are using Microsoft SQL server 2005 in our application, we have two separate Server instances where one instance synchronize data from other server table using SQL Server SSIS package. What can be the counterpart of this functionality in Oracle. I have looked into materialized views but in my case the target table will have more columns than the base table, and the query used to get data from base table will extract some values from one of the BLOB type column of base table and then populate target table multiple columns.
    Kindly suggest me any solution.
    Best Regards
    Irfan

    You can start with Oracle doc,
    Oracle® Database PL/SQL User's Guide and Reference
    http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14261/toc.htm
    I don't think there's side by side comparison reference between them. Some syntax is very different.

  • Help With "Package An Application" Using APEX  3.0.1 with XE

    I'm using apex 3.0.1 and XE Database and I'm trying to create a package application but without succes, I can find the way to do it and I know that it's possible. What I'm trying to do is create a file like the package application that we can download from Oracle page but for an application I create.
    Looking here in the forums I found this link:
    http://www.oracle.com/technology/oramag/oracle/06-jul/o46browser.html
    And I was trying to follow it step by step until I found the Step 4: Package Up the Application, number 7.
    1. In the breadcrumb links in the upper left-hand corner of the screen, click the Application nnn link (where nnn corresponds to the ID of the employee lookup application in your Oracle Application Express instance).
    2. Click the Edit Attributes icon, and then click Supporting Objects.
    3. Click Edit.
    4. In the Welcome section, enter readme text for the application in the Message field, such as "This application lets users browse employee information. Users accessing the application with a USERID stored in the table can upload a photo if one does not already exist."
    5. Click the right arrow to go to the Prerequisites tab.
    6. To ensure that folks who already have a table named OM_EMPLOYEES in their schemas don't run into a conflict with this script, enter OM_EMPLOYEES in the first Object Names field and click Add.
    [b]7. Click the Scripts tab.
    8. Click Create.
    9. Click the Copy from SQL Script Repository icon.
    10. Enter Create Table, Sequence, and Trigger in the Name field, and click Next.
    11. Select om_employees.sql, and click Create Script.
    12. Repeat steps 9 through 11 for the om_download_pict.sql and seed_data .sql scripts. Feel free to name these scripts as you see fit.
    13. Click the Deinstall tab, and click Create.
    14. Click the Create from File icon.
    15. Click Browse, select the drop_om_objects.sql script (included with this column's download file), click Open, and click Create Script.
    16. Click the right arrow.
    17. Select Yes for Include Supporting Object Definitions in Export.
    18. Click Apply Changes.
    I can't find the scrips tab and I completely lost. I start to believe that this steps don't apply for Apex 3.0.1.
    If anyone of you could help me with this, please do it, I really need it.
    Johann.

    Johann,
    That doc was probably written against 2.2 because in 3.0, we reworked the supporting objects page a bit. If you are on Supporting Objects, in the Installation region, click on Installation Scripts. For more information, check the Advanced Tutorials document off our OTN site for a Tutorial called Reviewing a Packaged App (something like that - I can't access the doc at the moment).
    -- Sharon

  • Dynamic SQL using DBMS_SQL Package

    Hi,
    How do i construct a
    "select * from :table_name(input parameter)"
    in a store proc in Oracle8 ?
    I know this is only possible using DBMS_SQL package in Oracle 8.
    I know that this is easily done using native Dyanamic SQL 8i onwards.
    Also I want to return the resultset obtained above through a REF cursor.
    Please Help !!!
    Will be greatly indebted to anyone who can supply the code or direct me to some helpful information on the net.
    Thanks in advance.
    Peeyush

    You are asking for two things here, use the tablename dynamically
    as bind variable to fetch the resultset and send the resultset to
    a stored procedure.
    I thought of doing both of them with REF Cursors, no Dynamic SQL here.
    Consider the following test,SQL> create or replace package ref_types as
      2       type r_cursor(pSal NUMBER) is ref cursor;
      3  end;
      4  /
    Package created.
    -- Please note that I did some quick and dirty coding to switch
    -- between the table names to show the results.
    SQL> create or replace procedure p_dynamic_table
      2  (pRefCur IN ref_types.r_cursor, pTable varchar2) as
      3     emp_rec my_emp%ROWTYPE;
      4     inv_rec test444%ROWTYPE;
      5  begin
      6    loop
      7       IF UPPER(pTable) = 'MY_EMP' Then
      8          fetch pRefcur into emp_rec;
      9       Elsif UPPER(pTable) = 'INV' THEN
    10          fetch pRefCur into inv_rec;
    11       Else
    12          exit;
    13       End if;
    14       exit when pRefcur%NOTFOUND;
    15       If UPPER(pTable) = 'MY_EMP' Then
    16          dbms_output.put_line(emp_rec.empno);
    17       Elsif UPPER(pTable) = 'INV' Then
    18          dbms_output.put_line(inv_rec.seq);
    19       Else
    20         Null;
    21       End if;
    22    end loop;
    23  end;
    24  /
    Procedure created.
    SQL> declare
      2     vRefCur         ref_types.r_cursor;
      3     vTableName      Varchar2(30);
      4  begin
      5    vTableName := 'my_emp';
      6    open vRefCur for 'select * from ' || vTableName;
      7    p_dynamic_table(vRefCur, vTableName);
      8    close vRefCur;
      9    vTableName := 'inv';
    10    open vRefCur for 'select * from ' || vTableName;
    11    p_dynamic_table(vRefCur, vTableName);
    12    close vRefCur;
    13  end;
    14  /
    7369
    7499
    7521
    7566
    7654
    7698
    7782
    7788
    7839
    7844
    7876
    7900
    7902
    7934
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    PL/SQL procedure successfully completed.Thx,
    Sri

  • Database Generator: PL/SQL Functions in packages

    I've created a package, P. I've created a function, F. I've specified that F is a sub-program of P.
    I run the designer generator, and tell it I want to generate everything. I get both the package with its function. So, P.F all fine :)
    But, since I selected everything to generate, it also generates F as a stand-alone function. How do I stop this happening?
    Obviously, in this case I could not select the function F to be generated. But we've actually got a mixture of stand-alone functions and procedures, as well as packages. And I don't want to have to manually ensure that I'm selecting and de-selecting the right names.

    What you want to do is use a filter - in other words filter Function Definitions so that only stand-alone functions are listed in the Navigator tree. But what property to filter? Function definitions don't have a property that shows the parent package. Well, they do have a property under Invocation called "Top Level?", but if you display the help on this property, you'll see that is documentation only, not used in generation, and has to be set manually. The default is "No". Still, you work with what you've got.
    So as a one-time deal, turn on the Property Palette (F4), highlight each stand-alone function in the Navigator, and change this property for all of your stand-alone functions to "Yes". Make sure that you do the same with stand alone Procedure Definitions and ALL Package Definitions. Save your changes. Whenever you create a new stand-alone function, or ANY package you'll have to remember to set this property to "Yes". Then right click PL/SQL Definitions, select Filter, then in the "Filter in Navigator set Top Level to Yes. You can make this your permanent default filter, or only use this filter when you are generating.

  • SQL Server DTS packages migration

    How to move DTS packages from SQL Server 2000 to SQL server 2008 version 
    can you plz provide me step by step procedure
    if i migrated DTS packages by using of save as option what will happen, is it working properly 
    and i had migrated DTS packages from sql 2000 to sql 2008 version but while i'm click to open the DTS i got below error
    ERROR:Managing DTS packages in SQL Server Management Studio requires the SQL Server 2000
    Data Transformation Services (DTS) runtime. To install the DTS runtime, on your SQL Server 2008 R2 installation media, locate and run the Windows Installer package for SQL Server 2005 Backward Compatibility (SQLServer2005_BC*.msi). You can also download the
    DTS runtime from the SQL Server Feature Pack page on the Microsoft Download Center. (Microsoft.SqlServer.DtsObjectExplorerUI)
    Kamal

    Hello,
    Please read below article completely
    Migrate DTS packages to SSIS
    For the error you got because you need to install DTS runtime , which is not present
    Support of DTS packages in 2008 R2
    Please mark this reply as the answer or vote as helpful, as appropriate, to make it useful for other readers
    My TechNet Wiki Articles

  • PL/SQL Help...Long Raw to BLOB

    Hello All,
    I have a PL/SQL Package and Function that does a search for text in a blob field. Below is the Package and the Function.
    Here the statement that executes the function
    Select *
               FROM PROGTXT
              WHERE pcode.str_loc_in_blob
                                        (pcode.blob_to_new_blob (progtxt),
                                         '<search string>'
                                        ) <> 0
           ORDER BY objectvalue1, objectvaluesCurrently the above mentioned sql works where the progtxt is a blob datatype.
    We have a database where the progtxt is of Long Raw datatype. I want to utilize the same sql exactly but change the function where i can copy the table structure to a global temporary table each time the function is executed using the dbms_lob funtion and delete the temp table once the function is executed after the results are posted/retrieved. The reason why i want to use the same application is because it is part of a .net program and the only thing i change is the function. I am not great with PL/SQL. If anyone can help that will be a great help!!!!!
    Below is the code for the package and the function
    CREATE OR REPLACE PACKAGE PCODE AS
    FUNCTION to_base (p_dec IN NUMBER, p_base IN NUMBER)
       RETURN VARCHAR2
    FUNCTION to_dec (
       p_str         IN   VARCHAR2,
       p_from_base   IN   NUMBER DEFAULT 16
       RETURN NUMBER
    FUNCTION to_hex (p_dec IN NUMBER)
       RETURN VARCHAR2
    FUNCTION to_bin (p_dec IN NUMBER)
       RETURN VARCHAR2
    FUNCTION to_oct (p_dec IN NUMBER)
       RETURN VARCHAR2
    FUNCTION str_to_hex(p_str IN VARCHAR2)
    RETURN VARCHAR2
    FUNCTION str_loc_in_blob(
      l_blob IN BLOB
    , l_str  IN VARCHAR2)
    RETURN NUMBER
    FUNCTION blob_to_new_blob(
      p_blob IN BLOB)
    RETURN BLOB
    END PCODE;
    CREATE OR REPLACE PACKAGE BODY PCODE AS
    FUNCTION to_base (p_dec IN NUMBER, p_base IN NUMBER)
       RETURN VARCHAR2
    IS
       l_str   VARCHAR2 (255) DEFAULT NULL;
       l_num   NUMBER         DEFAULT p_dec;
       l_hex   VARCHAR2 (16)  DEFAULT '0123456789abcdef';
    BEGIN
       IF (p_dec IS NULL OR p_base IS NULL)
       THEN
          RETURN NULL;
       END IF;
       IF (TRUNC (p_dec) <> p_dec OR p_dec < 0)
       THEN
          RAISE PROGRAM_ERROR;
       END IF;
       LOOP
          l_str := SUBSTR (l_hex, MOD (l_num, p_base) + 1, 1) || l_str;
          l_num := TRUNC (l_num / p_base);
          EXIT WHEN (l_num = 0);
       END LOOP;
       RETURN l_str;
    END to_base;
    FUNCTION to_dec (
       p_str         IN   VARCHAR2,
       p_from_base   IN   NUMBER DEFAULT 16
       RETURN NUMBER
    IS
       l_num   NUMBER        DEFAULT 0;
       l_hex   VARCHAR2 (16) DEFAULT '0123456789abcdef';
    BEGIN
       IF (p_str IS NULL OR p_from_base IS NULL)
       THEN
          RETURN NULL;
       END IF;
       FOR i IN 1 .. LENGTH (p_str)
       LOOP
          l_num :=
             l_num * p_from_base + INSTR (l_hex, UPPER (SUBSTR (p_str, i, 1)))
             - 1;
       END LOOP;
       RETURN l_num;
    END to_dec;
    FUNCTION to_hex (p_dec IN NUMBER)
       RETURN VARCHAR2
    IS
    BEGIN
       RETURN to_base (p_dec, 16);
    END to_hex;
    FUNCTION to_bin (p_dec IN NUMBER)
       RETURN VARCHAR2
    IS
    BEGIN
       RETURN to_base (p_dec, 2);
    END to_bin;
    FUNCTION to_oct (p_dec IN NUMBER)
       RETURN VARCHAR2
    IS
    BEGIN
       RETURN to_base (p_dec, 8);
    END to_oct;
    FUNCTION str_to_hex(p_str IN VARCHAR2)
    RETURN VARCHAR2 IS
    l_val VARCHAR2(2000) := NULL;
    BEGIN
       FOR i IN 1 .. LENGTH (p_str)
       LOOP
          l_val := l_val || to_hex(ASCII(SUBSTR (p_str, i, 1))) || case when i = LENGTH (p_str) then null else '00' end;
       END LOOP;
       RETURN UPPER(l_val);
    END str_to_hex;
    FUNCTION str_loc_in_blob(
      l_blob IN BLOB
    , l_str  IN VARCHAR2)
    RETURN NUMBER IS
    blob_len NUMBER;
    l_pos number := 0;
    BEGIN
    blob_len := dbms_lob.getlength(l_blob);
    l_pos := 0;
    FOR i in 0..15 LOOP
        l_pos := dbms_lob.instr(DBMS_LOB.SUBSTR (l_blob, 2000, i*2000+1), IMPACTUS_PCODE.str_to_hex((l_str)));
        IF l_pos <> 0 THEN
           RETURN i*2000+1 + l_pos - 1;
        END IF;
    END LOOP;
    FOR i in 0..15 LOOP
        l_pos := dbms_lob.instr(DBMS_LOB.SUBSTR (l_blob, 2000, i*2000+1), IMPACTUS_PCODE.str_to_hex(upper(l_str)));
        IF l_pos <> 0 THEN
           RETURN i*2000+1 + l_pos - 1;
        END IF;
    END LOOP;
    l_pos := 0;
    FOR i in 0..15 LOOP
        l_pos := dbms_lob.instr(DBMS_LOB.SUBSTR (l_blob, 2000, i*2000+1), IMPACTUS_PCODE.str_to_hex(lower(l_str)));
        IF l_pos <> 0 THEN
           RETURN i*2000+1 + l_pos - 1;
        END IF;
    END LOOP;
    l_pos := 0;
    FOR i in 0..15 LOOP
        l_pos := dbms_lob.instr(DBMS_LOB.SUBSTR (l_blob, 2000, i*2000+1), IMPACTUS_PCODE.str_to_hex(initcap(l_str)));
        IF l_pos <> 0 THEN
           RETURN i*2000+1 + l_pos - 1;
        END IF;
    END LOOP;
    RETURN 0;
    END str_loc_in_blob;
    FUNCTION blob_to_new_blob(p_blob BLOB)
       RETURN BLOB IS
    v_file_blob     BLOB;  
    v_file_blob_new BLOB := NULL;
    v_file_clob     CLOB;  
    v_file_size     INTEGER := dbms_lob.lobmaxsize;
    v_dest_offset   INTEGER := 1;
    v_src_offset    INTEGER := 1;
    v_blob_csid     NUMBER := dbms_lob.default_csid;
    v_lang_context  NUMBER := dbms_lob.default_lang_ctx;
    v_warning       INTEGER;
    BEGIN
    DBMS_LOB.CREATETEMPORARY(v_file_clob, TRUE);
            dbms_lob.convertToClob(
                            v_file_clob,
                            p_blob,
                            v_file_size,
                            v_dest_offset,
                            v_src_offset,
                            v_blob_csid,
                            v_lang_context,
                            v_warning);
            v_file_clob:=upper(v_file_clob);
            IF v_warning = 0 THEN
                    v_file_size     := dbms_lob.lobmaxsize;
                    v_dest_offset   := 1;
                    v_src_offset    := 1;
                    v_blob_csid     := dbms_lob.default_csid;
                    v_lang_context  := dbms_lob.default_lang_ctx;
                    v_warning       := null;
                    DBMS_LOB.CREATETEMPORARY(v_file_blob_new,true);
                    dbms_lob.convertToBlob(
                            v_file_blob_new,
                            v_file_clob,
                            v_file_size,
                            v_dest_offset,
                            v_src_offset,
                            v_blob_csid,
                            v_lang_context,
                            v_warning);
                    IF v_warning = 0 THEN
                       RETURN v_file_blob_new;
                    END IF;  
            END IF;
    END;
    END PCODE;
    /Thanks
    Nitin
    Edited by: user13048604 on Jan 12, 2011 10:18 PM

    First you may need to convert 'BLOB' which is of 'RAW' type to 'VARCHAR2'
    using
    utl_raw.cast_to_varchar2(urblob)Then you can make use of dbms_lob.instr,dbms_lob.substr etc...

  • Is it possible to return a data grid in sql developer from package?

    Hi, I am in need of some help in returning a datagrid rather than just a list from a package. This is my package:
    CREATE OR REPLACE PACKAGE BODY C_1
    as
    PROCEDURE COUNTING1 (C_YEARFROM IN NUMBER, C_TABLE_NAME IN VARCHAR2) is
    yearCount NUMBER;
    c_sql long;
    BEGIN
    execute immediate 'SELECT COUNT(DISTINCT SPECIES) FROM '||C_TABLE_NAME ||' WHERE year >2007' into yearCount;
    dbms_output.put_line('Distinct species count: ' ||yearCount);
    end counting1;
    end c_1;
    Is it possible to get the results of these in a table or data grid in sql developer, e.g. I would like to sort results etc rather than just a flat list? Something a bit more elegant then dbms_output.put_line?
    Thanks

    yes, I copied the wrong code into the example - what I actually want to display in a grid is the following:
    CREATE OR REPLACE PACKAGE RSET_CURSOR IS
    cursor rs_cursor is select species, location from ot;
    r_c rs_cursor%rowtype;
    end;
    create or replace package rset_cursor2
    is
    procedure printSpecies;
    end rset_cursor2;
    create or replace package body rset_cursor2
    is
    procedure printSpecies is
    begin
    open rset_cursor.rs_cursor;
    loop
    fetch rset_cursor.rs_cursor into rset_cursor.r_c;
    exit when rset_cursor.rs_cursor%notfound;
    dbms_output.put_line(rset_cursor.r_c.species);
    end loop;
    close rset_cursor.rs_cursor;
    end;
    end;
    I have also just noticed the list I am getting is only including one column of data where it should include 2, have I omitted something?
    Thanks

  • Regular Expression and PL/SQL help

    I am using Oracle 9i, does 9i support regular expression? What functions are there?
    My problem is the birth_date column in my database comes from teleform ( a scan program that reads what people wrote on paper), so the format is all jacked up.... 50% of them are 01/01/1981, 10% are 5/14/1995, 10% are 12/5/1993, 10% are 1/1/1983, 10% are 24-JUL-98. I have never really used regular expression and pl/sql, can anybody help me convert all of them to 01/01/1998?
    Does Oralce 9i support regular expression? What can I do if oralce 9i does not support regular expression? Thank you very much in advance.

    9i doesn't support regular expressions (at least not in the 10g regular expressions sense. There is an OWA_PATTERN_MATCH package that has some facilities for regular expressions). But it doesn't look like this is a regular expressions problem.
    Instead, this is probably a case where you need to
    - enumerate the format masks you want to try
    - determine the order you want to try them
    - write a small function that tries each format mask in succession until one matches.
    Of course, there is no guarantee that you'll ever be able to convert the data to the date that the user intended because some values will be ambiguous. For example, 01/02/03 could mean Feb 1, 2003 or Jan 2, 2003 or Feb 3, 2001 depending on the person who entered the data.
    Assuming you can define the order, your function would just try each format mask in turn until one generated a valid date, i.e.
    BEGIN
      BEGIN
        l_date := TO_DATE( p_string_value, format_mask_1 );
        RETURN l_date;
      EXCEPTION
        WHEN OTHERS THEN
          NULL;
      END;
      BEGIN
        l_date := TO_DATE( p_string_value, format_mask_2 );
        RETURN l_date;
      EXCEPTION
        WHEN OTHERS THEN
          NULL;
      END;
      BEGIN
        l_date := TO_DATE( p_string_value, format_mask_3 );
        RETURN l_date;
      EXCEPTION
        WHEN OTHERS THEN
          NULL;
      END;
      BEGIN
        l_date := TO_DATE( p_string_value, format_mask_N );
        RETURN l_date;
      EXCEPTION
        WHEN OTHERS THEN
          NULL;
      END;
      RETURN NULL;
    END;Justin

  • Proper installation on Windows 2003 - SQL Server - SSIS Package

    We are attempting to access an Oracle 10g database from a SQL Server 2005 installation through SSIS (Windows 2003 x64). Our admin has installed the Oracle 11g client tools, we are developing in VS2008 (on XP x86). We seem to be connecting to the server through VS, but when running the package on the server we get errors as follows:
    Executed as user: <domain\sqlagentid>. ....00.3042.00 for 64-bit Copyright (C) Microsoft Corp 1984-2005. All rights reserved. Started: 4:06:01 PM Error: 2008-09-29 16:06:05.97 Code: 0xC001000E Source: Description: The connection "{03AFE9D8-A2E4-4C3C-9EDF-77603B9A7C1C}" is not found. This error is thrown by Connections collection when the specific connection element is not found. End Error Error: 2008-09-29 16:06:06.69 Code: 0xC001000E Source: <package_name> Description: The connection "{03AFE9D8-A2E4-4C3C-9EDF-77603B9A7C1C}" is not found. This error is thrown by Connections collection when the specific connection element is not found. End Error Error: 2008-09-29 16:06:06.69 Code: 0xC001000E Source: <package_name> Description: The connection "{03AFE9D8-A2E4-4C3C-9EDF-77603B9A7C1C}" is not found. This error is thrown by Connections collection when the specific connection element is not found. End Er... Process Exit Code 1. The step failed.
    We suspect the issue is in the initial installation steps. (BTW - we used a TNSNAMES.ORA that worked on our local machines.)
    Can anyone help?

    The errors you are showing are Microsoft errors not Oracle errors. You should take this up with Microsoft support.

Maybe you are looking for