[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

3.8

Stored procedure and temporary tables.

Asked by Enid_JP in Oracle 9.x, PL / SQL, Oracle Database

Tags: table, procedure, stored, temporary

Hi,
I have a stored procedure that works fine with SQL server 2005.
I am having trouble making the same thing work with Oracle 9i.
The SP was modified to some extent; but I still get errors.
Here's what I am trying to do.
I execute a query and dump the resultset to a temporary table(#comp1).
Then I read the table and execute another query , the results of which are written to another temporary table.(#Details)
Finally, I need to write out the contents of the second temporary table to a report.(Crystal Report).

Can somebody please let me know how to go about this? I have listed the Procedure below.
Thank you.

CREATE OR REPLACE PROCEDURE TEST_PROC
(
            p_p_OWNER IN VARCHAR2,
            p_COMPANY_SEL_METHOD IN NUMBER,
            p_COMPANY_CODE_OP1 IN VARCHAR2,
            p_FIN_YEAR_METHOD IN NUMBER,
            p_FIN_YEAR_BEGIN IN VARCHAR2,
            p_FIN_YEAR_END IN VARCHAR2,
            CUR_USER IN VARCHAR2
)
IS    
             CompanyCode VARCHAR2(3);
             FinYear VARCHAR2(4);
             FinName VARCHAR2(60);
             SQLQuery VARCHAR(255);                      
             SQLWhereClause VARCHAR(255);  
             SQLWhereClause1 VARCHAR(255);
             SQLWhereClause2 VARCHAR(255);
             SQLWhereClause3 VARCHAR(255);
             SQLWhereClause4 VARCHAR(255);
             SQLFinalQuery VARCHAR(255);
                 
BEGIN
                 ETABLE := '#comp';      

               EXECUTE IMMEDIATE 'CREATE GLOBAL TEMPORARY TABLE #comp1
                                ( COMP_CODE VARCHAR2(60)         NULL
                                , FIN_YEAR VARCHAR2(4)                NULL
                                , FIN_NAME VARCHAR2(60)            NULL
                                ) ON COMMIT PRESERVE ROWS' ;  

               EXCEPTION

                   WHEN TAB_ALREADY_EXISTS THEN NULL;
                        EXECUTE IMMEDIATE 'TRUNCATE TABLE #comp1' ;
                   WHEN OTHERS THEN
                        m_ERROR_NO   :=  -20010;
                        m_ERROR_TEXT := 'Error while creating temp table #comp1. Error is : ';
                        RAISE;
       --END;
--BEGIN
                -- ETABLE := '#Details';                
               --EXECUTE IMMEDIATE 'CREATE GLOBAL TEMPORARY TABLE #Details
                             --   (
                                                --p_OWNER VARCHAR2(8) NULL,
                                                --PROCESSED_DATE DATE NULL,
                                                --FIN_NAME VARCHAR2(60) NULL,
                                                --COMP_CODE VARCHAR2(60) NULL,
                                                --FIN_YEAR VARCHAR2(4) NULL

                               -- ) ON COMMIT PRESERVE ROWS' ;
               --EXCEPTION
                   --WHEN TAB_ALREADY_EXISTS THEN NULL;
                        --EXECUTE IMMEDIATE 'TRUNCATE TABLE #Details' ;
                   --WHEN OTHERS THEN    
                        --m_ERROR_NO   :=  -20010;
                        --m_ERROR_TEXT := 'Error occured while creating temp table #Details . Error is : ';
                        --RAISE;
       --END;
/* To test        
exec TEST_PROC 'xyz',0,'001',0,'2005','2007','user1'
*/

BEGIN
  SQLQuery := 'SELECT FIN.COMP_CODE,
            DFIN.FIN_YEAR,
            FIN.FIN_NAME                  
            FROM
                        FIN
            INNER JOIN
                        DFIN
            ON
                        FIN.YR_CODE=DFIN.YR_CODE
            AND
                        FIN.p_OWNER=DFIN.p_OWNER ';
  SQLWhereClause1 := '           WHERE           FIN.p_OWNER='''+ p_p_OWNER+'''';                        

 

IF p_COMPANY_SEL_METHOD = 1 THEN
              SQLWhereClause2 := ' AND FIN.COMP_CODE = '''+p_COMPANY_CODE_OP1 +'''';

ELSE
             SQLWhereClause2 := '';

END IF;

IF p_FIN_YEAR_METHOD = 1 THEN
             SQLWhereClause3 := ' AND FIN_YEAR between '''+p_FIN_YEAR_BEGIN +''' and '''+p_FIN_YEAR_END +'''';  

ELSEIF p_FIN_YEAR_METHOD = 2 THEN
            SQLWhereClause3 := ' AND FIN_YEAR = '''+p_FIN_YEAR_BEGIN +'''' ;

ELSE
             SQLWhereClause3 := '';

END IF;            

 SQLWhereClause4 :='            ORDER BY  
                        FIN_YEAR,COMP_CODE';
 SQLWhereClause := SQLWhereClause1 + SQLWhereClause2 + SQLWhereClause3 + SQLWhereClause4;
 SQLFinalQuery := SQLQuery + SQLWhereClause;
--exec (SQLFinalQuery)
--END
INSERT INTO #comp1 (                COMP_CODE ,
                              FIN_YEAR,
                        FIN_NAME
             
            )
EXEC (SQLFinalQuery);
--END
DECLARE RPT_CUR CURSOR local fast_forward FOR
SELECT COMP_CODE ,       FIN_YEAR ,  FIN_NAME FROM #comp1
OPEN RPT_CUR
FETCH NEXT FROM RPT_CUR INTO CompanyCode,FinYear ,FinName
    WHILE @@FETCH_STATUS = 0
BEGIN
INSERT #Details                             -- insert records into temporary Details table
SELECT
                          PALC.p_OWNER
                        , REP.PROCESSED_DATE
                        , FIN.DEFN_DESC
                        , FIN.CLOSE_PROC
                        , FIN.COMP_CODE
                        , DFIN.FIN_YEAR

            FROM
                        PALC
            INNER JOIN
                        FIN
            ON
                        PALC.p_OWNER = FIN.p_OWNER
            AND
                        PALC.YR_CODE = FIN.YR_CODE
            INNER JOIN
                        REP
            ON
                        REP.p_OWNER=RLP.p_OWNER
            AND
                  REP.REQUEST_ID=RLP.REQUEST_ID
            AND
                        REP.REQUEST_TYPE=RLP.REQUEST_TYPE
            INNER JOIN  
                        DALC
            ON
                        FIN.YR_CODE=DFIN.YR_CODE
            AND
                        FIN.p_OWNER=DFIN.p_OWNER
            AND
                        DFIN.FIN_YEAR = @FinYear
            WHERE
                        PALC.p_OWNER = p_p_OWNER  
            AND PALC.FIN_YEAR = FinYear        
            AND FIN.COMP_CODE = CompanyCode                      
            AND FIN.FLX_UPDATE_USER =CUR_USER
            and PALC.PER_TYPE = 0
            ORDER BY
                        PALC.QTR_NO,PALC.PER_NO,REP.PROCESSED_DATE
            FETCH NEXT FROM RPT_CUR INTO CompanyCode,FinYear,FinName
END

---fetching from cursor
CLOSE RPT_CUR
DEALLOCATE RPT_CUR
DROP TABLE #comp1
SELECT * FROM #Details
DROP TABLE #Details
--GRANT EXECUTE ON TEST_PROC TO PUBLIC
END
--go

I get the following errors :

LINE/COL ERROR

-------- -----------------------------------------------------------------

95/8     PLS-00103: Encountered the symbol " p_FIN_YEAR_METHOD " when
         expecting one of the following:
         := . ( @ % ;


106/13   PLS-00103: Encountered the symbol "#" when expecting one of the   following:
         ( <an identifier> <a double-quoted delimited-identifier>         table the
         The symbol "#" was ignored.
111/1    PLS-00103: Encountered the symbol "EXEC" when expecting one of
LINE/COL ERROR
-------- -----------------------------------------------------------------

         the following:

         ( select values

         The symbol "select" was substituted for "EXEC" to continue.
114/1    PLS-00103: Encountered the symbol "DECLARE" when expecting one of     the following:
         . ( , * % & - + / at mod rem <an identifier>
         <a double-quoted delimited-identifier> <an exponent (**)> as
         from ||



[+][-]07/31/07 10:50 AM, ID: 19602583Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07/31/07 11:21 AM, ID: 19602849Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07/31/07 07:56 PM, ID: 19605978Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08/01/07 04:19 AM, ID: 19607708Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08/01/07 05:27 AM, ID: 19608065Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08/02/07 12:53 AM, ID: 19615138Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08/02/07 05:53 AM, ID: 19616374Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08/02/07 06:20 AM, ID: 19616576Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zones: Oracle 9.x, PL / SQL, Oracle Database
Tags: table, procedure, stored, temporary
Sign Up Now!
Solution Provided By: slightwv
Participating Experts: 4
Solution Grade: A
 
[+][-]08/02/07 09:48 AM, ID: 19618650Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08/02/07 10:29 AM, ID: 19619004Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08/03/07 03:01 AM, ID: 19623608Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08/03/07 03:07 AM, ID: 19623629Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08/03/07 05:02 AM, ID: 19624082Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08/04/07 07:18 AM, ID: 19630996Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08/06/07 05:48 AM, ID: 19637841Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08/06/07 07:51 PM, ID: 19643096Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08/09/07 07:32 PM, ID: 19667368Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08/10/07 05:32 AM, ID: 19669148Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08/13/07 10:51 PM, ID: 19689679Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08/14/07 05:23 AM, ID: 19691152Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08/20/07 06:39 AM, ID: 19730238Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08/20/07 07:10 AM, ID: 19730471Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08/20/07 07:11 AM, ID: 19730483Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08/29/07 04:58 AM, ID: 19790323Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09/04/07 05:50 AM, ID: 19824741Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09/24/07 08:24 AM, ID: 19949070Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09/24/07 08:34 AM, ID: 19949131Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08/09/08 05:50 PM, ID: 22198258Administrative Comment

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 30-day free trial to view this Administrative Comment or ask the Experts your question.

 
[+][-]08/11/08 05:22 AM, ID: 22203706Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08/20/08 07:58 PM, ID: 22275827Administrative Comment

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 30-day free trial to view this Administrative Comment or ask the Experts your question.

 
[+][-]08/27/08 02:41 PM, ID: 22329488Administrative Comment

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 30-day free trial to view this Administrative Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091021-EE-VQP-81