How to include 3 sql statements in a single procedure

I have 3 SQL statements to create 3 tables:
Table1:To get all the data from an ORIGIN table that have an expiration_dates between 02/01/2006 and 04/30/2006. This has all the customer data (customer_id, company, etc…)
Table 2:Secondly I am getting all the customer_ids for February into another table called table2
Table 3: Thirdly I am joining table 1 and table 2 on customer_id to get all the entries for the February customers those expire in February, March and April.
Now I want to include all these in a procedure. Can I put all these together in 1 procedure so that I can run all these at once and have the results?
Please throw some light on this.
Thanks,
Ac

I hope this code will help you a little bit
[email protected]> create table orgin(customer_id int, company varchar2(20), expiration_date date)
2 /
Table created.
Elapsed: 00:00:01.06
[email protected]> create table table2 (customer_id int, expiration_date date)
2 /
Table created.
Elapsed: 00:00:00.01
[email protected]> create table customers_table(customer_id int, cust_date date)
2 /
Table created.
Elapsed: 00:00:00.01
[email protected]> create table table3(customer_id int)
2 /
Table created.
Elapsed: 00:00:00.01
[email protected]> create table table1(customer_id int, company varchar2(20), expiration_date date)
2 /
Table created.
create or replace procedure customers is
begin
-- table1
insert into table1 select customer_id, company, expiration_date
from orgin
where expiration_date between to_date('01-02-2006','dd-mm-yyyy')
and to_date('30-04-2006','dd-mm-yyyy');
-- table2
insert into table2 select customer_id, cust_date from customers_table
where cust_date between to_date('01-02-2006','dd-mm-yyyy')
and to_date('28-02-2006','dd-mm-yyyy');
-- table3
insert into table3 select a.customer_id from table1 a, table2 b
where a.customer_id = b.customer_id;
end;
Best Regards
Krystian Zieja / mob

Similar Messages

  • How to find sql statement with Unix process pid

    Hi
    how to find sql statement with Unix process pid
    is there any view to find that.
    please if so let me know
    Thanks in advance

    this is how I am doing this:
    oracle 7352340 7459066 0 07:47:10 - 0:00 oracleJDERED (DESCRIPTION=(LOCAL=YES)(ADDRESS=(PROTOCOL=beq)))
    oracle 7459066 5386396 2 07:47:10 pts/1 0:01 sqlplus
    select sid,serial# from v$session where process='7459066';
    SID SERIAL#
    2178 6067
    select sql_text
    from
    v$sqlarea a,
    v$session b
    where a.hash_value = b.sql_hash_value
    and b.sid = 2178
    ;

  • How to Capture  sql statement

    we have 1 server oracle and many clients.
    when client sends sql statement to server.How to Capture sql statement to analysis berfore it sent to server and execution.
    Edited by: 955185 on Aug 27, 2012 4:22 AM

    955185 wrote:
    yes. how to do this?Check these link all of them talking about Already executed sql in database by Users , but i don't know if what you ask is possible since they already connect to database
    If you attending to analysis sql read the below links and start your analysis,
    Last executed sql
    http://www.databasejournal.com/features/oracle/article.php/3373701/Watching-SQL-Execute-on-Oracle---Part-I.htm
    http://stackoverflow.com/questions/55899/how-to-see-the-actual-oracle-sql-statement-that-is-being-executed

  • Writing mulitple sql statements in 1 stored procedure

    Hi all, can i know how to create mulitple sql statements in 1 stored procedure??
    Eg the first sql statement will generate few results and my second sql statement will based on the first statement result to execute its second results and my third sql statements will on the second results to generate the final results which will be passed back to jsp pages as a resultset??
    For the time being, i only know how to create a single sql statement in one stored procedure..i had surf through the oracle website but cant find any solution. Can anyone help me?? Samples or links to any website will do.. Thanks alot...

    Hi Irene,
    If I understand your question correctly, then I have already written
    a similar (PL/SQL) stored procedure without any problems.
    However, I do think your question is more suited to the following
    forum:
    http://forums.oracle.com/forums/forum.jsp?id=478021
    I also think it will help others to answer your question if you
    include the following information:
    1. Version of Oracle you are using.
    2. The error message you are getting.
    3. The part of your code that is causing the problem.
    Also, have you looked at the following web sites?
    http://asktom.oracle.com
    http://metalink.oracle.com
    Good Luck,
    Avi.

  • How to call SQL statements in InDesign CS6?

    Hi,
         My plug-in needs to interact with the database, and update the database content, how should I do, can I call SQL statements in InDesign CS6?
         Thanku very much.

    The same way you'd call them from any C++ program. You don't mention which platform, and that probably makes a difference.
    I'm accessing an SQL database in InDesign CS6 on Windows. I'm using the ODBC interface to SQL database that Windows provides, via the nanodbc wrapper. So I'm linking to odbc32.lib and odbccp32.lib, and including the nanodbc.cpp and nanodbc.h files. (See http://lexicalunit.github.io/nanodbc/ )
    Paul.

  • How to find SQL Statement fired using SYS.AUD$ - Database Auditing

    Dear Friends
    I am having Oracle 9i Database and have configured it with database auditing option by setting the following parameter in init.ora file
    AUDIT_TRAIL = "DB"
    I want to audit SELECT, INSERT , UPDATE and DELETE operations on PRACTICE.EMP table for which I did :
    1) Logged in as SYS
    2) SQL> AUDIT SELECT, INSERT, UPDATE, DELETE
    ON PRACTICE.EMP
    BY ACCESS
    WHENEVER SUCCESSFUL;
    Audit Succedded
    Now how should I find out the SQL statement that does the insert, update or delete operation on the EMP table using SYS.AUD$ table
    Thanks

    Hi,
    It's contents can be viewed directly or via the following views:
    * DBA_AUDIT_EXISTS
    * DBA_AUDIT_OBJECT
    * DBA_AUDIT_SESSION
    * DBA_AUDIT_STATEMENT
    * DBA_AUDIT_TRAIL
    * DBA_OBJ_AUDIT_OPTS
    * DBA_PRIV_AUDIT_OPTS
    * DBA_STMT_AUDIT_OPTS
    The audit trail contains a lot of data, but the following are most likely to be of interest:
    * Username : Oracle Username.
    * Terminal : Machine that the user performed the action from.
    * Timestamp : When the action occured.
    * Object Owner : The owner of the object that was interacted with.
    * Object Name : The name of the object that was interacted with.
    * Action Name : The action that occured against the object. (INSERT, UPDATE, DELETE, SELECT, EXECUTE)
    So, take a look at action_name column from DBA_AUDIT_TRAIL view.
    Cheers
    Legatti

  • How to find SQL statement = Database Auditing

    Dear All
    I have configured Database Auditing on Oracle 9i Enterprise Edition Server
    parameter init.ora file:
    AUDIT_TRAIL = "DB"
    I want to audit INSERT,UPDATE, DELETE STATEMENT on PRACTICE.EMP table
    for which i did :
    1) Logged in as SYS
    SQL> AUDIT INSERT,UPDATE,DELETE
    ON PRACTICE.EMP
    BY ACCESS
    WHENEVER SUCCESSFUL
    Audit Succedded
    2) Now I have to check the SQL statement that did insert update or delete operation using SYS.AUD$
    3) There is SQLTEXT field , datatype is CLOB.
    How should I check the SQL Statements that were fired on PRACTICE.EMP table
    Kindly help

    SQL> show user
    USER is "SYS"
    SQL> alter system set audit_trail = db,extended scope=spfile;
    alter system set audit_trail = db,extended scope=spfile
    ERROR at line 1:
    ORA-32001: write to SPFILE requested but no SPFILE specified at startup
    I have init.ora but no spifle so should I create SPFILE based on INIT.ORA and then give the command ?
    As of now I am using V$SQL view to find all the commands executed on my database.
    I found one good book "Oracle Security" OREILY PUBLICATION in which Auditing Database is discussed in good details.
    Thank you so much for all your efforts

  • How to retrieve SQL statement in the CR 2008

    I'm using Crystal Reports 2008 in MS Visual Studio 2008, how can i retrieve SQL statement from *.rpt file, i have tried this code, but it doesn't work:
    ReportDocument rdReport = new ReportDocument();
    rdReport.Load("Reports/EmployeeTest.rpt", OpenReportMethod.OpenReportByTempCopy);
    CrystalDecisions.ReportAppServer.Controllers.RowsetController rsController;
    CrystalDecisions.ReportAppServer.ClientDoc.ISCDReportClientDocument rdClient = rdReport.ReportClientDocument; // on this line it throws an exception "The ReportClientDocument property can only be accessed when the report is opened using a Report Application Server."
    CrystalDecisions.ReportAppServer.DataDefModel.ISCRGroupPath rdGroupPath = new CrystalDecisions.ReportAppServer.DataDefModel.GroupPath();
    string temp;
    string sql;
    rsController = rdClient.RowsetController;
    sql = rsController.GetSQLStatement(rdGroupPath, out temp);
    maybe i'm doing something wrong ?
    thanks

    Hello Ludek,
    when I try to get the report from the session I got an error like this (I am using State Server Session mode i.e out proc in my application)
    ReportClientDocument     'reportDocument.ReportClientDocument' threw an exception of type 'System.InvalidOperationException'     CrystalDecisions.ReportAppServer.ClientDoc.ISCDReportClientDocument {System.InvalidOperationException}
    +base     {"The ReportClientDocument property can only be accessed when the report is opened using a Report Application Server."}     System.SystemException {System.InvalidOperationException}
    StackTrace     "   at CrystalDecisions.CrystalReports.Engine.ReportDocument.get_ReportClientDocument()"     string
    so is it the problem of not opened with RAS. Does installation of RAS solves the problem, If so Is it a free-ware or needs to be purchased.
    Ashok

  • How to monitor  SQL statements issued by SIEBEL ?

    Hi,
    We have developed BI Siebel 10.1.3.3. application.
    One of the requirement is to persist/store in the database real SQL statement issued by BI Dashboards/Answers.
    The best solution would be having acces on-line to cursor cache.
    Could someone please tell me how to achive this ?
    Regards,
    Cezary

    Sounds like you're looking for Usage Tracking.
    OBIEE Server Administration Guide – Pages: 220
    OBIEE Installation and Configuration Guide – Pages: 229
    And this post here;
    http://oraclebizint.wordpress.com/2007/08/14/usage-tracking-in-obi-ee/
    A.

  • How to execute SQL statement with oracle jdev

    Please I'm a beginner in oracle jdeveloper. I want to know how to use and execute sql statememt within oracle Jdeveloper 10 g release 3 to manipulate objects in oracle database. I want for e.g. to Enable/disable trigger using sql statement "ALTER TRIGGER trigername DISABLE" explicitly. Please tell me how to proceed.
    i am sure you can help me
    Sincerly yours.

    Hi,
    Using following tutorial http://www.oracle.com/technology/obe/ADF_tutorial_1013/10131/index.htm
    you will found how to connect from Jdev to a database (chapter 1 or 2 ?). Then you just have to go under Tool>SQL*Plus or Tools>SQL Worksheet depending on what you need.
    Luck,
    Tif

  • How to execute sql statement under bat file?

    I want to execute following statement
    C:\>sqlplus /nolog
    SQL> conn scott/tiger
    SQL> select * from tab;
    I know I can realize it as following test.bat and testdb.sql file
    test.bat is follows:
    sqlplus /nolog @testdb.sql
    testdb.sql is follows:
    conn scott/tiger
    select * from tab;
    Now I don't want to use sql file,I only want to use bat file,like follows:
    test.bat is follows:
    sqlplus /nolog
    conn scott/tiger
    select * from tab;
    when I run test.bat,I find only sqlplus /nolog statement execute,the other statements don't execute.
    1)I want to know whether there is a method to execute sql statement only by bat file without a sql file? How to realize it?
    2)If I call sql file,how to hide passord of user? Because I don't want to other persons know scott password,if I use conn scott/tiger in testdb.sql,other person can see testdb.sql and know the password. Is there a good method to avoid?
    Thanks!

    I'm running *NIX, but works the same on Windows
    bcm@bcm-laptop:~$ cat here.sh
    sqlplus dbadmin/admindb << EOF
    select count(*) from user_objects;
    exit
    EOF
    bcm@bcm-laptop:~$ sh here.sh
    SQL*Plus: Release 11.2.0.1.0 Production on Mon May 17 18:14:09 2010
    Copyright (c) 1982, 2009, Oracle.  All rights reserved.
    Connected to:
    Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
    With the Partitioning, OLAP, Data Mining and Real Application Testing options
    SQL>
      COUNT(*)
          9
    SQL> Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
    With the Partitioning, OLAP, Data Mining and Real Application Testing options
    bcm@bcm-laptop:~$ Edited by: sb92075 on May 17, 2010 6:15 PM

  • How to process sql statements stored in a table

    I have a rule table that contain rule_type, rule_status and rule_condition. The rule condition is a sql statement. In a report I need to be able to expand this condtion based on the status selected. E.g When rule status is terminated the rule_condition is as below. When a user pick terminated status, I need to be able to go to the table and expand the sql statement. Another example is active status.
    RULE_STATUS TERMINATED
    SELECT leaseid
    FROM leatatt
    WHERE txtattid = 'LEAS END'
    and value = 'TERMINATED'
    RULE_STATUS ACTIVE
    SELECT leaseid
    FROM lease
    WHERE redoc_class = 'MASTER'
    AND TRUNC(SYSDATE) <=
    NVL(TRUNC(enddate),TRUNC(SYSDATE)+1)
    AND functional_status IN ('ACTIVE','OVERHOLD')
    Any suggestion will be appreciated.

    Please refer to
    http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:246014735810
    I am sure you would be twist this to bring it in to your use.
    <PRE>
    the proper way to do this is to NOT use a PLSQL table type but to use a SQL Object Type
    instead. It would look like this:
    [email protected]> create or replace type myScalarType as object
    2 ( x int,
    3 y date,
    4 z varchar2(25)
    5 )
    6 /
    Type created.
    [email protected]> create or replace type myTableType as table of myScalarType;
    2 /
    Type created.
    [email protected]> create or replace
    2 function demo_proc( p_start_row in number,
    3 p_end_row in number )
    4 return myTableType
    5 as
    6 l_data myTableType := myTableType();
    7 l_cnt number default 0;
    8 begin
    9 for x in ( select * from emp order by sal desc )
    10 loop
    11 l_cnt := l_cnt + 1;
    12 if ( l_cnt >= p_start_row )
    13 then
    14 l_data.extend;
    15 l_data(l_data.count) :=
    16 myScalarType( x.empno,
    17 x.hiredate,
    18 x.ename );
    19 end if;
    20 exit when l_cnt = p_end_row;
    21 end loop;
    22
    23 return l_data;
    24 end;
    25 /
    Function created.
    [email protected]> select *
    2 from the ( select cast( demo_proc(2,6) as mytableType )
    3 from dual ) a
    4 /
    X Y Z
    7788 09-DEC-82 SCOTT
    7902 03-DEC-81 FORD
    7566 02-APR-81 JONES
    7698 01-MAY-81 BLAKE
    7782 09-JUN-81 CLARK
    [email protected]>
    </PRE>

  • How to find SQL Statements for BW queries ?

    Experts,
    Is there a way, we can see what SQL statement BW queries creates ?
    please Help.

    Hi,
    use sql trace: transaction ST05.
    ask your database admin. He can control the database session.
    => for oracle: you can see the session also in the sap gui.
    Sven

  • How to write Sql statement for M:M relationship set?

    If theres two Entity sets "Department" and "Employee".....
    Department Entity contains this attribute dno,dname,address etc and
    "Employee" entity contain attribute like Empno,Empname,date,time etc
    and theres Many to Many relationship between Employee and Deapartment Entity set,i.e.each employee can work in any department, and each department has at least one employee (Many to Many relationship)
    What should be the SQL statement to create table for Many to Many relationship sets for Employee and Department set..
    Any helps will be appreciated.
    Femi

    create 3 tables: employee, department and empdept
    in the empdept table you reference foreign keys from the 2 other tables. so if my employee id was 42 and I work for departments 1,2 and 3, this table would look like this:
    emp_fk | dept_fk
    42           1
    42           2
    42           3

  • How to Retrieve SQL Statements in RDF Reports

    I need to retrieve the SQL statements from my reports without having to call each of them up in Reports Builder. The reports are in binary (RDF format). Does anyone know of a way to do this?

    Hello,
    Convert your RDF into a text format :
    - REX
    - XML/HTML/JSP if your are using Reports 9.0.x or greater)
    and search in these text files .
    Regards

Maybe you are looking for

  • Some movie files will suddenly start to lag or stutter?

    Any idea why some movie files will suddenly start to lag or stutter? You start playing a file and all is ok, but then about 2 minutes in it starts to play up. If you pause it and then press play again it will be ok for about a minute then play up aga

  • Bilingual support of Apache Lenya

    Dear All We are using Apache Lenya content management tool for our web based project and it supports internationalisation also. But my requirement is, i need to display user interface content in English by default and Marathi (One of the Indian Regio

  • Problems with getting internet help in Elements 2.0

    I have Windows XP and Photoshop Elements 2.0. When I opened up the Elements program it gave an error http://cgi..tform=ODLLVER=2.8.3.3AOMVER=2.8.3.3 check Internet Control Panel. Not sure what it is saying to do. The program seems to be working excep

  • Set the cursor on inputfield

    Hi, I have several input field in my MI7.1 application for PDA develop using NWDS 7.1 . Is that possible for me to set the cursor on the application. For example after user scan the product code the cursor will move to quantity input field. I try use

  • Aktivierung ohne micro sim?

    Liebe Apple-Gemeinde, ein leidlich bekanntes Problem wahrscheinlich... Jetzt habe ich mich gut 2 Wochen auf mein iphone 4s gefreut und dabei übersehen, bei meinem Telefonanbieter 1und1 rechtzeitig eine Micro Sim zu beantragen. Das ist zwar heute Nach