Stored Procedure to update some or all fields of a record

Hi,
I want to create a stored procedure in oracle pl/sql 8.1.7 which takes all field values of a table as a parameters and update the table. What if i want to update only selected fields via same procedure? Can we have something like this:
create table students (stdno number(4), stdname varchar2(20), stdaddress varchar2(30));
create procedure update_student (stdno2 number, stdname2 varchar2, stdaddress2 varchar2 default :old.stdaddress)
begin
update students set stdname = stdname2, stdaddress = stdaddress2 where stdno = stdno2;
end;
exec update_student(12, 'Ali');
And it updates only student name?
Thanks.

create or replace
procedure update_student (p_stdno number, p_stdname varchar2 default null, p_stdaddress varchar2 default null) is
begin
if p_stdname is not null or p_stdaddress is not null then
update students A
set stdname = nvl(p_stdname ,A.stdname )
,stdaddress = nvl(p_stdaddress,A.stdaddress)
where stdno = p_stdno
end if ;
end ;

Similar Messages

  • How to use the Stored Procedure to update my UDF

    I want to use the Stored Procedure to update my UDF U_InstokCS when the warehouse "OnHand" was changed. The UDF is display the stock by cases. I copied the query as follewing. I couldn't see any thing in the UDF after I made some transactions. Can anybody tell me why? How to continue it?
    if @transaction_type in ('A','U','D') and @Object_type='64'
    begin
    Update OITW
    Set U_InstokCS = OnHand/(Select T0.NumInBuy from [DBO].[OITM] T0
    Where T0.ItemCode = @list_of_cols_val_tab_del)
    Where ItemCode = @list_of_cols_val_tab_del
    end
    Thanks.
    Ying Zhang

    Ying,
    The use of any stored procedures against the SAP Business One database is not allowed per SAP Support.  There is not an instance where you can use SP's.  The ONLY SP that you are allowed to use is the SBO_SP_TransactionNotification SP that comes with SAP Business One itself. You can read about the use of this SP from this article...
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/e991e2b9-0901-0010-0395-ef5268b00aaf
    Eddy

  • Stored Procedure to update Ids

    Hi,
    I want to write a stored procedure to update IDs in detail table by matching description from master table i.e.
    TabMaster
    Col1: 1 2 3 4 5 6 7 8
    Col2: A B C D E F G H
    TabDetail
    Col:
    Col2: D B C E D A A B G H C
    Please Help!
    Thanks in advance

    Now sure what you are really after, but it looks like you may only need a correlated update statement. This statement can then be put inside a stored procedure:
    UPDATE  TabDetail TD
    SET     Col = (
                    SELECT  Col1
                    FROM    TabMaster TM
                    WHERE   TD.Col2 = TM.Col2
                  )This will update ALL the rows in the TabDetail table. However if you need to restrict the rows to be updated you can always add on a WHERE clause.

  • Stored procedure to update particular key column with increment of +1

    Hi,
    This is my table
    EMPID,NAME
    1 SSS
    2 AAA
    I NEED STORED PROCEDURE TO UPDATE EMPID WITH INCREMENT OF +1.BASED ON
    MAX(EMPID).fOr example if i execute stored procedure once it will update empid 2 as 3,
    if i run same procedure again it will take increment +1 then emp id should be 4 like that i want output.
    Any one please help me on this scenario...

    937506 wrote:
    Hi All,
    I have two tables,one is date dimension table,one is fact table.
    when we load data through informatica (source as csv file),then key will be populated in fact table based on lookup on
    date dimension table.it will create corresponding date key in fact table.
    My scenario:we load data in to fact table with etl with "n" number of records only once at a time.
    But next time onwords we will update that datekey in fact table through stored procedure.stored procedure
    will take only max(date_key) from fact table then update that key as like +1(logic n+1)
    If i run stored procedure nextday it will update that record with increment +1.
    we wil schedule this storedprocedure to run daily once.For this i need stored procedure..
    I think you will clear now................
    thxSo, are you saying you want to keep the same data you loaded "yesterday" but update the date_key so it appears as if it was from today?
    Still seems strange: why aren't you loading today's data?
    Also, you are assuming that the date_key in the date dimension table increments with no gaps: if it was sequence generated, that might not be true.

  • Opening a stored procedure in Crystal 12 with all formatting intact

    Is it possible to use Crystal to revise something in a stored procedure when the entire report was created via SQL?
    For clarity, I didn't create the procedure in question. I am trying to update some wording in a text box, but when I tried to pull up the stored procedure in Crystal, it brought  up a blank report with no formatting, no images, and no text boxes. I therefore assume that all of this non-field data has been coded into the stored procedure.
    Please assume for the purposes of this question that manually recreating the report from scratch is not an option. Also please assume that Crystal is the only tool I have available for updating the text box.
    In case it is relevant, I am using Crystal 12/2008, and the stored procedure is probably intended for Crystal 10 or 11. However, I am pretty sure it wouldn't matter which version it was intended for.

    Jane,
    1) All your stored procedure is going to do, at least as it pertains to CR (any version), is return a result set. It can do hundreds of things in the background, but for it to be of any use in CR it must simply provide a set of records... Nothing else.
    It will not hold any information pertaining to the report definition itself... No formatting... Nothing about manually placed text boxes...
    2) Stored Procedures aren't written for any specific report writing software. They are written for specific databases.
    That said, an SP can be written for the purpose of reporting in general in that it sole purpose in life is to supply a set of records when called upon to do so by whatever reporting software calls on it.
    3) You can't "Call up" an SP in CR. An SP is code that's stored on your database server. If you with to view the actual code that makes up the SP itself, throw "how to view the code in a stored procedure" into a Google search..
    HTH,
    Jason

  • Form on table: Using stored procedure to update?

    I have a view which joins a handful of tables. I have a PL/SQL API that contains all the necessary business logic and translations to update the tables underlying this view.
    If I use the HTMLDB wizard to create a form on this view, it would automatically generate plain INSERT/UPDATE statements for DML against the view. How can I make it use my API instead? (Yes, I can probably plug in my API in INSTEAD OF triggers on the view, but I really dont want to do that)
    [Of course, the reason I would use the built-in form-on-table wizard is to get the automatic lost-update detection, locking, etc features]
    Help? Thanks

    The wizards are there to help you build typical pages like "form based on a table", "form on based a stored procedure".
    There is no wizard for "form based on a view, using my own API for inserts, updates and delete" - but that doesn't prevent you building such a form by hand. I have built similar forms, and found it quite easy to approach it like this:
    1) use "form based on a stored procedure" to create a form based on your API insert procedure
    2) add further buttons and processes to call your API's update and delete procedures
    3) add an "on load" process to select the row from the view and populate the form for update or delete
    You need to add some logic for context-sensitivity - e.g. Update and Delete buttons only appear when in "update mode", etc.

  • Stored procedure to update the new table by using back up table

    Hi all,
    oracle version -10g
    iam planning to do one time legacy conversion during the migration of one of the tables.
    for that i took the back up of table , now i need to transfer all of the data from the backup table to the new table with some changes..
    so please suggest me how to write the stored procedure?
    back up table name: test t
    new table: test n
    new table will have extra one row .. in that i need to put the logic
    so am planning to write a procedure like below
    create or replace procedure test as
    begin
    insert into TEST T ( u
              v
              w
              X
              y
              z) VALUES
    SET T.U = O.U
    T.V = O.V
    T.W = DECODE(O.W, AD     '01',
                   00     '01')
    T.X = O.X
    T.Y = IF O.W = 'AD' AND O.Y = 'YES' THAN PUT 'AD'
         IF O.W = '00' AND O.Y = 'YES' THAN PUT 'PD'
    IF O.W NOT IN ('AD','00') AND O.Y = 'YES' THEN PUT 'E'
    O.Y= 'NO' THEN PUT 'D'.
         '

    10g is not an Oracle version number. Please run the following:
    SELECT * FROM v$version;What about your situation indicates a requirement for a stored procedure? I wouldn't write one based on what you have posted. It seems, again from what little you posted, that all you need is:
    INSERT INTO <new_table>
    SELECT ... FROM <temp_table>;

  • Stored Procedure - for update of commit problem

    HI all,
    I am getting an ORA-01002 error when rnning my stored procedure. I understnad this is because i am "commiting" when using a "For update of". But I am not sure how to commit or rollback this transaction. The procedure is below.

    oraCraft wrote:
    Do you know any way I can clean the code?Depends what's wrong with it. If you are getting the message 'Sorry, this content is not allowed' then there is a word blocked by the forum software (like 'dis&#99;ount').
    If it doesn't display at all, then it may be to do with HTML. For example, posting <tt>&lt;></tt> is tricky.

  • With clause in a stored procedure with update

    create table TEMP_STAGE as
    (select '111111' student_id, 'N' TMP_TEST FROM DUAL
    UNION
    select '111111' student_id, 'N' TMP_TEST FROM DUAL
    UNION
    select '222222' student_id, 'N' TMP_TEST FROM DUAL
    CREATE OR REPLACE PROCEDURE TEMP_SEC_TEST
    AS
    BEGIN
    UPDATE TEMP_STAGE S
    SET S.TMP_TEST = 'Y'
    WHERE STUDENT_ID IN
    WITH MARK AS
    SELECT '111111' STUDENT_ID FROM DUAL
    select STUDENT_ID from MARK
    END;
    I have a huge sql statement with several 'with' tables in the statement...It works if I execute it as a script but it does not work when I put it in a stored procedure.
    When I execute the above it gives me an error...
    Error Syntax Check (8:9)
    Found 'MARK' expecting .....
    It gives me an error at the wth Mark as line....
    I have to do it in the stored procedure as the statement is very complicated...
    Please help.

    What tool are you using to create the procedure? Error Syntax Check (8:9) is not an Oracle error, nor as far as I know from any Oracle product.
    It works just fine in sqlplus.
    SQL> CREATE procedure my_p AS
      2  BEGIN
      3     UPDATE t
      4     SET descr = 'Un'
      5     WHERE id IN (WITH tmp AS (
      6                     SELECT 1 x FROM dual)
      7                  SELECT x FROM tmp);
      8  END;
      9  /
    Procedure created.
    SQL> SELECT * FROM t;
            ID DESCR
             1 One
    SQL> exec my_p;
    PL/SQL procedure successfully completed.
    SQL> SELECT * FROM t;
            ID DESCR
             1 UnJohn

  • Stored Procedure for updating dynamic columns in a table

    I have a table with a lot of columns around 30ish
    Now I want to create a stored procedure that will update a specific column to a new value.
    I the @columname and @newvalue to be the parameters, and an addition @itemId for the WHERE clause so it will update that specific row/data only.
    here's my Stored Procedure
    USE [db]
    GO
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    ALTER PROCEDURE [dbo].[usp_UpdateData]
    @itemID int,
    @ColumnName varchar(50),
    @newValue nvarchar(50)
    AS
    BEGIN
    Update dbo.ProjectAllocation
    Set @ColumnName = @newValue
    Where itemID = @itemID END
    When I pass the following
    @ColumnName: UserName
    @newValue: NewUserName
    @itemID: 1
    it doesnt update row with itemID = 1.
    How can I do this?
    ----------------------- Sharepoint Newbie

    Did you try my last post method. Its better to use parameterized approach.
    Anyway, if you want to change your code,you may need to change as below.....
    SET @sql = 'UPDATE dbo.table SET ' + @ColumnName + '=''' + @newValue + ''' WHERE [itemID] = ' + cast(@itemID as varchar(50));

  • Exit stored procedure after UPDATE

    Hello,
    I have written a LOOP that calls a second Stored Procedure.
    In the second Stored Procedure I have 3 INSERTS each SELECT's values limited with a WHERE clause.
    Example:
    begin
    dynsql:=INSERT INTO destinationtable (ID,DATE,NAME)
    SELECT src.ID,src.DATE, dest.NAME FROM sourcetable src INNER JOIN destinationtable dest ON dest.ID=src.ID WHERE dest.date between '01.JAN.2012 and '03.JAN.2012' --if not condition not met, no insert
    execute immediate dynsql;
    dynsql:=UPDATE destinationtable SET DATE = dest.DATE FROM sourcetable src INNER JOIN destinationtable dest ON dest.ID=src.ID WHERE dest.date between '01.JAN.2012 and '03.JAN.2012'
    execute immediate dynsql;
    dynsql:=INSERT INTO destinationtable (ID,DATE,NAME)
    SELECT src.ID,src.DATE, dest.NAME FROM sourcetable src INNER JOIN destinationtable dest ON dest.ID=src.ID WHERE dest.date between '01.APR.2012 and '01.MAY.2012'  --if not condition not met, no insert
    execute immediate dynsql
    dynsql:=UPDATE destinationtable SET DATE = dest.DATE FROM sourcetable src INNER JOIN destinationtable dest ON dest.ID=src.ID WHERE dest.date between '01.APR.2012 and '01.MAY.2012'
    execute immediate dynsql;
    dynsql:=INSERT INTO destinationtable (ID,DATE,NAME)
    SELECT src.ID,src.DATE, dest.NAME FROM sourcetable src INNER JOIN destinationtable dest ON dest.ID=src.ID WHERE dest.date between '01.JUN.2012 and '01.JUL.2012'  --if not condition not met, no insert
    execute immediate dynsql;
    dynsql:=UPDATE destinationtable SET DATE = dest.DATE FROM sourcetable src INNER JOIN destinationtable dest ON dest.ID=src.ID WHERE dest.date between  '01.JUN.2012 and '01.JUL.2012'
    execute immediate dynsql;
    end;
    commit;What do I do?
    I update the existing "old" row with a new date and then I am basically duplicating that row but adding it with a new DATE, the ID and NAME is "copied" as it is.
    The big problem is that the rows result in recursive updates. if the first statement updates a date it might make the conditions for the second and first update become "true".
    Which is not what I want. Initially, only one of the statements is true, ever. The problem with my code is that after the first update and date setting, another "might" become true.
    This should stop. After one of the updates occured, I need to stop the stored procedure.
    How do I stop it after upate?

    metalray wrote:
    Hello BlueShadow, that makes sense. Thanks.
    Can you tell me when sql&rowcount is reset, after an execute immediate, after a commit?It doesn't get 'reset' in the strict sense. When a PL/SQL program unit is initiated the implicit "SQL" cursor space is defined and exists in the scope of that program unit. At that point it is like any variable that is declared with it's value undefined (null). When you issue any DML statement (insert, update, delete, merge etc.), these will explicitly set the ROWCOUNT attribute within the SQL cursor space. Other SQL statements are also issued from PL/SQL through the SQL "space" (interface), and as such, they may (it's not defined anywhere) effect the values of attributes within it, including the ROWCOUNT, but we cannot say exactly in what way. Therefore, the only thing that can be definitely determined is that a) when it's first instantiated, the SQL%ROWCOUNT will be null, and also, )_immediately_ after any appropriate DML statement the SQL%ROWCOUNT will contain the number of rows effected. If the SQL%ROWCOUNT value is examined at any other point, the value is indeterminate so, for example, after a commit statement, we cannot be sure what value it has or what that value refers to.
    I loop through each tax no. need to do either an update, update or delete, delete, each with different WHERE clauses. the danger is that
    I update and then the where clause for the deletion becomes true, but my process should not do the deletion if an update happened. its a sequential check and ones true and update/deletion made, the loop stored procedure should terminate. right now I check for sql&rowcount to "not" get into a update or delete if one already happened but I fail to grasp the logic of when sql&rowcount gets which value . I have the feeling that the parent stored procedure that calls my second one with the update and deletes sets the sqlrowcount to 1 because it has an insert. (I use 11g)After your insert/update you should immediately get the value of SQL%ROWCOUNT into a variable, so that you have the value before it is effected by other statements.
    You can then use that value in your variable to determine program logic e.g. whether the delete should process or not, regardless of whether you issued further code between the insert/update and the check to see if you should delete. Don't rely on things 'resetting' the ROWCOUNT attribute, only rely on things setting it.

  • Strange error on stored procedure after update to version 7.6.06.10

    Hi,
    in past version MaxDB 7.6.03 i created a stored procedure with follow SQL statement inside:
    TRY
                SELECT SUM(QTDE) QTDE_SAIDA
                   FROM VENDOR_CONCES.MVIEW_MOVPRODUTOS mviewS
                   WHERE mviewS.MY_EMPRESA = :OID_EMPRESA AND
                         mviewS.MY_PRODUTO_DEF = :OID_PRODUTO_DEF AND
                         mviewS.GERA_ESTOQUE = 'S' AND
                         mviewS.TIPO = 'S' AND
                         mviewS.DATA BETWEEN :MAX_DATA_ESTOQUE_INICIAL AND :DTA_ESTOQUE AND
                         EXISTS(SELECT * FROM VENDOR_CONCES.MVIEW_MOVPRODUTOS mviewE WHERE 
                            mviewE.my_Empresa = mviewS.my_Empresa AND
                            mviewE.tipo = 'E' AND
                            mviewE.data <= mviewS.data AND
                            mviewE.my_Produto = mviewS.my_Produto AND
                            mviewE.gera_Estoque = 'S' AND
                            mviewE.gera_Financeiro != 'N'
                FETCH INTO :QTDE_SAIDA;
            CATCH
                IF $rc <> 100 THEN STOP ($rc, 'unexpected error ao contar Saidas');
    if execute that procedure with new version 7.6.06.10 i get an error:
    (at 1834): Data types must be compatible.
    the line of error is this:
    mviewS.DATA BETWEEN :MAX_DATA_ESTOQUE_INICIAL AND :DTA_ESTOQUE AND
    if i remove the EXISTS part that procedure works, but i need to use EXISTS there.
    ps: MVIEW_MOVPRODUTOS is a table, not a view, i preceed tables with MVIEW for tables created by triggers, to simulate Materialized Views.
    ps2: DATA field is DATE field on english.
    any idea what can be wrong?
    best regards.
    Clóvis

    Hi, Elke
    you are right, changing SELECT * to SELECT oid works, follow the full procedure with changes:
    CREATE DBPROC SP_ESTOQUE_ATUAL_DATA_PROD_DEF (
        IN OID_EMPRESA VARCHAR(8),
        IN OID_PRODUTO_DEF VARCHAR(8),
        IN DTA_ESTOQUE TIMESTAMP,
        OUT ESTOQUE_ATUAL VARCHAR(200))
    AS
        VAR MAX_DATA_ESTOQUE_INICIAL TIMESTAMP;
            QTDE_ESTOQUE_INICIAL FIXED(10,3);
            QTDE_SAIDA FIXED(10,3);
            QTDE_ENTRADA FIXED(10,3);
        BEGIN
            TRY
                SELECT MAX(DATA) MAX_DATA_ESTOQUE_INICIAL
                   FROM VENDOR_CONCES.ESTOQUEINICIAL
                   WHERE MY_EMPRESA = :OID_EMPRESA AND
                       MY_PRODUTO = :OID_PRODUTO_DEF AND
                       DATA <= :DTA_ESTOQUE;
                FETCH INTO :MAX_DATA_ESTOQUE_INICIAL;
            CATCH
                IF $rc <> 100 THEN STOP ($rc, 'unexpected error em MAXDATAEINI');
            TRY
                IF MAX_DATA_ESTOQUE_INICIAL IS NULL THEN BEGIN
                    SET MAX_DATA_ESTOQUE_INICIAL = '1900-01-01 00:00:00.000';
                    SET QTDE_ESTOQUE_INICIAL = 0;
                END ELSE BEGIN
                    SELECT QTDE QTDE_ESTOQUE_INICIAL
                       FROM VENDOR_CONCES.ESTOQUEINICIAL
                       WHERE MY_EMPRESA = :OID_EMPRESA AND
                           MY_PRODUTO = :OID_PRODUTO_DEF AND
                           DATA BETWEEN :MAX_DATA_ESTOQUE_INICIAL AND :DTA_ESTOQUE;
                    FETCH INTO :QTDE_ESTOQUE_INICIAL;
                END;
            CATCH
                IF $rc <> 100 THEN STOP ($rc, 'unexpected error em Carregamento do Estoque Inicial');
            TRY
                SELECT SUM(QTDE) QTDE_SAIDA
                   FROM VENDOR_CONCES.MVIEW_MOVPRODUTOS mviewS
                   WHERE mviewS.MY_EMPRESA = :OID_EMPRESA AND
                         mviewS.MY_PRODUTO_DEF = :OID_PRODUTO_DEF AND
                         mviewS.GERA_ESTOQUE = 'S' AND
                         mviewS.TIPO = 'S' AND
                         mviewS.DATA BETWEEN :MAX_DATA_ESTOQUE_INICIAL AND :DTA_ESTOQUE AND
                         EXISTS(SELECT oid FROM VENDOR_CONCES.MVIEW_MOVPRODUTOS mviewE WHERE 
                            mviewE.my_Empresa = mviewS.my_Empresa AND
                            mviewE.tipo = 'E' AND
                            mviewE.data <= mviewS.data AND
                            mviewE.my_Produto = mviewS.my_Produto AND
                            mviewE.gera_Estoque = 'S' AND
                            mviewE.gera_Financeiro != 'N'
                FETCH INTO :QTDE_SAIDA;
            CATCH
                IF $rc <> 100 THEN STOP ($rc, 'unexpected error ao contar Saidas');
            TRY
                IF QTDE_SAIDA IS NULL THEN
                    SET QTDE_SAIDA = 0;
            CATCH
                IF $rc <> 100 THEN STOP ($rc, 'unexpected error ao zerar saida');
            TRY
                SELECT SUM(QTDE) QTDE_ENTRADA
                   FROM VENDOR_CONCES.MVIEW_MOVPRODUTOS
                   WHERE MY_EMPRESA = :OID_EMPRESA AND
                       MY_PRODUTO_DEF = :OID_PRODUTO_DEF AND
                       GERA_ESTOQUE = 'S' AND
                       TIPO = 'E' AND
                       DATA BETWEEN :MAX_DATA_ESTOQUE_INICIAL AND :DTA_ESTOQUE;
                FETCH INTO :QTDE_ENTRADA;
            CATCH
                IF $rc <> 100 THEN STOP ($rc, 'unexpected error ao contar entradas');
            TRY
                IF QTDE_ENTRADA IS NULL THEN
                    SET QTDE_ENTRADA = 0;
            CATCH
                IF $rc <> 100 THEN STOP ($rc, 'unexpected error ao zera entrada');
            TRY
                SET ESTOQUE_ATUAL = CHR(QTDE_ESTOQUE_INICIAL + QTDE_ENTRADA - QTDE_SAIDA);
            CATCH
                IF $rc <> 100 THEN STOP ($rc, 'unexpected error');
        END;
    about the error, I discovered the line using database studio, as I droped the old procedure and tried to recreate, database studio says that error is at BETWEEN expression, but you find the right problem with select * in exists.
    best regards
    Clóvis

  • How run stored procedure in Crystal report?

    I have table from query in report, but first I need to run stored procedure in report.
    How I need to do it?

    previous post not correct
      this is correct
    When I need to run my report
    1) I need to run storeed procedure ( the stored procedure will update some tables)
    I just used Add Command and added stored procedure in Database Fields, but I think the procedure doesn't work in report. Maybe I need add new commant and write there:
    exec ProcedureName par1 par2
    or
    exec ProcedureName (par1={?parameter1} par2={?parameter2})
    It's doesn't work. What I need to do?
    2) I use some query in report
    ex.
    select t1.col1, t2.col2, t6.col3 t1.col7 t4.col1
    from t1, t2, t6, t4, r4, ju, hh
    where hh.col11={?parameter1}
    and ju.col3=6
    and r4.col3={?parameter2}
    group by .....
    order by ......
    How I need to create me report? What I need to do first?
    If parameter in stored procedure par1={?parameter1} in query
    and par2={?parameter2}

  • How to create a stored procedure that contains all 3 AFTER Triggers Update/Insert/Delete ?

    Hi guys, I'm trying to create a Stored procedure that will automatically add all 3 After triggers when executed on any given database, can someone please explain and give an example on how do I go about doing this ? I'd also like it to raise any errors
    that may come across, thanks in advance.

    Lets start with the question why do you need the triggers at all. Since SQL Server 2005 we can use an OUTPUT clause.
    This code can be re-written in SQL Server 2005 using the OUTPUT clause like below:
    create table itest ( i int identity not null primary key, j int not null unique )
    create table #new ( i int not null, j int not null)
    insert into itest (j)
    output inserted.i, inserted.j into #new
    select o.object_id from sys.objects as o
    select * from #new
    drop table #new, itest;
    go
    Now from this example, you can see the integration of OUTPUT clause with existing DML syntax.
    Another common scenario is auditing of data in a table using triggers. In this case, the trigger uses information from the inserted and updated tables to add rows into the audit tables. The example below shows code that uses OUTPUT clause in UPDATE and DELETE
    statements to insert rows into an audit table.
    create table t ( i int not null );
    create table t_audit ( old_i int not null, new_i int null );
    insert into t (i) values( 1 );
    insert into t (i) values( 2 );
    update t
       set i  = i + 1
    output deleted.i, inserted.i into t_audit
     where i = 1;
    delete from t
    output deleted.i, NULL into t_audit
     where i = 2;
    select * from t;
    select * from t_audit;
    drop table t, t_audit;
    go
    Best Regards,Uri Dimant SQL Server MVP,
    http://sqlblog.com/blogs/uri_dimant/
    MS SQL optimization: MS SQL Development and Optimization
    MS SQL Consulting:
    Large scale of database and data cleansing
    Remote DBA Services:
    Improves MS SQL Database Performance
    SQL Server Integration Services:
    Business Intelligence

  • Inserting to a clob field using cx_Oracle via a stored procedure

    Hello,
    Does anyone have experience using cx_Oracle to call a stored procedure which inserts to a clob field? I have found examples of doing this via straight SQL but I was hoping it was possible to do this via a stored procedure call. Thanks for any help you can provide.
    Jason

    And cursor.callproc('insert_clob_proc', (clob,))
    doesn't work for you?
    PrzemekYes - I should have been more clear in my original post. The callproc function works until we have a value which is over 32K. At values over 32K, we get an error message "ORA-01460: unimplemented or unreasonable conversion requested". I believe this is because we are sending the value as a string and so we would need to figure out how to send as a CLOB in cx_Oracle? Here is some code to use to test if interested...
    Oracle (Oracle Database 10g Release 10.1.0.4.0 - Production):
    CREATE TABLE clob_test (CLOB_FIELD CLOB);
    CREATE OR REPLACE PROCEDURE ins_clob_test (v_clob_field IN CLOB)
    AS
    BEGIN
    INSERT INTO clob_test (clob_field) VALUES (v_clob_field);
    END ins_clob_test;
    Python (2.5):
    conn = cx_Oracle.connect(xhash['oraclelogin'])
    cursor = conn.cursor()
    clob_var = 'Some test data' * 10000
    cursor.callproc('ins_clob_test',(clob_var,))
    conn.commit()
    cursor.close()
    conn.close()
    I should also mention that I am the Oracle developer and not the Python programmer - my knowledge of Python is very limited. I would like the Python programmers to use the procedures (packages) I have created to do their inserts but this situation has caused them to put the SQL directly in their code.
    Thanks again for any assistance you can provide.
    Jason

Maybe you are looking for