Help required in writning sql

i am new to sql and have to write following program
my tables r
department     
dept_id     location
1     London
2     New York
3     Singapore
4     Tokyo
employee               
emp_id     dept_id     salary     tier_id
1     2     20000     4
2     4     200000     1
3     3     25000     4
4     1     60000     2
5     1     30000     3
tier     
tier_id     tier_name
1     Director
2     Manager
3     Analyst
4     Intern
I need to write
1.the DDL to create the following three tables and the DML to insert the data into the table. Create a sequence for the ID field on all three tables and use the sequence in the DML. The DDL to create the tables should include the logical referential integrity.
2.the PL/SQL to create two stored procedures in a package. The first procedure will take in an department ID and will return both the current timestamp and a list of the different distinct tiers belonging to that department ID. These will be returned as two separate parameters.
3.The second stored procedure will take in a tier ID and provide back the second highest salary for that tier.
4. the syntax to add a modified_time field to all three tables as a timestamp, and populate this field with the current timestamp.
4.the syntax to drop all three tables, sequences and the package as commented out in the script.
Plz help

user10502390 wrote:
atleast help in writing stored procedure as i have no idea abt ithttp://www.oracle.com/pls/db112/homepage
http://download.oracle.com/docs/cd/E11882_01/appdev.112/e10766/toc.htm
http://download.oracle.com/docs/cd/E11882_01/appdev.112/e10766/tdddg_subprograms.htm#CIHDFDJG
http://download.oracle.com/docs/cd/E11882_01/appdev.112/e10766/tdddg_subprograms.htm#BABDHFAC
http://download.oracle.com/docs/cd/E11882_01/appdev.112/e10472/toc.htm

Similar Messages

  • Help required in developing SQL developer extension

    Hi,
    We have a requirement to develop an extension for Sql Developer. The requirement matches the Reports framework in Sql Developer.
    We need to have a separate dock as in reports where we can navigate through the tree and execute some predefined queries.
    I implemented this using the Docking Sample of Sql Developer extensions. I am able to show a separate dock with the tree hieararchy of the nodes and adding context menus to the nodes.
    But , the problem is how do we integrate this UI with the queries and how do we prompt the user to select the connections and other bind variables.
    We can do this by using an XML file and importing it in the reports. But, we need a separate dock for our functionality.
    I tried modifying the reports API by obtaining the code from the oracle.sqldeveloper.report.jar . But , facing problems while compiling the modified code to a jar.
    Any help in this regard is appreciated.
    Edited by: 883431 on Sep 8, 2011 12:32 AM

    Sorry for that,
    Here is what I did,
    Create a variable for posting period
    Put posting period in column.
    Create 2 selections for the KF.
    Restrict 1st sel from Jan – Variable-1
    Restrict 2nd sel from Variable – Dec

  • Help required to build SQL loader control file

    I have a table, That we need to load using SQL loader.
    table structure is --
    <emp_id>,<first_name>,<middle_name>,<last_name>,<sal>
    The structure of flat file is like below,
    <emp_id>|<emp_name>|<sal>
    <emp_name> field can contain space to define first name, middle name and last name,
    if no space is there means we only need to load first name. and one space means First and last name should load.
    Sample flat file--
    1001|Ram|10000
    1002|Syam Kumar Sharma|20000
    1003|Jadu Prashad|15000
    Please help me out to build the control file.
    Thanks in Advance

    Means, can use DBMS_SCHEDULER for loading data ?Yes, you can create procedures for that and let the scheduler execute them on the desired interval
    (you can even execute OS commands through DBMS_SCHEDULER).
    Read about it here:
    http://www.oracle.com/pls/db102/search?word=DBMS_SCHEDULER&partno=
    http://www.oracle-base.com/articles/10g/Scheduler10g.php
    By the way, instead of using sqlloader why not switch to using external tables?
    http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:6611962171229
    http://www.oracle-base.com/articles/9i/SQLNewFeatures9i.php#ExternalTables
    A few other approaches (pre 10g)
    http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:2048340300346698595
    http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:3084681089099

  • Help required for update SQL

    Hi Guys,
    I am looking for some help to frame the update query.
    I have two tables temp_1 and temp_2.
    I want to update temp_2 based on data from temp_1. However i do not want to make an update where temp_1 has null value.
    One approach i can think of is creating two different update statements but is there any chance to get it done through
    only one statement. Also i would like to add here that temP_1 has 250K data and i going to make update on approx 500K
    rows from temp_2. So i need to look from performance point of view as well.
    Temp_1                       temp_2
    Col1   Col2  Col3        col1     col2    col3
    1 abc   abc                  1        null    null
    2 abc   null                  2         xyz     xyz
    3 null  null                   3          xyz     null
    After update i am looking forward to get data in below format.
    temp_2
    col1     col2    col3
    1        abc     abc
    2        abc     xyz
    3        xyz     null  

    USE TESTdb
    go
    create table express (col1 int, col2 varchar(25), col3 varchar(25))
    go
    create table express2 (col1 int, col2 varchar(25), col3 varchar(25))
    go
    insert into express values (1,'abc','abc'),(2,'abc',null),(3,null,null)
    insert into express2 values (1,null,null),(2,'xyz','xyz'),(3,'xyz',null)
    select * from express
    select * from express2
    update express2
    set col2= case when x.col2 is null and e.col2 is not null then e.col2
    else x.col2
    end ,
    col3= case when x.col3 is null and e.col3 is not null then e.col3
    else x.col3
    end
    from express e inner join express2 x on e.col1=x.col1
    --drop table express, express2
    ebro

  • Help required in connecting sql devloper to db 11g

    any please tell me how to connect to the database 11g using SQL developer
    What r the configuration settings to be used

    For a basic connection (using the jdbc thin driver) you need to specify the hostname of the database server, the database serveice name and the port number (probably 1521). You also need to provide a username and password.

  • Help Required with PL/SQL loading logic

    Hi All,
    We have a simple pl/sql code which does loading(insertions) of records into the table. This pl/sql code actually refers to an translation website URL(microsoft based) and inserts the translated text into our table. What happens is sometimes this URL gets blocked out due to some issue. So we are forced to restart our entire operation of loading once again. Actually we have a commit at the end(outside the loop). on the other hand we cant keep commit inside the loop as it may pose an overhead to performance since its commiting once every insert happens.
    What we are expecting is something like this. Say we have 10,000 records. the loading fails at 5500 record. next time when we start again we want to start from 5501 record and NOT from beginning. In informatica kind of ETL tools we have an option to do this. However not sure if we can do this through PL/SQL.
    we thought of keeping counter variable and keep it incrementing for each and every insert happens. but before doing this we have to order by our table according to primary key. This is taking huge amount of time since the table is very big.
    can you please tell any alternative to this?
    Regards,
    Paul

    If I understand correctly, you are doing something as follows:
    // process a defined data set
    for c in (select .. some data... ) 
    loop
        // translate the data (via a web service call)
        Translate( c, translatedOutput )
        // insert the translated data
        insert into some_table translatedOutput
    end loop
    commitIn principle, nothing wrong with this approach. And yes, committing inside the loop for every x number of rows will increase the complexity of code and could perhaps violate ANSI SQL standards of fetching across commits.
    A better approach would be to consider parallelising this process. Run multiple copies of that code - but provide each copy of the code with a small and unique data set to process. So instead of doing 10,000 rows in serial, you schedule a 100 jobs and give each a unique set of a 100 rows to translate.
    Let's say your job queue size is set to 20. This means up to 20 of these processes will run in parallel. Should one fail, the job manager will automatically reschedule it for execution (up to 16 times after which it will be marked as broken).
    So not only does this type of approach enables you spread the processing load, it also enables you to scale your processing (you can handle much larger data volumes like this, and more powerful server h/w will enable you to use more parallel processes). In addition, restart is automated courtesy of the Oracle job manager.
    Compare this type approach with committing inside a loop.. The latter buys you what ito flexibility and performance and scalability? Nothing really - it only makes the process a lot more complex as it needs to be able to correctly restart after a failure. You will not be able to process bigger volumes of data. You will not be able to increase existing performance.
    One needs to carefully consider the approach used to processing data - serialisation is inherently limited. Restarting serialised processes is difficult and complex.

  • XSLT mapping Help Required.

    XSLT mapping Help Required.
    Hi Experts,
    I am New to XSLT Mapping. I am practising the below Example:
    InputXML File:
    <?xml version="1.0" encoding="UTF-8"?>
    <?xml-stylesheet type="text/xsl" href="Persons111.xsl"?>
    <ns0:MT_XSLT_Source xmlns:ns0="http://XYZ.com/gen">
    <Person>
    <FirstName>Anshul</FirstName>
    <LastName>Chowdhary</LastName>
    <Gender>Male</Gender>
    <Address>
    <Street>2nd Main</Street>
    <Houseno>83/b</Houseno>
    <City>Mysore</City>
    </Address> </Person>
    </ns0:MT_XSLT_Source>
    XSL StyleSheet File:
    <?xml version='1.0' encoding="UTF-8"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ns0="http://XYZ.com/Gen"
    Xmlns:ns1=”http://XYZ.com/Test”>
    <xsl:template match="/">
    <ns1:MT_XSLT_Target>
    <Title> <xsl:value-of select="ns0:MT_XSLT_Source/Person/Gender"/> </Title>
    <Name> <xsl:value-of select="concat(concat(ns0:MT_XSLT_Source/Person/FirstName,' '), ns0:MT_XSLT_Source/Person/LastName)"/>
    </Name>
    <Street> <xsl:value-of select="concat(concat(ns0:Mt_XSLT_Source/Person/Address/Houseno,' '),
    ns0:Mt_XSLT_Source/Person/Address/Street)"/> </Street>
    <City> <xsl:value-of select="ns0:Mt_XSLT_Source/Person/Address/City"/> </City>
    </ns1:MT_XSLT_Target>
    </xsl:template>
    </xsl:stylesheet>
    The Desired Output shuold be:
    <?xml version="1.0" encoding="UTF-8"?>
    <ns1:MT_XSLT_Target xmlns:ns1="http://XYZ.com/Test">
    <Title>Male</Title>
    <Name>Anshul Chowdhary</Name>
    <Street>83/b 2nd Main</Street>
    <City>Mysore</City>
    </ns1:MT_XSLT_Target>
    I have refered the xsl in xml and i am getting the below Oupt in a Single line like this:
    Anshul Chowdhary Male 2nd Main 83/b Mysore
    I am Unable to display in Target XML Fomrat as shown above. Please check and do the needful.
    Regards,
    GIRIDHAR

    Hi,
    I have used below for testing.
    Input xml:
    <?xml version="1.0" encoding="UTF-8"?>
    <?xml-stylesheet type="text/xsl" href="Persons111.xsl"?>
    <ns0:MT_XSLT_Source xmlns:ns0="http://XYZ.com/gen">
    <Person>
    <FirstName>Anshul</FirstName>
    <LastName>Chowdhary</LastName>
    <Gender>Male</Gender>
    <Address>
    <Street>2nd Main</Street>
    <Houseno>83/b</Houseno>
    <City>Mysore</City>
    </Address> </Person>
    </ns0:MT_XSLT_Source>
    xsl code:
    <?xml version='1.0' encoding="UTF-8"?> 
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ns0="http://XYZ.com/gen" 
        xmlns:ns1="http://XYZ.com/Test"> 
        <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/> 
        <xsl:template match="/"> 
            <ns1:MT_XSLT_Target> 
                <Title> <xsl:value-of select="ns0:MT_XSLT_Source/Person/Gender"/> </Title> 
                <Name> <xsl:value-of select="concat(concat(ns0:MT_XSLT_Source/Person/FirstName,' '), ns0:MT_XSLT_Source/Person/LastName)"/> 
                </Name> 
                <Street> <xsl:value-of select="concat(concat(/ns0:MT_XSLT_Source/Person/Address/Houseno,' '), 
                    /ns0:MT_XSLT_Source/Person/Address/Street)"/> </Street> 
                <City> <xsl:value-of select="/ns0:MT_XSLT_Source/Person/Address/City"/> </City> 
            </ns1:MT_XSLT_Target> 
        </xsl:template> 
    </xsl:stylesheet>
    For testing in PI ,change the extension from .txt to .xsl and zip it and upload into PI as an imported archive .
    Regards
    Venkat

  • Urgent help required: Query regarding LC Variables

    Hi All
    Sometime earlier I was working on a performance issue raised by a customer. It was shell script that was taking almost 8-9 hrs to complete. During my research I came across a fact that there were some variables which were not set, the LC variables were impacting the sort funnel operations because of which the script was taking a long time to execute.
    I asked them to export the following commands, after which the program went on smoothly and finished in a couple of mins:
    export LC_COLLATE=en_US.ISO8859-1
    export LC_MESSAGES=C
    export LC_MONETARY=en_US.ISO8859-1
    export LC_MONETARY=en_US.ISO8859-1
    export HZ=100
    export LC_CTYPE=en_US.ISO8859-1
    export LANG=en_US.UTF-8
    Later I did recover that setting the LC_COLLATE to C, is not helping and the program was again taking a lot of time. Few questions that I want to ask are:
    1. Can someone please tell me, what each of these variable mean and how these values make a difference.
    2. When I exported LC_COLLATE=en_US.ISO8859-1, it worked fine, but when i tried with the defalut value LC_COLLATE=C, then why the program didnt work.
    As this issue is still going on, hence I would request All to provide their valuable inputs and let me know as much as possible.
    Appreciate your help in this regard.
    Thanks
    Amit
    Hi All
    A new development in this regard. The customer has send us a screen shot in which they were trying to export the locale variable using the commands which I have pasted above. I can see in the screen shot that while exporting LC_COLLATE and LC_TYPE, they get a message that ""ksh: export: couldn't set locale correctly"".
    Request everyone to please give their inputs as it's a bit urgent.
    Thanks for all the help in advance.
    Thanks
    Amit
    Some help required please...
    Edited by: amitsinhaengg on Jul 22, 2009 2:03 AM
    Edited by: amitsinhaengg on Jul 22, 2009 2:06 AM

    LC_CTYPE
    Controls the behavior of character handling functions.
    LC_TIME
    Specifies date and time formats, including month names, days of the week, and common full and abbreviated representations.
    LC_MONETARY
    Specifies monetary formats, including the currency symbol for the locale, thousands separator, sign position, the number of fractional digits, and so forth.
    LC_NUMERIC
    Specifies the decimal delimiter (or radix character), the thousands separator, and the grouping.
    LC_COLLATE
    Specifies a collation order and regular expression definition for the locale.
    LC_MESSAGES
    Specifies the language in which the localized messages are written, and affirmative and negative responses of the locale (yes and no strings and expressions).
    You can use command
    # locale -k LC_CTYPE
    to see more detail about each type.

  • Need help in rewriting a sql query

    Can any one please tell me if there is any utility that can help me correcting the sql I have I need to tune the query as its taking lot of time. I want to use some tool that will help me re-formating the query.
    Any help in this regard will be highly appreciated.

    If you think that Oracle SQL Tuning Tools like SQL Tuning Advisor and SQL Access Advisor are not helping.
    You might look into thrid party tools like Quest- SQL Navigator and TOAD.
    But I don't advise this based on the following:
    Re: Oracle Third Party Tools and Oracle Database
    Oracle have enough tools of its own to satisfy the various needs.
    Adith

  • Help required - Sales order item is partially delivered but the item grayed

    I have a sales order 123 having say item10 with qty 1, item20 with qty 10 , item 30 qty 12
    Item 1 confirmed qty 1 and delivered qty is 1
    Item 2 confirmed qty 10 and delivered qty 10
    Item 3 confirmed qty 1 and delivered qty is 1
    Now the item3 still has open requirements of 11 to be delivered. But the item is GRAYED OUT already.
    even if I do ATP the qty is not confirming for the remaining 11 pieces.
    Why is that? How to make that item out from GRAY.
    How to confirm the remaining 11 qty for that item.
    Help required as early as possible.
    Appreciate ur help guys
    Radha

    hi Radha, how are you ?
         ---the partial deliveries in master data must have not been mentioned.
         ---the deliveries should be upto target quantity.
         ---check order type, item category and schedule line category.
         ---check unrestricted stock availability.
    thank you
    regards
    Khera.

  • Search Help with in a serach help required in SRM 4.0

    Hi,                                                     
    Requirement: Search help required for Product Category field in the Search help for Product(BBPH_PRODUCT) in SRM portal.
    This search help is used in Create shopping Cart transaction. The hyper link on Internal Goods/Services leads to the search help BBPH_PRODUCT. 
    My analysis:           
    The field Product Category (CATEGORY_ID) has search help(COM_CAT_HIER) attached to its data element. When I single test the search help BBPH_PRODUCT in SAP GUI,I can see the search help for field product category in the selection dialogue box. However the same does not appear on the corresponding screen in HTML.
    Please let me know whether I need to do some thing to make the search help appear on the HTML screen?
    With Regards,         
    Prakash Kamath

    Hi Prakash,
    I have the same problem but with another field. Unloading point. Could you please tell me how did you solve this problem with displaying F4 help on html/ SRM portal?
    Thank you very much.
    Best regards,
    Danijela ZIvanovic

  • Help needed in framing SQL query.

    Hi,
    I have table having following schema:
    PRODUCT_ID         INT
    DATE                   DATETIME
    ITEMS_SOLD         INT
    This table contains data for a week (sunday to saturday). I want to write an SQL query to get (filter out) PRODUCT_ID of products which has same no. of ITEMS_SOLD for all 7 days. Also for given PRODUCT_ID I need to find the longest period of successive days where the no. of ITEMS_SOLD is same for all days in this period. Eg.(PRODUCT_ID 23 was sold as following along the week in no. of units sold: 4,6,6,6,6,7,4 .So the longest period is *4 days* from Monday to Thursday.) The first condition is special case of second condition where no. of days is 7.
    Any help to get the SQL query will be appreciated.
    Thanks,
    Akshay.

    PRODUCT_ID      DATE           ITEMS_SOLD
    1          10/10/2011     3
    1          11/10/2011     3
    1          12/10/2011     3
    1          13/10/2011     3
    1           16/10/2011     5
    2          10/10/2011     4
    2           11/10/2011     4
    2          12/10/2011     4
    2          13/10/2011     4
    2           14/10/2011     4
    2          15/10/2011     4
    2          16/10/2011     4
    Output:
    PRODUCT_ID ITEMS_SOLD NO_OF_DAYS
    1          3                4     
    2          4               7
    Explanation of results:
    The table to be queried contains data for 1 week: from 10/10/2011(Sunday) to 16/10/2011(Saturday). Now, product with PRODUCT_ID '1' was sold on dates 10,11,12,13,16. Out of these 5 days 3 units were sold on 4 successive days (from 10-13). So output should be like :
    PRODUCT_ID ITEMS_SOLD NO_OF_DAYS
    1          3               4     
    as longest period of successive days is 4 where same no. of units were sold i.e 3 units (other period is of 1 day on 16th ).
    For PRODUCT_ID 2 we have only one period of 7 days where 4 units were sold each day. So we output :
    PRODUCT_ID ITEMS_SOLD NO_OF_DAYS
    2           4               7
    Other case where same PRODUCT_ID have different units sold on each day should be ignored.
    I hope that clarifies the problem more. Let me know in case I have missed out anything which should have been mentioned.
    -Akshay.

  • Help required with Photoshop Elements 4.0 this has been installed on my new Toshiba laptop with windows 8.1 for some 18 months and operating well. Now it will not open, message pops up saying "attempt to access invalid address" then "application not respo

    Help required with Photoshop Elements 4.0 this has been installed on my new Toshiba laptop with windows 8.1 for some 18 months and operating well. Now it will not open, message pops up saying “attempt to access invalid address” then “application not responding” Suggestions how to access would be much appreciated. Tks. Stuart

    What is the size of your hard disk?  PSE 4 is a very old program and I suspect it is not able to access the entire hard disk on your machine.  Just a thought here.

  • Help require with installing Adobe Acrobat onto my Macbook Pro Retina.

    Help require with installing Adobe Acrobat onto my Macbook Pro Retina.
    I have successfully installed all of my creative cloud apps with the exception being acrobat.
    I cannot print from Indesign to PDF.
    I have unistalled, reinstalled and still no Adobe Acrobat.
    I now have to go back to Windows 8 and create the PDF's there.
    Any one know how to get around this issue?
    Thanks in advance
    Kelvin

    OSX has effectively killed the ability to print to pdf, (print to pdf eliminates most of the "Rich features" of current pdf).
    Export from InDesign, always, excpet for the 1% of the time where you know why print to pdf would produce a better result.

  • Help Required for Denormalization

    Hi Guys ,
    Need help in denormalising table:
    SQL > DESC SAMPLE
    Name Null? Type
    CNO VARCHAR2(10)
    CTYPE VARCHAR2(1)
    CED DATE
    EED DATE
    STATUS VARCHAR2(2)
    REASON VARCHAR2(3)
    CFROM DATE
    CTO DATE
    My data looks like this
    CNO C CED EED ST REA CFROM CTO
    123456a A 03-JUN-05 31-DEC-99 01 023 02-JUN-05 07-MAY-08
    123456a B 03-JUN-05 31-DEC-99 02 012 17-MAY-06 27-OCT-82
    123456a C 01-JAN-07 31-DEC-99 03 001 12-JUL-08 23-NOV-08
    I want to denormalise that data into as per the following record
    SQL> DESC NEW_SAMPLE
    Name Null? Type
    CNO VARCHAR2(10)
    ACED DATE
    AEED DATE
    ASTATUS VARCHAR2(2)
    AREASON VARCHAR2(3)
    ACFROM DATE
    ACTO DATE
    BCED DATE
    BEED DATE
    BSTATUS VARCHAR2(2)
    BREASON VARCHAR2(3)
    BCFROM DATE
    BCTO DATE
    CCED DATE
    CEED DATE
    CSTATUS VARCHAR2(2)
    CREASON VARCHAR2(3)
    CCFROM DATE
    CCTO DATE
    SAMPLE RECORD LOOKS LIKE THIS :
    CNO ACED AEED AST AREA ACFROM ACTO
    ----- ----- ----------- ------------- ------------BCED BEED BST BREA BCFROM BCTO
    -------- --------- --------- --------- ------ ------CCED CEED CST CREA CCFROM CCTO
    123456a 03-JUN-05 31-DEC-99 01 023 02-JUN-05 07-MAY-08
    03-JUN-05 31-DEC-99 02 012 17-MAY-06 27-OCT-82
    01-JAN-07 31-DEC-99 03 001 12-JUL-08 23-NOV-08
    I mean i want all the columns in a single table , so some one please guide me how should i start inserting the data into new table . Please help me with Sql i should be writing to insert the data from the existing table.
    Thanks in Advance.
    Regards,
    Venu Kadiyala
    Message was edited by:
    Kadiyala,Venu

    1.
    CTAS new_sample with columns: CNO, A*, B,*, C*
    select only A* columns where CTYPE='A'
    2.
    insert into new_sample with columns with B*
    with subquery from old_sample values (B*)
    where old.CNO = new.CNO and old.CTYPE='B'
    3.
    insert into new_sample with columns with C*
    with subquery from old_sample values (C*)
    where old.CNO = new.CNO and old.CTYPE='C'

Maybe you are looking for