Creating a table/view or temporary table from within a stored procedure

Hi Gurus,
Can someone tell me if it is possible to create a table (or view) from within a stored procedure.
PROBLEM:
In fact I need to create a report at back end (without using oracle developer forms or reports). This report requires creating several tables to hold temporary report data. If I create a sql*plus script for this, i works fine, because it can run DDL and other sql or pl/sql statements sequencialy. But this sql*plus script cannot be called from application. So, application needs an stored procedure to do this task and then application call that procedure. But within stored procedure, i am unable to create table (or run any ddl statement). Can somebody help me in this?
Thanks in Advance.

Denis,
The problem with Nicholas' suggestion isrelated to the fact that now you have two components
(a table and a stored procedure)
I don't see any problem to have "two
components" here. After all, what about all others
tabes ? This is only one more, but I don't understand
why want manage less objects, that implies more code,
more maintenance, and more difficulties to debug.
Needless to say about performance...
Nicolas.The same reasons apply if you were forced to declare all PL/SQL variables publicly (outside the stored proc.) rather than privately (from inside the stored proc). Naming conflicts for one. If the name that you want to use for the GTT already exists, you need to find a new name. With the SQL Server type local/private declarations, you wouldn't have that problem.
I can see how performance would be the same or better using GTTs. If the number of records involved is low, this is likely negligable.

Similar Messages

  • Sending email from within a stored procedure

    Is it possible to send and email within a stored procedure written in PL/SQL. I have searched this site and the web for an Oracle package which simulates a mail agent written in PL/SQL, but I have not had any success.
    null

    Well, on NT one way we did it was to link to kernel32.dll so we could execute OS commands (WinExec), and did the email that way.
    Here's a bit of script to try:
    connect sys/@db;
    drop library kernellib;
    CREATE LIBRARY kernellib as 'c:\winnt\system32\kernel32.dll';
    show errors
    CREATE OR REPLACE PACKAGE UTIL IS
    function run(lpCmdLine IN varchar2, nCmdShow IN binary_integer) return binary_integer;
    end;
    show errors
    CREATE OR REPLACE PACKAGE BODY UTIL IS
    function run(lpCmdLine IN varchar2, nCmdShow IN binary_integer) return binary_integer
    AS EXTERNAL
    NAME "WinExec"
    LIBRARY kernellib
    parameters (lpCmdLine STRING, nCmdShow long);
    end;
    show errors
    Then you just call util.run() with an appropriate command line to send email. Bit of a hack, but it depends on what you want to do with it. Another hack would be to use the UTL_HTTP package to submit a form to your web server and use a CGI program to send the email.

  • SELECT query from within a stored procedure

    DB Version:10gR2
    For auditing purpose, i just want to execute the query within the IF condition, and get the results for spooling. But i am getting PLS-00428 error. Can't i just execute a SELECT query and get its results displayed in SQLPLUS so that i can spool them?
    SQL> create or replace procedure ship_dtl_aud
      2  is
      3  v_exists number;
      4 
      5  begin
      6  
      7  Select count(1) into v_exists
      8  From ship_dtl
      9  WHERE track_code = 10
    10  AND mod_date_time < SYSDATE - 1/(24*60);
    11 
    12   if v_exists>0
    13   then
    14            select s.username,s.sid, s.serial#, s.terminal,p.spid
    15   from v$session s, v$process p
    16   where s.paddr = p.addr and s.sid in (select SESSION_ID from V$LOCKED_OBJECT);
    17 
    18          end if; 
    19  end;
    20  /
    Warning: Procedure created with compilation errors.
    SQL> show errors
    Errors for PROCEDURE ship_dtl_aud:
    LINE/COL ERROR
    14/11    PLS-00428: an INTO clause is expected in this SELECT statement

    Within PL/SQL code, the results of a query have to be returned from the SQL engine to the PL/SQL engine, hence why it is asking you to include an INTO within your query. Note that the PL/SQL engine is running on the database server so it has no interface to display output to. To output from within PL/SQL you would have to write the data out yourself to whatever output you want e.g. use DBMS_OUTPUT to put the data to the standard output buffer (which can then be read by SQL*Plus if serveroutput is set to "on") or written out to a file on the server, or written out to a table.
    You are assuming that because you can execute SQL from SQL*Plus and spool the output, you can do the same within PL/SQL. This is not the case. When SQL*Plus issues a SQL statement, it goes to the SQL engine and the results of that cursor (as an SQL query is a cursor) are collected by SQL*Plus and it displays them itself. When PL/SQL issues a SQL statement, it goes to the SQL engine and the results of that cursor come back to PL/SQL. PL/SQL doesn't have a display mechanism, so the results have to be collected INTO something.
    Hope that's clear.

  • Running "Host" From Within a Stored Procedure

    Hellow
    Wanna Run a "Host" Command from Within A SP
    or DB Trigger
    Any Help is Appreciated !!
    Regards
    Tariq

    the only way to run an OS command from within the database is through extproc
    (works from 8.x onwards).
    Essentially, you have to:
    - modify the database listener to support external procedure calls
    - create a library object
    - create a C - program and compile it as a shared library
    - write a wrapper function in PL/SQL that calls the shared library
    I can send you an example, if you want.
    Regards
    Anton Weindl

  • How to create a maintainance view for a table.

    Hi All,
    Can anyone explain me how do we create a maintainance view for a table?
    Also, what access is required to create the view.
    Is it true that for SAP tables we cannot create a maintainance view?
    Appreciate any help on this.

    Hi
    Can anyone explain me how do we create a maintainance view for a table?
    <i>
    You can use the SE11 menu option 'Utilities-->Table Maintenance Generator' or you can use transaction SE54.</i>
    also check
    <i>http://help.sap.com/saphelp_nw04/helpdata/en/38/81c1351181b73fe10000009b38f839/frameset.htm</i>
    http://help.sap.com/saphelp_nw04/helpdata/en/38/81c1351181b73fe10000009b38f839/frameset.htm
    Regards
    krishna
    <i>Note: Award Points if helpful. Thanks</i>

  • Creating a "Print View" of a Table on Another Sheet

    Hi-
    I would like to create a "print view" of a table on another sheet that already has reorganization filters applied to it.  There is a template in Numbers called "Employee Schedule" that has exactly this, where the "printable" table's cells simply reference every cell in the source table on the other sheet.
    I know there is a way to very quickly (i think with a dragging motion), create the references in each cell in one or two operations, as opposed to going to each individual cell and typing in the reference to the source table.  I saw a post about how to do this a while back but cannot seem to locate it again
    How do I do this?  Thanks again for everyones help ;-)
    Thanks
    Matt

    mattford1 wrote:
    Hi-
    Re-reading this, I don't think this answered my question.  I understand how to reference a single cell, but how do you reference an entire table easily without having to go to each cell.
    Thanks
    Matt
    Matt,
    Select the first cell by clicking once on it, such that the border is highlighted. Then grab the little circle in the lower right corner of the border and drag it to the end of your table, either right or down. You can use this method to fill down or to the right. Sometimes it can be fussy, and if it refuses to behave, then you can use the alternate method, Copy and Paste. Click once on the first cell and Command-C. Shift-click the last cell and Command-V.
    Jerry

  • How to create table view with reference table

    Hi experts,
    How to create table view with reference table in SE11, plz gve me stp by stp procedure.
    pints grnded for hlp.

    Hi
    Go to Tcode se11 choose view and enter the name and create a popup opens up choose database view option
    enter the description
    On the left hand side choose the table name.
    Click on view fields tab and choose your table fields.Here you can choose which fields you want in your view.
    Save and then activate.
    Hope this helps.
    Regards,
    Harish

  • How to insert a table data into temporary table

    Hi
    Can anyone help me to insert a table data into temporary table.
    Thanks
    Navin

    If you could provide a (simplified) example of the data you have and the output you're attempting to get, that would probably be quite helpful. I'm not sure that I understand exactly what you're trying to do here...
    1) It sounds like you know the structure of the result set you're trying to generate. So it would be possible to create a temporary table once (at the same time that you create all your other tables) and write procedural PL/SQL code that would step through the data, write data to the temp table, select the data out of the temp table, and return a REF CURSOR. That would tend not to be the way that an Oracle developer would do things (there are exceptions, of course), but it would work.
    2) I don't see any inherent problems in using sub-selects and inline views to do whatever aggregation you're trying to do on the secondary tables, which would allow you to get the output in a single query. For example, given an ORDERS table and an ORDER_DETAILS table,
    SELECT o.customer_id, o.invoice_number, SUM( od.line_item_cost ) total_cost
      FROM orders o,
           order_details od
    WHERE o.order_id = od.order_id
    GROUP BY o.customer_id, o.invoice_number3) If you do need to use procedural logic, I would tend to look into the use of pipelined table functions or to read the data into an in-memory collection and to manipulate and return that collection.
    Justin

  • T-sql 2008 r2 place results from calling a stored procedure with parameters into a temp table

    I would like to know if the following sql can be used to obtain specific columns from calling a stored procedure with parameters:
    /* Create TempTable */
    CREATE TABLE #tempTable
    (MyDate SMALLDATETIME,
    IntValue INT)
    GO
    /* Run SP and Insert Value in TempTable */
    INSERT INTO #tempTable
    (MyDate,
    IntValue)
    EXEC TestSP @parm1, @parm2
    If the above does not work or there is a better way to accomplish this goal, please let me know how to change the sql?

    declare @result varchar(100), @dSQL nvarchar(MAX)
    set @dSQL = 'exec @res = TestSP '''+@parm1+''','' '''+@parm2+' '' '
    print @dSQL
      EXECUTE sp_executesql @dSQL, N'@res varchar(100) OUTPUT', @res = @result OUTPUT
    select @result
    A complicated way of saying
    EXEC @ret = TestSP @parm1, @parm2
    SELECT @ret
    And not only compliacated, it introduces a window for SQL injection.
    Erland Sommarskog, SQL Server MVP, [email protected]

  • Please recommend if we have options to read xml file and insert data into table without a temporary table.

    Please recommend if we have options to read xml file and insert data into table without a temporary table. 

    DECLARE @data XML;
    SET @data =N'<Root>
    <List RecordID="946236" />
    <List RecordID="946237" />
    <List RecordID="946238" />
    <List RecordID="946239" />
    <List RecordID="946240" />
    </Root>'
    INSERT INTO t (id) SELECT T.customer.value('@RecordID', 'INT') AS id
    FROM @data.nodes('Root/List')
     AS T(customer);
    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

  • BO v5.1 - creating a report from an oracle stored procedure

    Post Author: newrochelle
    CA Forum: Publishing
    hi to all,
    im using BO 5.1 and i need to create a document from an oracle stored procedure that have only one IN parameter and ten OUT parameters.
    Creating the new report I selected the database connection then I choose the stored procedure name from the list, I inserted the value for the IN parameter and finally I click on Run button.
    I got the following error message:
    ORA-06550: line 1, column 38: :PLS-00103: Encountered the symbol
    "," when expecting one of the following: : : ( - + case mod
    new not null others <an identifier> : <a double-quoted
    delimited-identifier> <a bind variable> avg : count current
    exists max min prior sql stddev sum variance : execute forall
    merge time timestamp interval date : <a string literal with
    character set specification> : <a number> <a single-quoted SQL
    string> pipe : <an alternatively-quoted string literal with
    character set specification> : <an alternatively-q :-6550
    it seems to be caused by the OUT parameters!
    i leaved them without any value.
    it's the first time that I used a stored procedure to create a BO report, but I think the OUT parameters are needed to do that, otherwise what data will be presented in the report???
    can you help me?
    please answear me ASAP.
    Thank's in advance
    Regards
    Andrea

    Post Author: synapsevampire
    CA Forum: Publishing
    Try posting in a BO forum, this is Crystal Reports.
    -k

  • Retrieving a UDT object from a Java Stored Procedure

    I am really having trouble returning a UDT object (AttributeUDT) from a Java stored procedure. I am using Oracle 8.1.6 and JDeveloper 3.2.2. I have successfully used JPublisher to create the Java source code files for my UDT, now I would like to use that in coordination with my Java stored procedure. I've loaded the Java stored procedure into the database using the Deployment option in JDeveloper. However, when it loads the procedure, it translates the 3rd parameter to an OBJECT type, thus making the stored procedure invalid. I can use SQL Navigator to correct the package by changing the OBJECT reference to AttributeUDT (my UDT data type). Unfortunately, my Java stored procedure still does not work. Any help would be greatly appreciated! Thanks in advance for your time!
    In the example below, could anyone please tell me:
    1. How do I register the OUT variable for the UDT?
    2. Is it correct to use the casted call to getObject to retrieve my UDT object?
    3. Is it valid to use the UDT data type in the java stored procedure method signature?
    The call to the Java stored procedure:
    OracleCallableStatement cs3 = (OracleCallableStatement)conn.prepareCall( "{ call sandbox.getQualifiersV3( ?, ?, ?) }");
    cs3.registerOutParameter( 1, Types.VARCHAR);
    cs3.registerOutParameter( 2, Types.VARCHAR);
    cs3.registerOutParameter( 3, ???????);
    cs3.execute();
    System.out.println( "ID: " + cs3.getString( 1));
    System.out.println( "Prompt: " + cs3.getString( 2));
    AttributeUDT attributes = (AttributeUDT)cs3.getObject( 3);
    System.out.println( "Table id: " + attributes.getLogicalTableId());
    System.out.println( "Element id: " + attributes.getElementId());
    cs3.close();
    ===========================================
    The Java stored procedure:
    public static void getQualifiersV3( String ids[], String prompts[],
    AttributeUDT attributes[]) throws SQLException {
    OracleConnection conn = (OracleConnection)new OracleDriver().defaultConnection();
    Statement stmt = conn.createStatement();
    OracleResultSet rs = (OracleResultSet)stmt.executeQuery(
    "SELECT * "
    + "FROM VPS_ABOK_QUALIFIERS "
    + "WHERE qualifier_id = 2001");
    rs.next();
    ids[0] = rs.getString( 1);
    prompts[0] = rs.getString( 2);
    attributes[0] = (AttributeUDT)rs.getCustomDatum( 3, AttributeUDT.getFactory());
    rs.close();
    stmt.close();
    null

    Sounds like your C2 REF TYP1 attribute may be null. Unfortunately you neglected to say where in your code the NullPointerException occurs.

  • I would like to prevent any user including admins from modifying a stored procedure

    I would like to prevent any user including admins (apart from myself) from modifying a stored procedure.
    I cant use encryption because i need people to be able to read the code, I cant use trigger because we arent able to add triggers to system tables. 
    Any ideas?

    You cannot prevent from the logins who are members of sysadmin role to modify stored procedures.
    If you DENY ALTER SCHEMA then the user won't be able to issue any DDL changes (CREATE, ALTER, DROP) that affect objects in that schema
    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

  • Calling JPA from a Java Stored Procedure

    Is it possible to call JPA from a java stored procedure? If so, does anyone have example? How do you setup the persistence.xml?
    How does the peformance compare with straight JDBC in a java stored procedure?
    Thanks for any help!
    Johnny

    Hi Johnny:
    Basically you can run any JDK 1.5 framework inside your Oracle 11g JVM, I have experience integrating Lucene IR library as a new [Domain Index for Oracle 11g/10g|http://docs.google.com/View?id=ddgw7sjp_54fgj9kg] .
    I am not familiar with JPA internals but my advice is howto handle the connection inside the OJVM and the configuration files.
    Some time ago I took a look to SpringFramework integration and I found that writing a new ApplicationContext class which handles the loading of beans.xml from XMLDB repository instead a file should be enough to work.
    Another important point is the life cycle of the [Oracle internal JVM|http://download.oracle.com/docs/cd/E11882_01/java.112/e10588/chtwo.htm#BABHGJFI]. Unlike an standard JVM the OJVM is created once you first connect from the middle tier at OCI level and remains in execution during the connection pool existence.
    I mean, if you connect using a JDBC pool the JVM will remains running across multiple soft open/close connections of your middle tier application. This is good because you can read your persistence.xml file using a Singleton class and this expensive operation will be re-used by multiple open/close operation done from the middle tier.
    I suggest you do a simple Proof of Concept with a Hello World application and check if it works.
    Remember that any security issues will be notified to the .trc files, security issues are related to the strong security layer configured by default inside the OJVM, for example you can not read any files from the OS file system without an specific grant, you need another grant to access to the class loader and so on, but you can simply grant this specific needs to a database role and then grant this role to the user which connect to the OJVM.
    Another important point is related to the [End-of-Call Optimization|http://download.oracle.com/docs/cd/E11882_01/java.112/e10588/chtwo.htm#BABIFAAI] this can be useful if you want to perform some clean up in your Singleton class at the level of per-statement execution.
    Best regards, Marcelo

  • Invoking "java myClass" using Runtime.Exec from a Java Stored Procedure

    Hi All,
    This is regarding the use of Runtime.getRunTime().exec, from a java programme (a Java Stored Procedure), to invoke another Java Class in command prompt.
    I have read many threads here where people have been successuful in invoking OS calls, like any .exe file or batch file etc, from withing Java using the Runtime object.
    Even i have tried a sample java programme from where i can invoke notepad.exe.
    But i want to invoke another command prompt and run a java class, basically in this format:
    {"cmd.exe","java myClass"}.
    When i run my java programme (in command prompt), it doesnt invoke another command prompt...it just stays hanging.
    When i run the java programme from my IDE, VisualCafe, it does open up a command prompt, but doesnt get the second command "java myCLass".
    Infact on the title of the command prompt (the blue frame), shows the path of the java.exe of the Visual Cafe.
    and anyway, it doesnt run my java class, that i have specified inside the programme.
    Even if i try to run a JAR file, it still doesnt do anything.
    (the JAR file other wise runs fine when i manually invoke it from the command prompt).
    Well, my question is, actually i want to do this from a Java Stored Procedure inside oracle 8.1.7.
    My feeling is, since the Java Stored Procedure wont be running from the command prompt (i will be actually invoking it through a Oracle trigger), it may be able to invoke the command prompt and run the java class i want. and that java class has to run with the SUn's Java, not Oracle JAva.
    Does any one have any idea about it?
    Has anyone ever invoked a java class or JAR file in command prompt from another Java Programme?
    YOur help will be highly appreciated.
    (P:S- Right now, my database is being upgraded, so i havent actually been able to create a Java Stored procedure and test it. But i have tested from a normal java programme running in command prompt and also from Visual Cafe).
    Thanks in advance.
    -- Subhasree.

    Hello Hari,
    Thanks for your quick reply.
    Can you please elaborate a little more on exactly how you did? may be just copy an dpaste taht part of teh code here?
    Thanks a lot in advance.
    --Subhasree                                                                                                                                                                                                                                                                                                                                                                                                           

Maybe you are looking for

  • My phone screen is lagging, my phone screen is lagging

    my screen is not true to the touch anymore. I find my self typing text messages or emails and I have to stop to let the phone catch up to my typing. Sliding throuh pictures or switching screens is the same I swype and then have to wait a second or tw

  • My ipod resets when a certain song plays and it won't update some videos

    There is one song that no matter what when it plays it resets my ipod, black screen with the silver logo then main menu after like 30 seconds. And I have a tv show on my iTunes but even though it shows its on my ipod I can't find it on there. So is t

  • Query is taking only 1 dept .,...how to pass dept98 in query

    select file_subject as "File Subject", (select RECEIPT_DATE from FILETRANS JOIN FILEMASTER on filemaster.file_serial_no = FILETRANS.file_serial and filemaster.file_year=FILETRANS.file_year and filetrans.RECEIPT_DATE between trunc(sysdate-6)+(15/24) a

  • SL300-Vide​o-Problem: Powerpoint​-Display gone crazy!

    Hello everybody! I'm not having a user/desing-problem with powerpoint. There is a massive display/graphics-problem with my SL300, that does only happen when I use powerpoint so far: Lenovo Thinkpad SL 300: CPU: Core 2 Duo T6570, 2,10GHz; RAM: 2GB; GP

  • Splitting a long recording into different songs?

    Some friends and I will be recording today and there are a few things I am unsure about. First, we usually play for about 2 hours nonstop and we will be recording 3 simultaneous tracks. After the session, I would like to export the recording into itu