Oracle function in stored procedure to retreive particular table name

Hi,
I need to delete a table 'xxsys_dram_flatproperties' from database given model name as 'dram-model'.
the model name can be any thing.corresponding table name will be[i] 'xxsys_<modelname>_flatproperties'.
I wrote stored procedure .I am able to retrieve all the tables in the database using user_tables.Is there any funtion in oracle like
if table name contains letters that are there in model name.
Pleasehelp.

Suppose all your tables created in the schema 'temp'
and you are absolutly sure you want to drop only tables which have for example '_model3_' in its name (nothing else should have same part in your schema)
then try a simple solution:
CREATE TABLE temp.xx_model3_01 (col1 NUMBER)
CREATE TABLE temp.xx_model3_02 (col1 NUMBER)
SELECT table_name from all_tables where OWNER = 'TEMP' and table_name LIKE '%_MODEL3_%'
TABLE_NAME                   
XX_MODEL3_01                 
XX_MODEL3_02
DECLARE
   CURSOR c1
   IS
      (SELECT table_name
         FROM all_tables
        WHERE owner = 'TEMP' AND table_name LIKE '%_MODEL3_%');
BEGIN
   FOR rec IN c1
   LOOP
      EXECUTE IMMEDIATE 'DROP TABLE ' || rec.table_name;
   END LOOP;
END;

Similar Messages

  • Call Oracle function from Stored Procedure

    Hi,
    I have function Which returning one number. I want to use that number in a procedure. How to call the Oracle Function from the Procedure
    Create procedure
    AS
    Begin
    Check number;
    Select Function1 into check from dual;
    It is giving error.
    Can anyone provide me example for this.
    Thanks in advance

    Put the Check Number; before begin
    SQL> create or replace procedure abc as
      2 begin
    3 val number;
      4  select abcd into val from dual;
      5  dbms_output.put_line(val);
      6  end;
      7  /
    Warning: Procedure created with compilation errors.
    Elapsed: 00:00:00.00
    SQL> show error
    Errors for PROCEDURE ABC:
    LINE/COL ERROR
    3/5      PLS-00103: Encountered the symbol "NUMBER" when expecting one of
             the following:
             := . ( @ % ;
             The symbol ":=" was substituted for "NUMBER" to continue.
    SQL> create or replace procedure abc as
      2 val number;
    3 begin
      4  select abcd into val from dual;
      5  dbms_output.put_line(val);
      6  end;
      7  /
    Procedure created.
    Elapsed: 00:00:00.00
    SQL> exec abc;
    100.22
    PL/SQL procedure successfully completed.
    Elapsed: 00:00:00.00
    SQL>

  • Function in stored procedure

    Hello,
    I'm using RPAD function in stored  procedure 4 times in one query and then inserting to another table. from dm_exec_sql_text table I see that every time that procedure approach to Rpad function it's open and closing in the and so it's open and closing
    function 4 times per one row, If I have 1000 rows to insert the function will open and close 4000 times and it's very slow.
    My question if there is some way to change this functionality of open / close function every time ?
    Thank You
    Daniel

    Yes, avoid using UDF  , means especially a scalar udf... See how you can re-write a scalar udf  as table valued udf.
    http://sqlblog.com/blogs/alexander_kuznetsov/archive/2008/05/23/reuse-your-code-with-cross-apply.aspx
    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

  • Does Oracle have Extended Stored Procedure like SQL Server and Sybase?

    Hi, i am new to Oracle. I want to know if...
    Does Oracle have Extended Stored Procedure like SQL Server and Sybase?
    If it does not have, then how can i call outside program written in C or JAVA from the Database stored procedure or trigger?

    refer to this link on external procedures
    http://download-west.oracle.com/docs/cd/A87860_01/doc/server.817/a76956/manproc.htm#11064

  • Trouble referencing return values of a Function in Stored Procedure

    Hello all,
    I have the following Function and Stored Procedure (simplified for this post). The error I am getting is in the SELECT, WHERE clause of the UPDATE command. My function is returning a sys_refcursor and I am trying to reference column names but keep getting the error
    ORA-00904: "PUBLISHEDDOCVERSIONID": invalid identifier
    What am I doing wrong?
    Function
    CREATE OR REPLACE FUNCTION &HKDB_Schema_Name..QueryKnowdeDocVersion(aKGID int)
    RETURN sys_refcursor
    IS
    aCur sys_refcursor;
    BEGIN
    OPEN aCur FOR
    SELECT pkd.KnowdeID as "PublishedKnowdeID", pkd.DocumentID as "PublishedDocID", pkd.VersionID as "PublishedDocVersionID"
    FROM KnowdeDocument pkd
    WHERE pkd.KGID = aKGID;
    RETURN aCur;
    END;Stored Procedure
    UPDATE KnowdeDocument
    SET DocumentID = (SELECT PublishedDocID FROM (SELECT QueryKnowdeDocVersion(aKGID, aPublishedKGID, aTextVersionID) FROM DUAL)
                      WHERE PublishedKnowdeID = KnowdeDocument.KnowdeID
                      AND PublishedDocID = KnowdeDocument.DocumentID
                      AND ((PublishedDocVersionID is NULL and KnowdeDocument.VersionID is NULL) OR (PublishedDocVersionID is not NULL AND
                               PublishedDocVersionID = KnowdeDocument.VersionID)))Regards,
    Toby

    Hi redeye,
    Your select is from:
    (select queryknowdedocversion(akgid
                                  ,apublishedkgid
                                  ,atextversionid)
                         from dual)This has no publisheddocversionid. Unfortunately I cannot figure out what you are trying to do with that ref_cursor.
    Edit:
    Or perhaps publisheddocversionid is a column in KnowdeDocument? Could this be case sensitive as well? (Bad idea to use quotations when naming things)
    Regards
    Peter
    Edited by: Peter on Aug 24, 2009 3:39 AM

  • Create a View, function or stored procedure for query?

    Hi All,
    I like to know how I can create a view or function for the query below. If its going to be a function or stored procedure will I be able to union it with another view?
    DECLARE
    @BegDate DATE,
    @EndDate DATE
    SELECT
    @BegDate = MIN(vl.VoidStartDate),
    @EndDate = MAX(vl.LetDate)
    FROM #VoidLoss vl
    ;WITH d(d) AS (
    SELECT TOP (DATEDIFF(dd, @BegDate, @EndDate))
    DATEADD(dd, ROW_NUMBER() OVER (ORDER BY (SELECT NULL)) -1, @BegDate)
    FROM sys.all_objects o
    ), cal AS (
    SELECT
    d.d,
    MONTH(d.d) AS m,
    YEAR(d.d) AS y
    FROM d
    SELECT
    vl.History_IND,
    vl.PropCode,
    vl.VoidCategory,
    vl.ControlGroup,
    CASE WHEN vl.VoidStartDate < MIN(cal.d) THEN MIN(cal.d) ELSE vl.VoidStartDate END AS VoidStartDate,
    CASE WHEN vl.LetDate > MAX(cal.d) THEN MAX(cal.d) ELSE vl.LetDate END AS LetDate,
    vl.MarketRent,
    DATENAME(mm, CAST('1900-' + CAST(cal.m AS VARCHAR(2)) + '-1' AS DATE)) AS [Month],
    cal.y AS [Year],
    COUNT(*) AS DaysVoid,
    COUNT(*) * vl.MarketRent AS VoidLoss
    FROM
    #VoidLoss vl
    JOIN cal
    ON cal.d BETWEEN DATEADD(dd, 1, vl.VoidStartDate) AND vl.LetDate
    GROUP BY
    vl.History_IND,
    vl.PropCode,
    vl.VoidCategory,
    vl.ControlGroup,
    vl.VoidStartDate,
    vl.LetDate,
    vl.MarketRent,
    cal.m,
    cal.y
    ORDER BY
    vl.History_IND,
    vl.PropCode,
    vl.VoidStartDate
    Thanks

    A view or an inline-function is a single query, so this part does not fit in:
    DECLARE
    @BegDate DATE,
    @EndDate DATE
    SELECT
    @BegDate = MIN(vl.VoidStartDate),
    @EndDate = MAX(vl.LetDate)
    FROM #VoidLoss vl
    And you cannot have it multi-statement function either, since you cannot refer to temp tables in such a function. In any case, using a multi-statement function in a view definition or nest it in another function definition is likely to be a performance disaster.
    The sole alternative that remains as long as you have the temp table is a stored procedure. You cannot use a stored procedure in a view or a function.
    Erland Sommarskog, SQL Server MVP, [email protected]

  • Table Type  Stored Procedure in OBIEE Physical table properties

    Hi,
    Any one has ever used the Stored Procedure in OBIEE Physical table properties??
    I've a procedure & a table i want to plopulate the tabel using the Procedure from OBIEE physical layer.

    It would be nice if we know more details about 'Populating table'...
    Using connection pool->connection pool scripts tab you may go for inserting/updating (Populating table) records into table.
    It would be nice if you use dedicated connection pool for init blocks...
    Ex: I want to insert user login time some xyz table my query would be like
    insert into xyz values ('valueof(NQ_SESSION.USER)',sysdate)
    without knowing your requirements its hard to tell anything apart from what is said.
    If helps pls mark
    Edited by: Srini VEERAVALLI on Jan 16, 2013 10:37 PM

  • Create a procedure which will pass table name as an argument

    Please let me know, I want to create a procedure which will take
    table name as an argument and will display total no. of rows of
    that table.

    Hopefully this code will help u.
    CREATE OR REPLACE PROCEDURE P1(TAB_NAME IN VARCHAR2, ROW_NO
    OUT NUMBER)
    AS
    SQL_STMT VARCHAR2(1000);
    BEGIN
    SQL_STMT := 'SELECT COUNT(*) FROM ' || TAB_NAME;
    EXECUTE IMMEDIATE SQL_STMT INTO ROW_NO;
    END;
    SQL > VAR A NUMBER
    SQL > EXEC P1('EMP',:A);
    SQL > PRINT A
    A
    12
    SQL > SELECT COUNT(*) FROM EMP;
    COUNT(*)
    12

  • Oracle 8i and stored procedures

    Hi I was hoping someone could point me to the right direction here.
    I have been using SQL server before and often use stored procedures. I understand that if you want to use stored procedures you will use the CallableStatement object and the prepareCall method of the Connection object like so:
    let's say my stored proc has 2 number parameters:
    CallableStatement cs = con.prepareCall( " { call <stored_proc_name> (?, ?) } );
    cs.getString(1, 1);
    cs.getString(2, 2);
    ResultSet rs = cs.executeQuery( );
    where con is my connection object that i used to connect to my database. So far am I right with the following code?
    But my problem is I have to use Oracle 8i. So what is the equivalent of SQL server stored procs in Oracle? Is it functions? Procedures? Or Java Stored Procedures? I have been reading all these sites and the forums for ideas but still haev no clue what approach I should take
    I have managed to connect to my db using the thin drivers and have successfully passed SQL statements. Although, I don't want to pass SQL statements, I want to use stored procedures. With SQL server I would create all my stored procedures and use my beans to call these stored procedures. So as a new user of Oracle 8i coming form SQL server, what approach do I use and how?
    Thanks in advance for all the help!

    Alright well looks like I'm stuck now.
    This seems more like a PL\SQL question though. If I want to return 2 or more values do I use function or a procedure? here's the code I made:
    CREATE OR REPLACE FUNCTION sign_in(username VARCHAR(20), userpassword VARCHAR(20))
    RETURN NUMBER IS id_num NUMBER, user_type VARCHAR(1);
    BEGIN
    SELECT * INTO id_num, user_type
    FROM ID_MASTER idm, PERSON prs
    WHERE USERNAME = username
    AND USER_PASSWORD = userpassword
    AND idm.ID_NUM = prs.ID_NUM;
    RETURN id_num, user_type;
    END;
    now according to Oracle this is an invalid function. But the error message doesn't say much. Basically I want to pass 2 parameters to use for a query and return 2 variables from the result of the query. Am I suppose to use a procedure?
    If I pass paramters do which string do I use to prepareCall: "{ ? = CALL sign_in (?, ?) }" or do I use the "{ CALL sign_in (?, ?) }"
    But my problem right now is how to make the proper stored procedure. I'd be very much obliged to anyone who can give a sample. Thank you all for your time!

  • Oracle.DataAccess.Client stored procedure ORA-01403

    Hello,
    Microsoft announced that System.Data.OracleClient is deprecated and will be no more supported so I try to use the driver Oracle.DataAccess.Client after having installed ODP.
    It works fine except for stored procedures.
    After calling a stored procedure that increases a value in a column I meet this error :
    ORA-01403: no data found
    ORA-06512: at "XXXXX.MY_FUNCTION", line 15
    ORA-06512: at line 1
    Oracle Data Provider for .NET
    at Oracle.DataAccess.Client.OracleException.HandleErrorHelper(Int32 errCode, OracleConnection conn, IntPtr opsErrCtx, OpoSqlValCtx* pOpoSqlValCtx, Object src, String procedure, Boolean bCheck)
    at Oracle.DataAccess.Client.OracleException.HandleError(Int32 errCode, OracleConnection conn, String procedure, IntPtr opsErrCtx, OpoSqlValCtx* pOpoSqlValCtx, Object src, Boolean bCheck)
    at Oracle.DataAccess.Client.OracleCommand.ExecuteNonQuery()
    The same function worked very well during several years with OracleClient !
    Does any body has an idea ?
    Best regards
    Alan

    Hello,
    I had the solution by an other forum.
    It's necessary to define the property BindByName at true.
    The driver OracleClient did that by default not the driver DataAccess !
    Best regards

  • How to call CLOB to BLOB conversion function within stored procedure?

    I have a tiny APEX application from which I need to be able to print. I’ve used these two resources: (Is there an inexpensive APEX report printer for invoices/checks/statements? and http://download.oracle.com/docs/cd/E14373_01/appdev.32/e13363/up_dn_files.htm#CJAHDJDA)
    I guess that in order to be able to download the RTF document stored in CLOB, I need to convert it into BLOB. I’ve found this function for this purpose on Oracle forums:
    CREATE OR REPLACE FUNCTION     c2b( c IN CLOB ) RETURN BLOB
    -- typecasts CLOB to BLOB (binary conversion)
    IS
              pos PLS_INTEGER := 1;
              buffer RAW( 32767 );
              res BLOB;
              lob_len PLS_INTEGER := DBMS_LOB.getLength( c );
    BEGIN
         DBMS_LOB.createTemporary( res, TRUE );
         DBMS_LOB.OPEN( res, DBMS_LOB.LOB_ReadWrite );
    LOOP
         buffer := UTL_RAW.cast_to_raw( DBMS_LOB.SUBSTR( c, 16000, pos ) );
         IF          UTL_RAW.LENGTH( buffer ) > 0
         THEN
                   DBMS_LOB.writeAppend( res, UTL_RAW.LENGTH( buffer ), buffer );
         END IF;
         pos := pos + 16000;
         EXIT WHEN pos > lob_len;
    END LOOP;
    RETURN res; -- res is OPEN here
    END c2b;And I am trying to use it in the modified download procedure that I also have found on Oracle forums:
    CREATE OR REPLACE PROCEDURE DOWNLOAD_WO(v_id IN NUMBER)
    AS
            v_mime          VARCHAR2(48);
            v_length     NUMBER;
            v_file_name     VARCHAR2(2000):= 'WO_Download.rtf';
            lob_loc          CLOB;
              v_blob      BLOB;
              v_company        jobs_vw.company%TYPE;
              v_project        jobs_vw.project%TYPE;
              v_description     jobs_vw.description%TYPE;
              v_date_          jobs_vw.date_%TYPE;
              v_job_no          jobs_vw.job_no%TYPE;
              v_apqwo               jobs_vw.apqwo%TYPE;
    --          v_mime           VARCHAR2(48) := 'application/msword';
    BEGIN
            SELECT     mime_type, report, DBMS_LOB.GETLENGTH(report)
              INTO     v_mime,lob_loc,v_length
              FROM     report_layouts
              WHERE     rl_id = 22332925279634283;
    -- JOB_VW record:
        SELECT     job_no
                   ,date_
                   ,description
                   ,apqwo
                   ,project
                   ,company       
         INTO     v_job_no
                   ,v_date_
                   ,v_description
                   ,v_apqwo
                   ,v_project
                   ,v_company
         FROM     jobs_vw
         WHERE     id = 214;
    -- Replace holders with actual values:
        lob_loc := REPLACE(lob_loc, '#COMPANY#', v_company);
        lob_loc := REPLACE(lob_loc, '#PROJECT#', v_project);
        lob_loc := REPLACE(lob_loc, '#DESCRIPTION#', v_description);
        lob_loc := REPLACE(lob_loc, '#DATE_#', TO_CHAR(v_date_, 'DD/MM/YYYY'));
        lob_loc := REPLACE(lob_loc, '#JOB_NO#', v_job_no);
        lob_loc := REPLACE(lob_loc, '#APQWO#', v_apqwo);
                  -- set up HTTP header
                        -- use an NVL around the mime type and
                        -- if it is a null set it to application/octect
                        -- application/octect may launch a download window from windows
                        owa_util.mime_header( nvl(v_mime,'application/octet'), FALSE );
                    -- set the size so the browser knows how much to download
                    htp.p('Content-length: ' || v_length);
                    -- the filename will be used by the browser if the users does a save as
                    htp.p('Content-Disposition:  attachment; filename="'||replace(replace(substr(v_file_name,instr(v_file_name,'/')+1),chr(10),null),chr(13),null)|| '"');
                    -- close the headers           
                    owa_util.http_header_close;
                    -- download the BLOB
    --                wpg_docload.download_file( Lob_loc );
                             v_blob := c2b(lob_loc);
                             wpg_docload.download_file( v_blob );
    end DOWNLOAD_WO;
    /Unfortunately when I try to compile the download_wo stored procedure I am getting this error:
    Error at line 64: PL/SQL: Statement ignoredThe 64th line is:
    v_blob := c2b(lob_loc);How should I correctly call c2b within download_wo? Any advice is greatly appreciated.
    Thank you for your time.
    Daniel

    Hello there,
    Well, its invalid :(
    Object C2B is Invalid. I didn't know since when I run the create ... function, I only get this feedback:
    Statement processed.
    0.19 secondsI am investigating.
    Daniel

  • Remove Invocation to a Function or Stored Procedure

    Hi,
    This is regarding invoking functions, stored procedures remotely, from Oracle database to another Oracle database. This call is going to be made from databases set in different networks, and using plain PL-SQL. When the remote database receives the call it will start processing thousands of records, this operation is estimated to last at least an hour.
    Our question is related to session's time out, would the database that made the call time out because the remote database is taking too long to respond (in this case, too long to process the records)?
    Thank you.

    user3112983 wrote:
    Hi,
    This is regarding invoking functions, stored procedures remotely, from Oracle database to another Oracle database. This call is going to be made from databases set in different networks, and using plain PL-SQL. When the remote database receives the call it will start processing thousands of records, this operation is estimated to last at least an hour.By thousands do you mean hundreds of thousands, millions or more? If your application can only process a thousand records in an hour i'd say there's some process tuning to be done :)
    Our question is related to session's time out, would the database that made the call time out because the remote database is taking too long to respond (in this case, too long to process the records)?
    Thank you.If you expect the duration to be that long, why not have the client (database A) submit a job to the server (database B) ? You could achieve that by creating a procedure on database B which submits a job via DBMS_JOB.
    One option anyway.

  • Function calling stored procedure that returns a cursor into a LOV

    Hello,
    Is it possible in HTML DB to implement a process that has a function that calls a stored procedure that returns a cursor, used to then populate a select list?
    Or can I do a function call to a stored procedure in the 'List of values definition' box for the item itself that returns a cursor to populate the item's select list?

    Hi Vikas,
    Actually, I just found another posting that shows how to do what I'm looking for:
    Re: Filling a LOV with a cursor
    Check it out. I posted another question in response to that discussion...maybe you could answer that? Thanks!
    Laura

  • Sending Long Raw Data to Oracle database through Stored  Procedure

    Hi,
    I am trying to push data to Oracle 9i database through Stored Procedure via thin driver. It is going smoothly upto 29411 bytes. But it is not accepting for 53843 bytes and giving following error :
    java.sql.SQLException: Data size bigger than max size for this type: 53843
    Is it thin driver limitation? Can I solve it by using OCI driver? Or is there any other approach?
    I tried creating connection pool in weblogic 7.0 through OCI driver. But I am not able to configure it. Is there any special way of configuration.
    Quick response will be greatly appreciated.
    Thanks
    Sanjiv

    It happens to me. But I am using CMP of Weblogic 7. If you write your own jdbc code, the following link may be helpful.
    http://otn.oracle.com/sample_code/tech/java/codesnippet/xmldb/HowToLoadLargeXML.html

  • Cursors in Oracle 10g XE stored procedures

    I want to use a cursor in a stored procedure. I saw many examples on the net but none of them seem to work in Oracle 10g Express Edition.
    I am new to Oracle and any solution relevant to Oracle 10g XE is highly appreciated.
    Yosief Kesete

    Dear user!
    Simple error. Try that:
    CREATE OR REPLACE PROCEDURE "employeesgetlist
      p_FIRST_NAME IN VARCHAR2,
      returnValue OUT SYS_REFCURSOR
    IS
      p_EMPLOYEE_ID NUMBER;
      CURSOR C1 IS
      SELECT employee_id
      FROM employees
      WHERE first_name = p_FIRST_NAME;
    BEGIN
      BEGIN
        -- OPEN A PREVIOUSLY DECLARED CURSOR
        OPEN C1;
        LOOP
          FETCH C1 INTO p_EMPLOYEE_ID;
          EXIT WHEN C1%NOTFOUND;
        END LOOP;
         -- CLOSE THE CURSOR
        CLOSE C1;
      END;
      OPEN returnValue FOR
      SELECT * FROM employees
      WHERE employee_id = p_EMPLOYEE_ID;
    END;
    {code}
    Yours sincerely
    Florian W.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

Maybe you are looking for