Stored Procedure to delete a number of tables with a common name attribute

Hi All,
This is my first post so I hope I have posted to the required level with sufficient information. This is my first stored procedure (SP) and is for Oracle 10.
I am trying to write a script to delete 11 tables and some rows from another 3 tables, all of which are named with a number that I would like to input at the point of creation of the SP. Below is the script I have written and edited. My original has been lost by crashing servers!
When I run the script it gives me the following output:
"Warning: execution complete with warning
procedure ScenarioDelete compiled"
The SP hasn't deleted any of the tables and I'm not sure if it's because my script is poor or because of something else. Any help is greatly appreciated!!
-- table delete SP
-- Run begin ScenarioDelete ('x'); with x as the ScenarioId
create or replace procedure ScenarioDelete (ScenarioNo IN varchar2);
countstable := 'C_' || ScenarioNo;
changetable := 'CG_' || ScenarioNo;
countsinfotable := 'CI_' || ScenarioNo;
datatable1 := 'D_0_' || ScenarioNo;
datatable2 := 'D_1_' || ScenarioNo;
datatable3 := 'D_2_' || ScenarioNo;
hietable1 := 'HI_0_' || ScenarioNo;
hietable2 := 'HI_1_' || ScenarioNo;
hietable3 := 'HI_2_' || ScenarioNo;
hielinktable1 := 'HL_1_' || ScenarioNo;
hielinktable2 := 'HL_2_' || ScenarioNo;
AS
execute immediate 'drop table ' || countstable;
execute immediate 'drop table ' || changetable;
execute immediate 'drop table ' || countsinfotable;
execute immediate 'drop table ' || datatable1;
execute immediate 'drop table ' || datatable2;
execute immediate 'drop table ' || datatable3;
execute immediate 'drop table ' || hietable1;
execute immediate 'drop table ' || hietable2;
execute immediate 'drop table ' || hietable3;
execute immediate 'drop table ' || hielinktable1;
execute immediate 'drop table ' || hielinktable2;
execute immediate 'delete from USERACESS where SCENARIOID = ' || ScenarioNo;
execute immediate 'delete from SCENARIO where SCENARIOID = ' || ScenarioNo;
execute immediate 'delete from SCENARIOINFO where SCENARIOID = ' || ScenarioNo;
-- or --
execute immediate 'delete from USERACESS where SCENARIOID = '' || ScenarioNo || ''';
execute immediate 'delete from SCENARIO where SCENARIOID = '' || ScenarioNo || ''';
execute immediate 'delete from SCENARIOINFO where SCENARIOID = '' || ScenarioNo || ''';
END;

Hi,
Welcome to the forum!
When you compile a stored procedure, you get only the vaguest of error messages by default.
Always say SHOW ERRORS immediately after compiling, to get more detailed error messages. (And, of course, post the complete error message, including line number, when you need help.)
Remember to specify a datatype (and, in the case of VARCHAR2 variables, a maximum length) for all local variables you declare:
create or replace procedure ScenarioDelete (ScenarioNo IN varchar2)     -- no semicolon here
AS  -- AS or IS (it doesn't matter which) required here
    countstable  VARCHAR2 (50) := 'C_'  || ScenarioNo;
    changetable  VARCHAR2 (50) := 'CG_' || ScenarioNo;
...You're not actually wasting any space if you decalre the variable as 50 characters, but only use 3.
It really helps if you format code, so that, for example,
all the local variables are indented before the word BEGIN
everything between BEGIN and its corresponding END is indented
everything between IF and its corresponding END IF is indented,
and so on.
You're probably already doing that, but it doesn't show up on this site unless you type these 6 characters
(small letters only, inside curly brackets) before and after the formatted text.
That's what I did for the code fragement above.
Edited by: Frank Kulash on Mar 23, 2009 12:04 PM
Formatting stuff added.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

Similar Messages

  • JDBC Receiver, Stored Procedure that Deletes

    Hi,
    I have a stored procedure that deletes fields in a table based on a lot of different criteria.
    I can't use DELETE or SQL_QUERY ie Statement3 and 6 in http://help.sap.com/saphelp_nw04s/helpdata/en/2e/96fd3f2d14e869e10000000a155106/frameset.htm . I can only use this Stored Procedure.
    This is my message type.
    <MT_HEADER>
        <Statement>
             <ClearTable>
                 <action>.......attribute...set to EXECUTE
                  <table> .......maps to Stored Procedure
                  <isInput>  ......attribute... set to TRUE
                  <type>   ........attribute...set to STRING
    However, I'm getting this error
    ERROR: Invalid XML document format for stored procedure: 'type="<SQL-type>"' attribute is missing for element 'table' (Setting a SQL-type (e.g. INTEGER, CHAR, DATE etc.) is mandatory !)
    Any ideas?

    Damien,
    If you look in the link you have procided, the datatype for Stored Procedure every element needs to have a TYPE attribute asscoiated with it and you need to give the corresponding Datatype of that element,
    <i>The attribute type=<SQL-Datatype> , which describes the valid SQL data type, is mandatory for all parameter types (IN, OUT, INOUT).
    The following SQL data types are supported:
    INTEGER, BIT, TINYINT, SMALLINT, BIGINT, FLOAT, REAL, DOUBLE, NUMERIC, DECIMAL, CHAR, VARCHAR, STRING, LONGVARCHAR, DATE, TIME, TIMESTAMP, BINARY, VARBINARY, LONGVARBINARY, BLOB (input and output),CLOB (input and output), CURSOR (output; only in conjunction with the Oracle JDBC driver).
    </i>
    Regards
    Bhavesh

  • Calling Managed CLR Stored Procedure from C++ SQL Server 2008 fails with Msg 2809

    I am trying to call a stored procedure from C++ (VS 2010).
    Here is what the stored procedure looks like:
    public class Validate
    [Microsoft.SqlServer.Server.SqlProcedure(Name = "ClientTest")]
    public static void ClientTest(out String res )
    { res = "50";}
    To create a stored procedure I deploy at first the assembly
    USE [test]
    GO
    CREATE ASSEMBLY ClientTestAssembly
    AUTHORIZATION testLogin
    FROM 'C:\Users\test\Documents\Visual Studio 2010\Projects\TestCreationAssemblyCSharp\TestCreationAssemblyCSharp\bin\x64\Debug\TestCreationAssemblyCSharp.dll'
    and call 
    USE test
    GO
    CREATE PROCEDURE ClientTest (@res NVARCHAR(40) OUTPUT)
    AS
    EXTERNAL NAME ClientTestAssembly.Validate.ClientTest
    I can call my procedure direct in SQL Server Management Studio without any errors
    declare @res nvarchar(10)
    execute ClientTest @res OUTPUT
    print @res
    But when I try to call this procedure from C++ using CALL syntax
    SQLBindParameter(sqlstatementhandle, 1, SQL_PARAM_OUTPUT, SQL_C_CHAR,
    SQL_VARCHAR , 40, 0, version, sizeof(version) ,
    &pcbValue);
    res = SQLExecDirect(sqlstatementhandle, (SQLCHAR*)("{CALL ClientTest(?) }"), SQL_NTS);
    I get the Error 2809 with SQLSTATE 42000 and with statement 
    The request for 'ClientTest'
    (procedure) failed because 'ClientTest' is a procedure object.
    However, if I wrap my CLR stored procedure into a T-SQL stored procedure, like
    CREATE PROCEDURE myProc (@res NVARCHAR(40) OUTPUT)
    AS
    EXEC ClientTest @res OUTPUT
    and call then myProc instead of ClientTest
    res = SQLExecDirect(sqlstatementhandle, (SQLCHAR*)("{CALL myProc(?) }"), SQL_NTS);
    everithing works fine and I get 50 as result.
    I have no ideas what is the reason for that behavior.
    Thanks very much for any suggestion. 
    Christina

    I'm not an ODBC expert, but you might try following the sample here:
    Process Return Codes and Output Parameters (ODBC)
    To see if it also behaves differently for your CLR proc.
    David
    David http://blogs.msdn.com/b/dbrowne/

  • Deleted cell number appears (along with the edited number) when sending a text.  How do I get rid of it?

    Deleted cell number appears (along with the edited number) when sending a text.  How do I get rid of it?

    It has nothing to do with iOS 6. It's always been that way. Given that it's been this way for so long, one assumes that Apple knows about it and has their own reasons for not changing it.
    Restore the phone as new, not from back up to delete the numbers. Or, wait until the cache gets overwritten.
    Best of luck.

  • How can I check if there is a table with the given name ?

    I'm using 8i and 9i.
    Could anybody teach me how to check if there is a table with a certain name in SQLPLUS without using SELECT
    statement ?
    I want to use the following logical procedure.
    if exists "table_to_be_deleted" then drop table "table_to_be_deleted"
    Or, is there any system table that I can check the names of tables like
    count = select "table_to_be_deleted" from "an_oracle_system_table"
    if ( count != 0 ) then drop table "table_to_be_deleted"
    Thanks,
    John

    Just create it, but be aware that DDLs can't be executed directly from Pl/Sql, so you'll have to use dynamic Sql, e.g. :
    SQL> create table test(a number);
    Table created.
    SQL> begin
      2  drop table test;
      3  exception
      4  when others then
      5  null;
      6  end;
    SQL> /
    drop table test;
    ERROR at line 2:
    ORA-06550: line 2, column 1:
    PLS-00103: Encountered the symbol "DROP" when expecting one of the following:
    begin case declare exit for goto if loop mod null pragma
    raise return select update while with <an identifier>
    <a double-quoted delimited-identifier> <a bind variable> <<
    close current delete fetch lock insert open rollback
    savepoint set sql execute commit forall merge pipe
    SQL> ed
    Wrote file afiedt.buf
      1  begin
      2  execute immediate 'drop table test';
      3  exception
      4  when others then
      5  null;
      6* end;
    SQL> /
    PL/SQL procedure successfully completed.
    SQL>Now the table does not exist anymore, but further executions will not generate errors, due to the exception handler :
    SQL> desc test
    ERROR:
    ORA-04043: object test does not exist
    SQL> /
    PL/SQL procedure successfully completed.
    SQL>

  • Finding a table with a like %name% in a schema

    What is the query I should use to find a table with a like %name% in a schema?
    Thank you for any help

    select * from all_tables
    where owner = 'YOUR_SCHEMA' and lower(table_name) like '%name%'
    /Regards
    Dmytro

  • Is it possible to have 2 tables with the same name in an Orable database?

    Hello,
    I'm a complete Oracle newbie so please excuse my question if it's stupid.
    I was trying to create 2 tables with the same name using different tablespaces but it does not seem to work. Like this (second time just change the name of the tablespace):
    CREATE TABLE test_tbl (
      id INTEGER,
      status VARCHAR2(10),
      last_modified DATE DEFAULT SYSDATE
    TABLESPACE tblspc1Is it in general in Oracle possible to acquire this goal?
    Thanks a lot!
    P.S. I have already created the needed tablespaces
    CREATE TABLESPACE tblspc1 DATAFILE 'tblspc1.dbf' SIZE 10MEdited by: 808239 on 02-Mar-2011 02:18

    It is not possible to create two tables with same name in same schema.
    A user can own one schema with his own name and another with the schema name SYS.
    For this you have to grant sysdba privilage to the user and then have to connect using sys password or with the password specified in password file.
    But this still you have to access to the table in sys schema using sys.table_name.
    Hope Answered tthe Question.

  • Reference all tables with the same name

    If I have multiple worksheets that each have an identically structured table "Test", is it possible to create a formula in a cell of another worksheet that references the same range of cells in every table "Test"? So far I haven't found a way to reference cells in a table with an ambiguous name without having to prepend the worksheet name to the reference like so: 'Worksheet 1' :: Test :: B3:C4. What I want to be able to do is say Test :: B3:C4 and have the formula reference B3:C4 in all "Test" tables.
    Thanks!

    You've picked the correct descriptive term. Such a reference would indeed be "ambiguous".
    You might be able to reference a set of disconnected ranges of cells, but each range would have to be explicitly described.
    You might be able to collect the values in the cells into a single array in a single table, then reference that array in your formula.
    Regards,
    Barry
    PS: "Sheets" in Numbers have little in common with "Worksheets" in MS Excel. Using the Numbers vocabulary can help keep the distinction more clear, and avoid unwarranted expectations.
    B.

  • Many to many join table with different column names

    Hi have a joint table with different column names as foreign keys in the joining
    tables...
    e.g. i have a many to many reltnshp btwn Table A and Table B ..and join table
    C
    both have a column called pk.
    and the join table C has columns call fk1 and fk2
    does cmd require the same column name in the join table as in the joining table?
    are there any workarounds?
    thanks

    HI,
    No, the foreign key column names in the join table do not have to match the primary
    key names in the joined tables.
    -thorick

  • Stored procedure to delete information within number of days?

    Hello everyone,
    I am struggling with creating a stored procedure which will allow me to delete old data from specific tables within a specific date range. Ideally what I would like to do is to create a stored procedure where I can specify the delete from let's say 6 different tables and an adhoc number of days. I am new to this and any help is greatly appreciated.
    Regards,

    No version number.
    No information on the number of tables.
    No DDL.
    No information on the delete criteria.
    No information of the number of rows in each table.
    No information on the number or percentage of rows being deleted.
    No information on indexes.
    No information on foreign key constraints.
    No information on replication, if any.
    No information on triggers, if any.
    No information on partitioning.
    Please provide sufficient information from which a good answer can be formulated. In short, address each of the items listed above.

  • Stored procedure to delete a row from a table

    I have forgotten how to do this and cant find my college notes so here goes...
    How do you create a stored prcedure to delete a row of data from a table, I want to pass in three parameters to identify the unique row. Any help would be great

    Since you use the work hyperlink, I'm assuming that you are developing some sort of web-based front end. If you are having flow control issues, you probably want to address your question to a forum that specializes in your particular front-end language/ environment/ framework. A JSP app using Struts, an ASP.Net app using C#, and a PHP app will all have rather different approaches to state control and page flow.
    Justin
    Distributed Database Consulting, Inc.
    http://www.ddbcinc.com/askDDBC

  • Stored procedure as a column in a table

    Is it possible to have a column defined as a stored procedure in a table?
    I was told that this could be done and that other columns on that row could be used in the stored procedure and you would query the data just as you would for any other column (i.e. select storProcColumn from table).
    The reason I am asking is that the column that I want as a stored procedure needs to be calculated every time that column is asked for as it is a calculation from many pieces of data.
    The plan is to make a Java stored procedure that will do the calculation, define a column that points to a Java stored procedure, which will do the calculation using data from the row it is in along with other data from other tables.
    I am familiar with Java stored procedures but don't know if it is possible to have a column point to it.
    Can someone please point me to some documentation?
    Thanks,
    Dennis

    I don't think that you can do exactly what you are expecting, but close. However, without knowing all of your requirements, I don't know if there might be a better way. You will need to use some form of dynamic SQL and it can get complicated and you will need to use functions rather than procedures if you expect to use them in a select statement. I have provided a demonstration below, in which I have created a table with the names of stored functions in one column and the values of parameters to be passed to the functions in the other column. After creating a bunch of java (using examples from the documentation) and some pl/sql, I have ultimately been able to perform a select from your table as you have requested, using just one function. The resulting data contains row counts of tables from one function, where the table name came from the other column in the row and a character string from another function, where the other column is null. I have used if ... end if to allow for the different parameters. Hopefully all of this will either help show you how to do it or help you decide that this is not the way to go and you need to come up with a simpler design for your system.
    scott@ORA92> -- tables and data for testing:
    scott@ORA92> CREATE TABLE test_tab
      2    (col1      VARCHAR2(10),
      3       func_col VARCHAR2(10))
      4  /
    Table created.
    scott@ORA92> INSERT INTO test_tab (col1, func_col)
      2  VALUES ('dept', 'row_count')
      3  /
    1 row created.
    scott@ORA92> INSERT INTO test_tab (col1, func_col)
      2  VALUES ('emp', 'row_count')
      3  /
    1 row created.
    scott@ORA92> INSERT INTO test_tab (col1, func_col)
      2  VALUES (NULL, 'HelloWorld')
      3  /
    1 row created.
    scott@ORA92> SELECT * FROM test_tab
      2  /
    COL1       FUNC_COL
    dept       row_count
    emp        row_count
               HelloWorld
    scott@ORA92> SELECT COUNT (*) FROM dept
      2  /
      COUNT(*)
             4
    scott@ORA92> SELECT COUNT (*) FROM emp
      2  /
      COUNT(*)
            14
    scott@ORA92> --
    scott@ORA92> --
    scott@ORA92> -- java and functions to perform calculations
    scott@ORA92> -- based on other columns in row and other tables:
    scott@ORA92> --
    scott@ORA92> -- to count rows in a table:
    scott@ORA92> create or replace and compile java source named "RowCounter" as
      2  import java.sql.*;
      3  import java.io.*;
      4  import oracle.jdbc.*;
      5 
      6  public class RowCounter {
      7    public static int rowCount (String tabName) throws SQLException {
      8        Connection conn =
      9          DriverManager.getConnection("jdbc:default:connection:");
    10        String sql = "SELECT COUNT(*) FROM " + tabName;
    11        int rows = 0;
    12        try {
    13          Statement stmt = conn.createStatement();
    14          ResultSet rset = stmt.executeQuery(sql);
    15          while (rset.next()) {rows = rset.getInt(1);}
    16          rset.close();
    17          stmt.close();
    18        } catch (SQLException e) {System.err.println(e.getMessage());}
    19        return rows;
    20    }
    21  }
    22  /
    Java created.
    scott@ORA92> CREATE OR REPLACE FUNCTION row_count (tab_name VARCHAR2) RETURN NUMBER
      2  AS LANGUAGE JAVA
      3  NAME 'RowCounter.rowCount(java.lang.String) return int';
      4  /
    Function created.
    scott@ORA92> --
    scott@ORA92> -- to return specific string:
    scott@ORA92> create or replace and compile java source named "Hello" as
      2  public class Hello
      3  {
      4       public static String world ()
      5       {
      6          return "Hello world";
      7       }
      8  }
      9  /
    Java created.
    scott@ORA92> create or replace function HELLOWORLD return VARCHAR2 as
      2  language java name 'Hello.world () return java.lang.String';
      3  /
    Function created.
    scott@ORA92> --
    scott@ORA92> --
    scott@ORA92> -- function to calculate and return result using column values
    scott@ORA92> -- containing function and table names as parameters
    scott@ORA92> -- for dynamic execution:
    scott@ORA92> CREATE OR REPLACE FUNCTION get_value
      2    (p_func IN VARCHAR2,
      3       p_col  IN VARCHAR2)
      4    RETURN       VARCHAR2
      5  AS
      6    v_result   VARCHAR2(20);
      7  BEGIN
      8    IF p_col IS NULL THEN
      9        EXECUTE IMMEDIATE
    10          'SELECT ' || p_func || '() FROM DUAL'
    11          INTO v_result;
    12    ELSE
    13        EXECUTE IMMEDIATE
    14          'SELECT ' || p_func || '(''' || p_col || ''') FROM DUAL'
    15          INTO v_result;
    16    END IF;
    17    RETURN v_result;
    18  END get_value;
    19  /
    Function created.
    scott@ORA92> SHOW ERRORS
    No errors.
    scott@ORA92> --
    scott@ORA92> --
    scott@ORA92> -- select statement that selects rows from your table
    scott@ORA92> -- and uses the get_value function to pass the column values
    scott@ORA92> -- for dynamic execution and return the results:
    scott@ORA92> COLUMN result FORMAT A20
    scott@ORA92> SELECT col1, func_col, get_value (func_col, col1) AS result
      2  FROM   test_tab
      3  /
    COL1       FUNC_COL   RESULT
    dept       row_count  4
    emp        row_count  14
               HelloWorld Hello world
    scott@ORA92>

  • Creating stored procedure to import csv data into tables

    I am trying to create a stored procedure to import data from a csv file into a table. I tried using sqlldr but could not run it at school due to access permissions that they will not change. So I looked at the utl_package and from what I can see it requires a "virtual" directory, which conflicts with the access permissions again at school. So can I create a stored procedure that will just read data from a csv file into a table without the need to write or create a file/directory.
    Thankyou

    Satyaki_De wrote:
    Since, you are talking about so much restriction - i don't think you will get that.
    One alternative solution can be -> write a java based pl/sql procedure and try load that by parsing it. But, for that you need execute privileges on dbms_java package.
    Do you have that? I doubt.
    Regards.
    Satyaki De.Nope not allowed to use java, and im new to oracle. Why can't a stored procedure in pl/sql just read a file and put the data into a table I create prior?

  • Deleting rows in a table with a button

    Good Day All;
    I seemed to have run into a snag with trying to add a delete button in a table that will delete a row. Let me expain.
    The form has 1 table that has 7 cells made up of text fields and drop downs. This table is in its own subform.
    There is a button to add rows as the user requires. The code I am using to add rows: psl_list_subform.instanceManager.addInstance(1);
    I have been asked to add a delete button so a user can delete rows. I have added this to the end of the table. SO each time a row gets repeated, there is a delete button. The code I am “trying” to use is;
    Table4.Row1.instanceManager.removeInstance(this.parent.index);
    When I click on the button to delete, nothing happens. I brought up the JavaScript debugger, there are no errors.
    Any ideas what I missed.
    Thanks All
    Chomp

    Hi,
    from my understanding of your form, you adding new instances of the subform "psl_list_subform" which contains a single table row.
    The hierarchy that will look like "psl_list_subform.Table4.Row1.RemoveButton".
    To remove an instance of the subform, from a button within the table row the script needs to refer to the 3rd parent of the remove button.
    this.parent.parent.parent.instanceManager.removeInstance(this.parent.parent.parent.index);
    Explaination: this = RemoveButton, 1st parent = Row1, 2nd parent = Table4, 3rd parent = psl_list_subform

  • WCF-SQL table operation on tables with the same name.

    Hello,
    My situation involves generating table operation schemas (Insert, Update, Delete, Select) for tables in two different SQL databases.  These tables happen to have the same name.  For the sake of discussion lets call the tables dbo.Customer.  However,
    these tables have different fields in them.  When generating the schemas to be used by BizTalk, they end up as the same message type like so:
    Database1: http://schemas.microsoft.com/Sql/2008/05/TableOp/dbo/Customer#Update
    Database2: http://schemas.microsoft.com/Sql/2008/05/TableOp/dbo/Customer#Update
    To my understanding, I can't simply change the namespaces or root nodes to be unique since this structure is expected by the SQL Adapter (shown here: https://msdn.microsoft.com/en-us/library/dd788023.aspx).  I had a couple thoughts on a solution: 
    Use schema versions to differentiate between the two different table schemas.
    Use a unique namespace and root node for the schemas.  Then, create a custom pipeline component to modify them to the standard as it is sent to SQL server.
    Modify the schema so support both tables with all columns in both tables.
    I don't really like any of these solutions, so I am hoping somebody in the community has run into this situation before and has something better.
    -Richard

    You don't really have to do anything other than make sure the particular message gets routed always to the correct database.
    Having duplicate MessageType's is only a problem if you're relying on the automatic resolution of the XmlDisassembler and that would only be a concern on the Response side.
    To get around that, just create a custom Pipeline with the XmlDisassembler and set the Document Schemas list to only the one for that Port.

Maybe you are looking for