Help needed in stored procedures

Hi,
I wrote a stored procedure when i execute it. i get the error
ORA-00942: table or view does not exist
ORA-06512: at "SANDEEP.PROC_INS_TEMP_NAC_GL", line 18
ORA-06512: at line 9
I was unable to resolve this error please help.
CREATE OR REPLACE PROCEDURE PROC_INS_TEMP_NAC_GL(
p_bu IN STRING,
p_period IN STRING
IS
sql_stmt varchar2(1000);
cnt number;
BEGIN
     SELECT count(view_name) INTO cnt FROM sys.all_views where view_name = UPPER(p_bu||'_v_ldga') and owner = 'SUN';
     sql_stmt := 'INSERT INTO temp_nac_gl'||
     ' SELECT ''' || p_bu ||'''BU, gl.ACCNT_CODE , gl.ANAL_T0 , gl.ANAL_T1 , gl.PERIOD , gl.MEMO_AMT , gl.AMOUNT , gl.REGION, gl.ANAL_T3'||
               ' FROM sun.'|| p_bu ||'_v_ldga gl, temp_acnt_grp acnt' ||
               ' WHERE gl.accnt_code = acnt.acnt_code ' ||
               ' AND acnt.bu = '''|| p_bu ||'''' ||
               ' AND gl.period <= '''|| p_period || '''' ||
               ' ORDER BY gl.REGION';
EXECUTE IMMEDIATE sql_stmt;
END;
/

If you are accessing a object from a Oracle procedure/function then you need direct rights and not through roles.
You can check this by executing a SELECT from SQL plus , if you are able to see the table then type the following commond
SQL> set role none;
SQL> SELECT statement
If it gives an error then you dont have direct rights.
Thanks
Edited by: Himanshu Kandpal on May 14, 2009 5:04 PM

Similar Messages

  • Help needed in Stored Procedure validation

    Hi,
    I have defined 5 dimensions in my database. For GLs of Expense and Revenue drawer, I want to validate that if Dimension 1 is selected for a GL in any transaction, then Dimension 2 must also be mandatory.
    Now different transactions have different tables in SAP, like for service type AP Invoice and AR Invoice, I have to read different table; for Incoming & Outgoing Payment against Account, I have to read different table. Then there is Manual Journal Entry also etc.
    But all these transactions also generate a Journal Entry, so in my Stored Procedure, irrespective of AP, AR or whichever screen, how can I access the underlying Journal Entry of that transaction and validate the GL accounts in the Journal Entry that Dimension 2 is mandatory if Dimension 1 is selected?
    Thanks.

    Hi,
    What is your Account Dimension 1 and 2 supposed to be? Can you post here your Chart of Accounts? for us to build the right query for SP_TransactionNotification.
    Thanks
    Alvin

  • Help needed for Stored procedure

    I'm using this code for initializing an approval procedure.I want  to create an exception for customers whose  card code is ,C-KL-KKD -185 & C-KL-TCR-1204 in this procedure.How  to do this.Anyone please help.
    GO
    /****** Object:  StoredProcedure [dbo].[SP_Nocil_CreditDays_60]    Script Date: 04/04/2014 16:49:28 ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    ALTER PROCEDURE [dbo].[SP_Nocil_CreditDays_60]
      @list_of_cols_val_tab_del NVARCHAR(255), @error_message NVARCHAR(255) OUTPUT
    AS
    BEGIN
      declare @RowCount int
      select
      @RowCount=COUNT(RDR1.ItemCode)
      from ORDR
      inner join RDR1 on ORDR.DocEntry=RDR1.DocEntry
      inner join OITM on RDR1.ItemCode=OITM.ItemCode and OITM.U_SeriesGrp='N' and isnull(ORDR.U_Approved,'N')='N'
      where
      ORDR.DocEntry=@list_of_cols_val_tab_del
      if @RowCount>0
      begin
      select @RowCount=0
      select
      @RowCount=COUNT(OINV.DocEntry)
      from
      OINV
      inner join INV1 on OINV.DocEntry=INV1.DocEntry
      inner join OITM on INV1.ItemCode=OITM.ItemCode and OITM.U_SeriesGrp='N'
      where
      OINV.DocTotal-OINV.PaidToDate>0 and DATEDIFF(Day,OINV.DocDate,GETDATE())>60
      and OINV.CardCode=(select ORDR.CardCode from ORDR where ORDR.DocEntry=@list_of_cols_val_tab_del)
      if @RowCount>0
      begin
      select @error_message= 'This document required approval. Please select Approval to "Yes" to continue'
      return -1
      end
      else
      begin
      return 0
      end
      end
      return 0
    End

    Hi,
    Try this:
    GO
    /****** Object:  StoredProcedure [dbo].[SP_Nocil_CreditDays_60]    Script Date: 04/04/2014 16:49:28 ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    ALTER PROCEDURE [dbo].[SP_Nocil_CreditDays_60]
      @list_of_cols_val_tab_del NVARCHAR(255), @error_message NVARCHAR(255) OUTPUT
    AS
    BEGIN
      declare @RowCount int
      select
      @RowCount=COUNT(RDR1.ItemCode)
      from ORDR
      inner join RDR1 on ORDR.DocEntry=RDR1.DocEntry
      inner join OITM on RDR1.ItemCode=OITM.ItemCode and OITM.U_SeriesGrp='N' and isnull(ORDR.U_Approved,'N')='N'
      where ORDR.cardcode not in ('C-KL-KKD -185',' C-KL-TCR-1204') and
      ORDR.DocEntry=@list_of_cols_val_tab_del
      if @RowCount>0
      begin
      select @RowCount=0
      select
      @RowCount=COUNT(OINV.DocEntry)
      from
      OINV
      inner join INV1 on OINV.DocEntry=INV1.DocEntry
      inner join OITM on INV1.ItemCode=OITM.ItemCode and OITM.U_SeriesGrp='N'
      where ORDR.cardcode not in ('C-KL-KKD -185',' C-KL-TCR-1204') and
      OINV.DocTotal-OINV.PaidToDate>0 and DATEDIFF(Day,OINV.DocDate,GETDATE())>60
      and OINV.CardCode=(select ORDR.CardCode from ORDR where ORDR.DocEntry=@list_of_cols_val_tab_del)
      if @RowCount>0
      begin
      select @error_message= 'This document required approval. Please select Approval to "Yes" to continue'
      return -1
      end
      else
      begin
      return 0
      end
      end
      return 0
    End
    Thanks & Regards,
    Nagarajan

  • Need Help With a Stored Procedure

    Help With a Stored Procedure
    Hi everyone.
    I am quite new relative to creating stored procedures, so I anticipate that whatever help I could get here would be very much helpful.
    Anyway, here is my case:
    I have a table where I need to update some fields with values coming from other tables. The other tables, let us just name as tblRef1, tblRef2 and tblRef3. For clarity, let us name tblToUpdate as my table to update. tblToUpdate has the following fields.
    PlanID
    EmployeeIndicator
    UpdatedBy
    CreatedBy
    tblRef1, tblRef2 and tblRef3 has the following fields:
    UserName
    EmpIndicator
    UserID
    In my stored procedure, I need to perform the following:
    1. Check each row in the tblToUpdate table. Get the CreatedBy value and compare the same to the UserName and UserID field of tblRef1. If no value exists in tblRef1, I then proceed to check if the value exists in the same fields in tblRef2 and tblRef3.
    2. If the value is found, then I would update the EmployeeIndicator field in tblToUpdate with the value found on either tblRef1, tblRef2 or tblRef3.
    I am having some trouble writing the stored procedure to accomplish this. So far, I have written is the following:
    CREATE OR REPLACE PROCEDURE Proc_Upd IS v_rec NUMBER;
    v_plan_no tblToUpdate.PLANID%TYPE;
    v_ref_ind tblToUpdate.EMPLOYEEINDICATOR%TYPE;
    v_update_user tblToUpdate.UPDATEDBY%TYPE;
    v_created_by tblToUpdate.CREATEDBY%TYPE;
    v_correct_ref_ind tblToUpdate.EMPLOYEEIDICATOR%TYPE;
    CURSOR cur_plan IS SELECT PlanID, EmployeeIndicator, UPPER(UpdatedBy), UPPER(CreatedBy) FROM tblToUpdate;
    BEGIN
    Open cur_plan;
         LOOP
         FETCH cur_plan INTO v_plan_no, v_ref_ind, v_update_user, v_created_by;
              EXIT WHEN cur_plan%NOTFOUND;
              BEGIN
              -- Check if v_created_by has value.
                   IF v_created_by IS NOT NULL THEN
                   -- Get the EmpIndicator from the tblRef1, tblRef2 or tblRef3 based on CreatedBy
                   SELECT UPPER(EmpIndicator)
                        INTO v_correct_ref_ind
                        FROM tblRef1
                        WHERE UPPER(USERNAME) = v_created_by
                        OR UPPER(USERID) = v_created_by;
                        IF v_correct_ref_ind IS NOT NULL THEN
                        -- Update the Reference Indicator Field in the table TRP_BUSPLAN_HDR_T.
                             UPDATE TRP_BUSPLAN_HDR_T SET ref_ind = v_correct_ref_ind WHERE plan_no = v_plan_no;
                        ELSIF
                        -- Check the Other tables here????
                        END IF;
                   ELSIF v_created_by IS NULL THEN
                   -- Get the EmpIndicator based on the UpdatedBy
                        SELECT UPPER(EmpIndicator)
                        INTO v_correct_ref_ind
                        FROM tblRef1
                        WHERE UPPER(USERNAME) = v_update_user
                        OR UPPER(USERID) = v_created_by;
                        IF v_correct_ref_ind IS NOT NULL THEN
                        -- Update the Reference Indicator Field in the table TRP_BUSPLAN_HDR_T.
                             UPDATE TRP_BUSPLAN_HDR_T SET ref_ind = v_correct_ref_ind WHERE plan_no = v_plan_no;
                        ELSIF
                        -- Check the Other tables here????
                        END IF;
                   END IF;
              END;
         END LOOP;
         CLOSE cur_plan;
         COMMIT;
    END
    Please take note that the values in the column tblToUpdate.UpdatedBy or tblToUpdate.CreatedBy could match either the UserName or the UserID of the table tblRef1, tblRef2, or tblRef3.
    Kindly provide more insight. When I try to execute the procedure above, I get a DATA NOT FOUND ERROR.
    Thanks.

    Ah, ok; I got the updates the wrong way round then.
    BluShadow's single update sounds like what you need then.
    I also suggest you read this AskTom link to help you see why you should choose to write DML statements before choosing to write cursor + loops.
    In general, when you're being asked to update / insert / delete rows into a table or several tables, your first reaction should be: "Can I do this in SQL?" If you can, then putting it into a stored procedure is usually just a case of putting the sql statement inside the procedure header/footers - can't really get much more simple than that! *{;-)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Help with a stored procedure....

    i'll be honest, i have never written one, and i have been doing research all day to do one and i have not had much luck. Seems like they mostly all take variables or require data that i just do not want it to require.
    I have a query (using TOAD fyi) that is run every morning.... i am trying to make it a stored procedure because i am in the process of automating this for people who want it as opposed to sending it to everyone.
    This is the query i am trying to turn into a stored procedure.... (some details removed for sake of security)
    SELECT CASE
    WHEN stuff
    ELSE 'Unknown'
    END aging,
    a.transaction_type, a.status_code, b.description, a.exception_code,
    c.description,
    decode(a.exception_code,'XXXX','YYYY',
    'XXXX','YYYY',
    'XXXX','YYYY','EXCEPTION') "CATEGORY"
    ,COUNT (*)
    FROM (SELECT TO_DATE
    (DBMS_LOB.SUBSTR (clob_details,10,DBMS_LOB.INSTR (clob_details,
    '<TransactionDate>') + 17 ),'yyyy-mm-dd') receipt_date,
    transaction_type, status_code, exception_code
    FROM thisdb.TRANSACTION
    WHERE status_code = 'MX'
    AND clob_details IS NOT NULL) a,
    thisdb.status b,
    thisdb.EXCEPTIONS c
    WHERE a.exception_code = c.exception_code
    AND a.status_code = b.status_code
    and a.status_code = 'MX'
    GROUP BY a.status_code,
    b.description,
    a.transaction_type,
    a.exception_code,
    c.description,
    CASE
    WHEN Stuff
    ELSE 'Unknown'
    END;
    now, please do not worry about the contents of the query, it works nicely and does its job :)
    but how can i take this and encapsulate it so that i can turn it into a stored procedure?
    Thank you all very much for any and all advice, i do greatly appreciate it!

    Hi,
    user12733751 wrote:
    it is just a query, the results will be going to excel later, all that is created already (the connection and runnign basic queries via excel VBA), so perhaps you are right, i do not need a stored procedure but a view?
    I have not heard of a view (stored query), how does that work?You create a view once for all like this:
    CREATE OR REPLACE VIEW  fubar
    AS
    SELECT    CASE
               WHEN  stuff
              ...     -- the rest of your original query goes here
              END;And you use it just like a table:
    SELECT  *
    FROM    fubar;A user who runs this last, extremely short, query gets the exact same results as someone who runs your original query.
    Here's a completely different approach.
    Depending on your front-end, you could also save your original query in a script, called fubar.sql, and people could run it by simply saying
    @fubar

  • I need Help with the stored procedure

    Hello, I new with VS.Net
    I'm tring to call a stored procedure, but when i try to retrive the data don't return nothing.
    my VB code is the follows
    ocm_comando.Connection = ocn_coneccion
    ocm_comando.CommandText = "WPROC_PRUEBA"
    ocm_comando.CommandType = CommandType.StoredProcedure
    ocm_comando.Parameters.Add("PNI_ID_ESTUDIO", OracleDbType.Decimal).Direction = ParameterDirection.Input
    ocm_comando.Parameters("PNI_ID_ESTUDIO").Value = CType(vc_id_estudio, Integer)
    ocm_comando.Parameters.Add("pco_precalificada", OracleDbType.Varchar2).Direction = ParameterDirection.Output
    ocm_comando.Parameters.Add("pco_resultado", OracleDbType.Varchar2).Direction = ParameterDirection.Output
    Txb_empresa.Text = ocm_comando.Parameters("pco_precalificada").Value
    My stored procedure only take the parameter that I sent and make a simple select and return the value in the variable pco_precalificada
    thank for your help
    **** Sorry for mi English

    You forgot to actually execute the command. Before the last line, where you ask for the value of pco_precalificada, you need to:
    1. Open the connection (if it's not already open)
    2. Call ocm_comando.ExecuteNonQuery()
    HTH,
    Tom

  • I need help writing a stored procedure

    How do I update several tables with columns that store social security number as a single transaction? I have over 70 tables to update the ssn with correct ssn.The database I'm working on is not normalized.
    The update is strictly by request. Occasionally, I get calls for a customer who entered their ssn wrongly the first time they registered on the our website. when I get such a request, I manually update all the ssn in every database table that stores information
    about the customer. A very tedious task to update over 70 tables with ssn columns one by one. Does anyone have an idea how to do this efficiently ?Can someone show me how write a stored procedure that I can pass in the old SSN and the new SSN then it updates
    the 70 tables accordingly?
    Does anyone have a blue print that demonstrates how to write the stored procedure?
    TableName ColumnName
    table1 colA
    table2 colB
    table3 colC
    table4 cold
    I query the INFORMATION_SCHEMA.COLUMNS view
    to retrieve all the tables that have ssn columns as shown above.

    You can create a procedure that receives a ssn parameter and a key value to be searched for in every table, and then a varchar(max) variable that would store a dynamically generated SQL command based on the parameter values and the tables with the ssn column.
    Example:
    -- THE FOLLOWING VARIABLES ARE PARAMETERS
    DECLARE @SSN VARCHAR(100) = '12354676'
    DECLARE @PREDICATE VARCHAR(100) = 'A'
    DECLARE @CMD VARCHAR(MAX) = '' -- THIS IS THE COMMAND VARIABLE
    -- THIS WILL BUILD A SCRIPT TO UPDATE ALL TABLES WHICH CONTAIN THE SSN COLUMN
    SELECT @CMD = @CMD + 'UPDATE ' + T.NAME + ' SET SSN = ''' + @SSN + ''' WHERE KEY_COLUMN = ''' + @PREDICATE + '''
    GO
    FROM SYS.TABLES T
    WHERE T.OBJECT_ID IN (SELECT OBJECT_ID FROM SYS.COLUMNS WHERE NAME = 'SSN')
    EXEC (@CMD);
    Just because there are clouds in the sky it doesn't mean it isn't blue. But someone will come and argue that in addition to clouds, birds, airplanes, pollution, sunsets, daltonism and nuclear bombs, all adding different colours to the sky, this
    is an undocumented behavior and should not be relied upon.

  • Help! Need oracle help with constructing stored procedure that return resultsets

    Suns tutorial path for returning resultsets from stored procedures indicates that the following should work...
    CallableStatement cs = con.prepareCall("{call SHOW_SUPPLIERS}");
    ResultSet rs = cs.executeQuery();
    Thats if you build your stored procedure something like this ...
    String createProcedure = "create procedure SHOW_SUPPLIERS " + "as " + "select SUPPLIERS.SUP_NAME, COFFEES.COF_NAME " + "from SUPPLIERS, COFFEES " + "where SUPPLIERS.SUP_ID = COFFEES.SUP_ID " + "order by SUP_NAME";
    We are using oracle 8.1.6. However I've been told that with oracle procedures when you return a result set from a called procedure you return a p_cursor variable. Somthing like this
    (p_cursor in out SHOW_SUPPLIERS.SHOCurTyp)
    is
    begin
    open p_cursor for
    select * from suppliers
    In which case the above mentioned sun code doesn't work.
    We want to use jdbc to call a stored procedure that returns a resultset that does not require us to import any proprietary oracle objects...
    Is there another way to write these stored procedures, rather than using this cursor construct? Are we missing something in the way we invoke them?

    Suns tutorial path for returning resultsets from stored procedures indicates that the following should work...
    CallableStatement cs = con.prepareCall("{call SHOW_SUPPLIERS}");
    ResultSet rs = cs.executeQuery();
    Thats if you build your stored procedure something like this ...
    String createProcedure = "create procedure SHOW_SUPPLIERS " + "as " + "select SUPPLIERS.SUP_NAME, COFFEES.COF_NAME " + "from SUPPLIERS, COFFEES " + "where SUPPLIERS.SUP_ID = COFFEES.SUP_ID " + "order by SUP_NAME";
    We are using oracle 8.1.6. However I've been told that with oracle procedures when you return a result set from a called procedure you return a p_cursor variable. Somthing like this
    (p_cursor in out SHOW_SUPPLIERS.SHOCurTyp)
    is
    begin
    open p_cursor for
    select * from suppliers
    In which case the above mentioned sun code doesn't work.
    We want to use jdbc to call a stored procedure that returns a resultset that does not require us to import any proprietary oracle objects...
    Is there another way to write these stored procedures, rather than using this cursor construct? Are we missing something in the way we invoke them?

  • Help in JAVA stored procedure

    Hi,
    We need to interface a JAVA application from a pl/sql block. We are using JAVA stored procedure to do the same. This
    stored java class ( that we call from a PL/SQL procedure) has the
    statement ( " textFont = new Font("Arial", 0, 11)" ) where a Font is
    initialized. This is throwing an error message as given below. Please
    let us know if there is any issue with respect to usage of java.awt
    classes in java stored procedures (Oracle JVM of Oracle9i Enterprise
    Edition Release 9.2.0.2.0).
    We tracked down the exception to the following stack trace:
    java.lang.NullPointerException
    at java.lang.Class.forName0(Class.java)
    at java.lang.Class.forName(Class.java)
    at
    java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnviron
    ment.java)
    at java.awt.Font.initializeFont(Font.java)
    at java.awt.Font.<init>(Font.java)
    at com.idautomation.pdf417.PDF417.<init>(com/idautomation/pdf417/PDF417)
    at GenBarCode.createBarCode(GenBarCode.java:24)
    at CallGenBarCode.callGenerateBarCode(CallGenBarCode.java:14)
    g_error_text= ORA-29532: Java call terminated by uncaught Java
    exception: java.lang.NullPointerException in CallGenBarCode_callGBC
    DECLARE
    ERROR at line 1:
    ORA-20001: ORA-29532: Java call terminated by uncaught Java exception:
    java.lang.NullPointerException in CallGenBarCode_callGBC err 15
    ORA-06512: at line 12
    Any pointers in this regard will be of great help.
    thanks,
    Ayyappa

    Hi,
    OracleJVM, as a server-side VM, does not support any UI classes such as awt and swing. The basic GUI components found in the JDK's Abstract Windowing Toolkit (AWT) cannot be used in Stored procedures.
    For more information refer to http://otn.oracle.com/docs/products/oracle9i/doc_library/release2/java.920/a96659/01_intro.htm#16826
    Hope this helps.
    Sujatha.
    http://otn.oracle.com/sample_code/content.html

  • HELP!! Stored Procedures - Adding and Inserting Records

    Can ANYONE tell what I'm doing wrong? I'm learning PL/SQL, and I don't know what I'm missing here.
    For starters, I'm trying to write a stored procedure to:
    -- insert data into a NULL column added using ALTER TABLE
    -- there's about +/- 45 records where this data needes to be added.
    -- the value for each null field in the column is a random value (that is, generated using dbms_random.random
    I've tried several ways to write the procedure, but have run against a wall to determine what I'm missing.
    Here's the SQL statements and the error messages:
    SQL> CREATE OR REPLACE PROCEDURE update_proj_number (p_proj4_id IN VARCHAR2)
    2 AS
    3 BEGIN
    4 DECLARE
    5 v_counter NUMBER(5) := 0;
    6 END;
    7 BEGIN
    8 v_counter := 0;
    9 dbms.random.initialize(32768);
    10 v_counter := v_counter + 1;
    11 p_proj4_id := dbms.random.random
    12 UPDATE sample_trades
    13 SET proj4_id = RANDOM(p_proj4_id);
    14 exit when NOTFOUND%;
    15 END;
    16 /
    Warning: Procedure created with compilation errors.
    SQL>
    SQL> SHOW ERRORS
    Errors for PROCEDURE UPDATE_PROJ_NUMBER:
    LINE/COL ERROR
    6/2 PLS-00103: Encountered the symbol "END" when expecting one of the following:
    begin function package pragma procedure subtype type use <an identifier>
    <a double-quoted delimited-identifier> cursor form current
    12/3 PLS-00103: Encountered the symbol "UPDATE" when expecting one of the following:
    . ( * @ % & = - + ; < / > in mod not rem an exponent (**)
    <> or != or ~= >= <= <> and or like between is null is not &#0124; &#0124; is dangling
    The symbol ";" was substituted for "UPDATE" to continue.
    14/22 PLS-00103: Encountered the symbol ";" when expecting one of the following:
    ( type <an identifier> <a double-quoted delimited-identifier>
    SQL>
    Would it be more efficient to use a cursor to fetch the rows containing the null value or is a stored procedure OK for this?
    Also, I would like to have a second example of a stored procedure that will add random rows to a table (that is, create duplicates of information already in the table). This stored procedure will also use dbms_random.
    For example,
    IF p_value1 = 'FIRST_VALUE' then
    add this record (incl. random_val for key);
    ELSIF p_value = 'SECOND_VALUE' then
    add that record (incl. random_val for key);
    and on and on.
    Much thanks to anyone who can help.
    For example,
    null

    Try this
    CREATE OR REPLACE PROCEDURE update_proj_number (p_proj4_id IN VARCHAR2)
    AS
    v_counter NUMBER(5) := 0;
    BEGIN
    v_counter := 0;
    dbms.random.initialize(32768);
    v_counter := v_counter + 1;
    p_proj4_id := dbms.random.random ;
    UPDATE sample_trades
    SET proj4_id = RANDOM(p_proj4_id);
    END;
    /

  • Help creating a stored procedure

    I have a query that is going to run many, many times per day, potentially hundreds of thousands so I want to make sure it's as quick as possible
    The purpose is to take a compiled IP number, look it up and relate it back to the country based on data in the table for current IP/countries
    There are currently 113,536 records in the country table, It's typically taking around 4ms to 5ms, so it's not exactly slow, but as the use of this particular lookup is going to increase significantly I'd like to make sure I have it as fast as possible.
    Here's the current code:
    <CFSET ipnumber = (#listgetat(remote_addr,1,'.')# *256*256*256) +  (#listgetat(remote_addr,2,'.')# *256*256) + (#listgetat(remote_addr,3,'.')#  *256) + #listgetat(remote_addr,4,'.')#>
    <CFQUERY name="GetCountry" DATASOURCE="#datasource#">
        SELECT TOP 1(countryshort) as countryshort
        FROM #ipcountry#
        WHERE ipfrom <= #ipnumber# and ipto >= #ipnumber#
    </CFQUERY>
    The first thought is to try to create a stored proc to see if that generates any performance gain, I've search and read over several documents on setting one up, but I have to admit, I just can't quite grasp it.
    I'm wondering if anybody would be kind enough to stick this query into a stored proc for me and let me know what CF code I need to execute it and read the result.
    Once I see this done I am sure I'll be able to push forward from there on my own in the future
    Thanks
    Mark

    JR \"Bob\" Dobbs wrote:
    Bear in mind that database servers, such as Microsoft SQL Server, will cache the execution plan for parameterized SQL queries which will result in performance gains similar to use of a stored procedure. 
    You might try using CFQUERYPARAM in your queries.  This is also recommended to help prevent SQL injection attacks.
    You might also create indexes on the ipfrom column on your table.
    Agreed. Just wrapping a query in a stored procedures does not mean it is going to run faster. Look at the table's indexes and examine the execution plan to see how it can be improved. And you really should be using cfqueryparam in all of your queries. Not just for performance, but because you are risking sql injection attacks without it.
    HiTopp wrote
    EXEC sp_executesql @sql,
    Since the table name is hard coded, there really is not a need for dynamic sql in this query.
    Message was edited by: -==cfSearching==-

  • Help in calling stored procedure with parameter in JSP

    I need to know how to call this stored procedure in JSP
    here is my Stored procedure in oracle 9i:
    CREATE OR REPLACE procedure broker_activity
    (p_broker_id IN number,p_TotalValue out number,p_CrossValue out number, p_blockValue out number, p_MktWeight out number,p_BuyingVal out number, p_sellingVal out number, p_NetValue out number)
    AS
    begin
    declare
    -- buying value
    cursor c_BuyingVal is select buyer_firm, sum(volume*price) value from last_sale where buyer_firm = p_broker_id group by buyer_firm;
    -- selling value
    cursor c_SellingVal is select seller_firm,sum(volume*price) value from last_sale where seller_firm = p_broker_id group by seller_firm;
    v_BuyingCurVal c_buyingVal%rowtype;
    v_SellingCurVal c_sellingVal%rowtype;
    n_buy_val number :=0;
    n_sell_val number :=0;
    n_total_value number := 0;
    begin
    --buying value
    open c_BuyingVal;
    fetch c_BuyingVal into v_buyingCurVal;
    n_buy_val := nvl(n_buy_val,0) + v_buyingCurVal.value;
    --Exit when c_BuyingVal%NOTFOUND;
    close c_buyingVal;
    p_BuyingVal := n_buy_val;
    --selling value
    open c_SellingVal;
    fetch c_SellingVal into v_SellingCurVal;
    n_sell_val := nvl(n_sell_val,0) + v_SellingCurVal.value;
    -- Exit when c_BuyingFirm%NOTFOUND;
    close c_SellingVal;
    p_SellingVal := n_sell_val;
    --total value
    p_TotalValue := n_buy_val + n_sell_val;
    --cross val
    select sum(volume*price) into p_CrossValue from last_sale where board = 'C' and (buyer_firm = p_broker_id or seller_firm = p_broker_id);
    --block Sale
    select sum(volume*price) into p_BlockValue from last_sale where board = 'B' and (buyer_firm = p_broker_id or seller_firm = p_broker_id);
    --Net Value
    p_NetValue := n_buy_val - n_sell_val;
    --markte_weight
    select (sum(volume*price) * 2)/100 into p_MktWeight from last_sale ;
    end;
    end;

    http://developer.java.sun.com/developer/onlineTraining/Database/JDBC20Intro/JDBC20.html

  • Help: using a stored procedure to insert a record in DB

    A stored procedure:
    PROCEDURE db_insert
    db_block IN OUT plsql_table)
    is created in DB.
    db_select and db_update are created too. They both work fine as
    db_select is called by go_block execute_query (block populated) and
    db_update is called by commit (DB updated);
    I am trying to have db_insert called as:
    1. DO_KEY('Create_Record');
    2. fill in fields and then
    3. commit.
    These 3 steps do not cause the call of the auto generated block trigger insert_procedure. I think that after filling in the fields and there should be a way to call this insert_procedure trigger. I am not sure how this will work.
    Any suggestions are greatly appreciated.

    I went through quite a deep search and yet not found any good answers. Knowing that select and update all done well with execute_query(stored procedure is called) and commit(stored procedure is called), but not insert.
    Logically there must be some FORM build in that will trigger the call of stored procedure insert.
    I am still looking for answers and just to remind that there are quite number of similar posts and I do not think that any clear answers were delivered.
    Please help.

  • Please help convert MSSQL Stored Procedure to Oracle PL/SQL

    Hi there to all,
    this be my first post to these forums. I have already posted this question on a microsoft msdn forum, until someone advised that I ask my question here - dunno why I didnt think of that! ?:|
    Im working with an Oracle 10g Database from an ASP.NET 2.0 application, and want to know if it Oracle supports OPENXML (rhetorical question I fear!). The reason I ask is because I want to create an Oracle Stored Procedure that will accept an XML string as an input parameter, prepare it, select from it, and then insert it into an Oracle table.
    I have done this successfully in SQL server using the following as an example:
    CREATE PROCEDURE [dbo].[Employee_INSERT]
    bq. @INSERTRECORD XML
    AS
    BEGIN
    bq. DECLARE @XDOC INT; \\ EXEC sp_xml_preparedocument @XDOC OUTPUT, @INSERTRECORD; \\ INSERT INTO [dbo].[REC_Employees] (
    bq. bq. [EMPTITLE], \\ [EMPFNAME], \\ [EMPLNAME], \\ [EMPDEPTID], \\ [EMPBEGINDATE], \\ [EMPACTIVE], \\ [EMPDATEADDED]
    bq. )
    bq. SELECT
    bq. bq. [EMPTITLE] = Title, \\ [EMPFNAME] = Firstname, \\ [EMPLNAME] = LastName, \\ [EMPDEPTID] = DepartmentID, \\ [EMPBEGINDATE] = StartDate, \\ [EMPACTIVE] = IsActive, \\ [EMPDATEADDED] = GETUTCDATE()
    bq. FROM
    bq. bq. OPENXML(@XDOC, '/EMPREC/Table', 2) \\ WITH (
    bq. bq. Title VARCHAR(10), \\ FirstName VARCHAR(50), \\ LastName VARCHAR(50), \\ DepartmentID INT, \\ StartDate DATETIME, \\ IsActive BIT
    bq. bq. );
    bq. EXEC sp_xml_removedocument @XDOC;
    END
    I would sincerely appreciate any help in this regard!
    PS - Please excuse the formatting!
    Much Thanks!
    regards
    shalan

    Assuming your table is named DESTINATION
    Name                                      Null?    Type
    TITLE                                              VARCHAR2(10)
    FIRSTNAME                                          VARCHAR2(50)
    LASTNAME                                           VARCHAR2(50)
    DEPARTMENT                                         NUMBER
    STARTDATE                                          DATE
    ISACTIVE                                           NUMBERYou can use a procedure like:
    create or replace
    procedure test (p_xml in xmltype)
    is
    begin
      insert into destination
      select title
           , firstname
           , lastname
           , department
           , to_date (startdate, 'yyyy-dd-mm hh24:mi:ss') startdate
           , isactive
        from (xmltable ('/EMPREC/Table' passing p_xml
                       columns title varchar2(5) path 'Title'
                             , firstname varchar2(10) path 'FirstName'
                             , lastname varchar2(10) path 'LastName'
                             , department number path 'Department'
                             , startdate varchar2(20) path 'StartDate'
                             , isactive number path 'IsActive'
                      ) temp
    end test;to create records in the table
    Removed a unnecessary SELECT FROM DUAL...
    Edited by: Alex Nuijten on Jan 19, 2009 2:24 PM

  • Help with Command - Stored Procedure

    Hi all,
    I'm having a great deal of difficulty getting my head around
    an update command / stored procedure, I've pulled out all of my
    books and spent the last two days on Google which has made my
    confusion worse. In simple terms what I'm trying to do is update a
    field in a table with the value y, but based on certain criteria.
    So my table has the following fields -
    JBAID
    JBASiteID
    JBADatePosted
    JBAPostFor
    JBANotified
    What i want to do is update the value of field JBANotified on
    all records that meeting the following criteria to Y
    The criteria is -
    WHERE DATEADD(d,JBAPostFor,JBADatePosted) BETWEEN DATEADD(d,
    -7, GETDATE()) AND GETDATE() AND JBANotified = 'n' AND JBASiteID =
    MMColParam (where MMColParam is Session("SITEID"))
    So I've just tried building a command / stored procedure -
    which reads (see attached code)(more than likely all wrong)
    The things that I cant get my head around are -
    Firstly getting the code right in the first place, running
    the command on page load and then when the command has run
    redirecting to the next page.
    I really would appreciate some help with this -
    thanks all

    Ed Stewart wrote:
    > Are you using CS3 with ASP/VBScript? There is a bug in
    the command
    > implementation that has this function broken.
    >
    > I asked about it in this forum several months ago, but
    now I can't find my
    > original post, but I did find another post that talks
    about the same thing:
    >
    http://www.adobe.com/cfusion/webforums/forum/messageview.cfm?forumid=12&catid=26
    > 3&threadid=1281539&enterthread=y
    >
    > My solution is to drop back to DW8 for command editing,
    but use CS3 for
    > everything else. I don't know what you're supposed to do
    if you don't have an
    > earlier version.
    >
    > It looks like your sql is correct, but the bug prevents
    the second code block
    > is not being updated with the correct values.
    >
    > I hope a solution is forthcoming....
    >
    Create a stored procedure and then use a recordset to
    exectute it,
    making sure the recordset has matching parameters that the
    stored
    procedure expects.
    Commands are broken, I reported it to Adobe and they said it
    might get
    fixed in the next version.
    Steve

Maybe you are looking for

  • Lightroom hangs when attempting to import RAW files from D750

    Hi guys, I purchased lightroom 5 sometime back to install on multiple platforms. Recently did an update on my macbook and it was able to read the NEF files from D750. However when I installed lightroom 5 on my iMac, the prog keeps hanging when I atte

  • Tracing User Exits for Transaction ME22N

    I have a problem with the transaction ME22N. When I try to add an additional item for a certain PO, I can't save the changes because there is an error message saying one of the previously created item has to be checked under the 'Returns' field. The

  • Trouble with reinstall of Win7 64 on a L505-ES5018

    Toshiba Satellite L505-ES5018, Win 7 64: Hard drive crased so I installed a new one and ordered the recovery disks for L500 series and installed. Some drivers are unsigned and WIndows Update nor the Windows Troubleshooter will work. Win Update says i

  • How to fix font and app color

    My iPod touch changed the color of wallpaper and the color behind some of the apps. How do I get it back to normal?

  • More than 2.5 million requests

    Is it possible that I can call Search API more than 2.5 million times in a month? How can I calculate the cost in that case? I could see the price for only fewer than 2.5 million requests in the table below. (datamarket.azure.com/dataset/bing/search)