Stored procedure help needed please!

dsds

hello ive an assignment due but ive hit a brick wall, would anyone be as kind to help me?
ShareTraders LTD is an online share brokerage which allows its customer to trade shares on the US stock market.  Customers can either sell or buy shares – the sales price depends on the curently quoted prices in the share table.  The below ERD
shows a section of their database that refers to their customers who trade shares online.
Funds are categorised into different categories.
Customers may limit their exposure to a particular category of fund.
Customers fund their share purchases through funds.
Customers may limit their exposure to a particular category of fund.
Shares are grouped into different categories.
Customer trades are tracked in their portfolios.
The shares that the customer’s trade are recorded in their portfolios.
Staff are authorised to change the share prices of particular categories of shares.
Staff are authorised to change the share prices of particular categories of shares.
TSQL à Stored procedure
Create a stored procedure (call it
Assign1) which will
insert a purchase of shares into the CustomerPortfolioTBL for a customer. The data that will be passed to the stored procedure is: the CustomerID, the ShareID, and the TransactionAmount.
The data for the other columns in the CustomerPortfolioTBL will be got as follows
TransactionID
à make sure that this column is an identity column which will automatically generate the next TransactionID.
TransactionType – this column will be filled by your sproc with the word “Purchase”.
SharePrice
à the price will be read from the share SellPrice column in the ShareTBl for that ShareID.
TransactionDate
à this column will be filled by your sproc with todays date
à use the GetDate() function.
Business Requirement
Customers are not allowed to purchase more than 5 times in the current month. Your sproc must therefore:-
Count the number of purchases the customer has made this month
à use the Month() and the GetDate() functions.
If the no of purchases is greater than or equal to 5 your sproc must send an error message of “Sorry
purchase is refused 5 purchases have been made this month”
Customers cannot spend over their exposure limit for a particular share category – get this from the CustomerExposureTBl.  Your sproc must therefore:-
Read in to an internal variable the exposure limit from the CustomerExposureTBl for the inputted CustomerID.
Add up all the transaction amount of shares that the customer has purchases (TransactionType = purchase) for shares whose category is the same as the share
being purchased).  Put this calculation into an internal variable.
Add up all the transaction amount of shares that the customer has sold  (TransactionType = sale) for shares whose category is the same as the share being
purchased).  Put this calculation into an internal variable.
iv) 
If ((Total Purchases
of share in this category – Total Sales of share in this category) + TransactionAmount) is greater than  exposure limit your sproc
must send an error message of “Sorry purchase is refused Exposure limit is breached”
Tables
http://tinypic.com/r/2nvqt88/8
This reads like you just want someone to do your homework for you. Could you post the following?
What have you written so far? Please include the code in your reply.
Where are you getting stuck specifically?
Mark as answer or vote as helpful if you find it useful | Igor

Similar Messages

  • SQL Server Stored procedure help needed

    I want to write a stored procedure to get result like
    this....how can i do?.
    Result needed from stored procedure.......
    lastname,firstname,logout_time,activity,score,pass/fail
    Tables....
    select activity_id
    ,login_time,logout_time,q_id,r_id,correct,activity
    from activity_log
    activity_log got multiple records....this is just dump all
    the activity from test questions.
    select user_id,firstname,lastname
    from users
    Queries inside the stored procedure.......
    select b.lastname,b.firstname,
    a.activity_id,a.login_time, a.logout_time
    from activity_log a, users b
    where a.activity_id = b.user_id
    group by user_id,lastname,firstname,login_time,logout_time
    select activity
    from activity_log
    where activity_id= 'a.activity_id' and activity is not NULL
    select sum(convert(int,correct,1)) as score
    from activity_log
    where activity_id='a.activity_id'
    if activity is C1
    select r_id,correct
    from activity_log
    where q_id = '10' and activity_id = 'a.activity_id'
    "Question 10 missed."
    select r_id,correct
    from activity_log
    where q_id = '20' and activity_id = 'a.activity_id'
    "Question 20 missed."
    if score gt 50
    pass
    else
    fail
    end if
    end if
    if activity is C2
    select r_id,correct
    from activity_log
    where q_id = '30' and activity_id = 'a.activity_id'
    "Question 30 missed."
    select r_id,correct
    from activity_log
    where q_id = '40' and activity_id = 'a.activity_id'
    "Question 40 missed."
    if score gt 50
    pass
    else
    fail
    end if
    end if

    Thanks. Please see now...i updated my posting.
    SQL Server 2000.
    Please see my tables...
    select activity_id
    ,login_time,logout_time,q_id,r_id,correct,activity
    from activity_log
    select user_id,firstname,lastname
    from users

  • Stored Procedure vs Views, Please clearify.

    Hi Gents,
    I am working on client side as a crystal report developer, the client has several applications linked to each other by some means and each application has its own database. They have created a common database called Reporting Layer, the database consists of only stored procedures, that is the stored procedures are collecting data from all the databases and making up a dataset. Now I need to develop reports using these stored procedures. Consider these stored procedures as tables for now.
    If you have got the basics, here is my concern about using stored procedures for the reports.
    Example : Say I need to refer 3 stored procedures for my report to get the required data then I need to call or attach all the three stored procedures with crystal and link them properly to get the required data. The question here is, say I need only 2 columns from each stored procedure then I simply drag the columns needed and drop on the reports...!!!
    So if I had a view instead of a stored procedure then I could refer 3 views in the command object or might have written a stored procedure to return the results containing only the columns the report is ment for.
    Select v1.a, v1.b, v2.a, v2.b, v3.a, v3.b from v1,v2,v3 where v1.id = v2.id and v1.id = v3.id
    or
    Select v1.a, v1.b, v2.a, v2.b, v3.a, v3.b from v1 inner join v2 on v1.id = v2.id inner join v3 on v1.id = v3.id
    I want to explain this to my client and ask them to convert all the stored procedures to views, please suggest what can I tell them ? And if you think that the method my client has opted that is of stored procedures is better than views then please explain in this scenario.
    Thanks
    -Azhar

    Hi Azhar,
    Not sure if you are in the right place, you would likely get a better description if you post your question to the Forums for which ever DB server you are using. They likely have more detailed info on the efficiencies of each.
    For Crystal Reports one possble scenario with using multiple Stored Proceedures (SP) is that each SP would or should be in it's on subreport. Unless you can link them, this will cause the SP to run each time that section is hit. Worst Example is if you put the subreport in the detail section for every record returned the subreport would run. If in the group header for each Group header condition met the subreport would run.
    Using them in a Command Object would work but not that efficient and would be better if you used one SP to get the data or use a database to save all the data into as you suggested and report directly off of it.
    As for the amount of data the SP returns CR may only ask for the fields used, depends on a few conditions, or it may have to get all of the data and filter out just the fields used in the report. Could be a big delay waiting for the SP to run and/or client side data filtering.
    As for Views all the data collection is done server side, same as an SP, but only one view would be required. Or you may want to create specific SP's for use in the reports and not use Command Objects but simply drop the SP into the Database Wizard as the data source. This way all data collection is done server side which is much more efficient and CR at filtering data.
    CR does not care if you use Views or SP's, we are simply sending the SQL to the server and waiting for the results. Which one is more efficient is more for that DB forum to answer.
    Hope this helps
    Don

  • Help needed please.. how do I remove my credit card from itunes? just discovered over $450 of charges when I looked at my email... Kids had no clue they were using our money and not their gift cards

    Help needed please.... I just discovered over $450 charges to my credit card from Itunes. The kids had no idea they were using our credit card and not their itunes gift cards and 4 year old just clicks on anything! I didnt save my credit card details so am a bit miffed at this... I cant find anywhere in itunes to remove it. Edit.. but not remove. Editing does not remove it.. HELP

    To Contact iTunes Customer Service and request assistance
    Use this Link  >  Apple  Support  iTunes Store  Contact
    Accepted forms of payment  >  http://support.apple.com/kb/HT5552
    Changing Account Information  >  http://support.apple.com/kb/HT1918

  • Help needed please, with Iphone stuck with apple picture and progress bar after software update attempted

    Help needed please, everytime I try to update the software version on my iphone it comes up with a message saying it could not be completed and is now frozen with the apple picture and progress bar on it. Do I unplug it and hope the macbook pro sees it again, I also stupidly did not back up before starting the download which I realise I will have to go back to the previous back up. This keeps happening, everytime I do this type of update, I'm starting to think I should just give up on updating my software on the Iphone. I thought it was happening because I was using a window based computer to do the updates, this time I used my Macbook Pro. Please somebody help

    ljm17 wrote:
    ...This keeps happening, everytime I do this type of update, I...
    Then you should know what you need to do... If you don't remember...
    See Here  >  http://support.apple.com/kb/HT1808

  • I recently had to restore my Iphone 4s and ever since I cannot double click the home button whilst the phone is locked and change my music. The controls come up and I can adjust the volume but I cannot change the songs. Help needed please!!

    I recently had to restore my Iphone 4s and ever since I cannot double click the home button whilst the phone is locked and change my music. The controls come up and I can adjust the volume but I cannot change the songs. Help needed please!!

    Have you guys been able to activate your iphone yet? I bought an iphone 4s from eBay and it worked fine, but the previous user had left some data on it, so last night I used the "erased all content and settings" to restore it to factory setting so I can start fresh and restore my backup. But now I'm stuck at the activation screen (I get the same "the activation server is temporarily unavailable")  and can't get it to activate, even if I use my old deactivated AT&T sim card (I'm on straighttalk now).
    I might try activating it with an active AT&T sim card from my fiancee's phone when she gets home, so I'll let you know how that works outs.
    If it's true that the server is down; anyone know when it will be back up again? Thanks in advance.
    iPhone 4s iOS 5.1.1 (9B206)
    Carrier AT&T 12.0
    Modem Firmware 2.0.12

  • Can someone help me diagnose a strange stored procedure performance issue please?

    I have a stored procedure (posted below) that returns message recommendations based upon the Yammer Networks you have selected. If I choose one network this query takes less than one second. If I choose another this query takes 9 - 12 seconds.
    /****** Object: StoredProcedure [dbo].[MessageView_GetOutOfContextRecommendations_LargeSet] Script Date: 2/18/2015 3:10:35 PM ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    CREATE PROCEDURE [dbo].[MessageView_GetOutOfContextRecommendations_LargeSet]
    -- Parameters
    @UserID int,
    @SourceMessageID int = 0
    AS
    BEGIN
    -- variable for @HomeNeworkUserID
    Declare @HomeNeworkUserID int
    -- Set the HomeNetworkID
    Set @HomeNeworkUserID = (Select HomeNetworkUserID From NetworkUser Where UserID = @UserID)
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.
    SET NOCOUNT ON
    -- Begin Select Statement
    Select Top 40 [CreatedDate],[FileDownloadUrl],[HasLinkOrAttachment],[ImagePreviewUrl],[LikesCount],[LinkFileName],[LinkType],[MessageID],[MessageSource],[MessageText],[MessageWebUrl],[NetworkID],[NetworkName],[PosterEmailAddress],[PosterFirstName],[PosterImageUrl],[PosterName],[PosterUserName],[PosterWebUrl],[RepliesCount],[Score],[SmallIconUrl],[Subjects],[SubjectsCount],[UserID]
    -- From View
    From [MessageView]
    -- Do Not Return Any Messages That Have Been Recommended To This User Already
    Where [MessageID] Not In (Select MessageID From MessageRecommendationHistory Where UserID = @UserID)
    -- Do Not Return Any Messages Created By This User
    And [UserID] != @UserID
    -- Do Not Return The MessageID
    And [MessageID] != @SourceMessageID
    -- Only return messages for the Networks the user has selected
    And [NetworkID] In (Select NetworkID From NetworkUser Where [HomeNetworkUserID] = @HomeNeworkUserID And [AllowRecommendations] = 1)
    -- Order By [MessageScore] and [MessageCreatedDate] in reverse order
    Order By [Score] desc, [CreatedDate] desc
    ENDThe Actual Execution Plan Shows up the same; there are more messages on the Network that is slow, 2800 versus 1,500 but the difference is ten times longer on the slow network.Is the fact I am doing a Top 40 what makes it slow? My first guess was to take the Order By Off and that didn't seem to make any difference.The execution plan is below, it takes 62% of the query to look up theIX_Message.Score which is the clustered index, so I thought this would be fast. Also the Clustered Index Seek for the User.UserID take 26%which seems high for what it is doing.
    I have indexes on every field that is queried on so I am kind of at a loss as to where to go next.
    It just seems strange because it is the same view being queried in both cases.
    I tried to run the SQL Server Tuning Wizard but it doesn't run on Azure SQL, and my problem doesn't occur on the data in my local database.
    Thanks for any guidance, I know a lot of the slowness is due to the lower tier Azure SQL we are using, many of the performance issues weren't noticed when were on the full SQL Server, but the other networks work extremely fast so it has to be something to
    with having more rows.
    In case you need the SQL for the View that I am querying it is:
    SET QUOTED_IDENTIFIER ON
    GO
    CREATE VIEW [dbo].[MessageView]
    AS
    SELECT M.UserID, M.MessageID, M.NetworkID, N.Name AS NetworkName, M.Subjects, M.SubjectsCount, M.RepliesCount, M.LikesCount, M.CreatedDate, M.MessageText, M.HasLinkOrAttachment, M.Score, M.WebUrl AS MessageWebUrl, U.UserName AS PosterUserName,
    U.Name AS PosterName, U.FirstName AS PosterFirstName, U.ImageUrl AS PosterImageUrl, U.EmailAddress AS PosterEmailAddress, U.WebUrl AS PosterWebUrl, M.MessageSource, M.ImagePreviewUrl, M.LinkFileName, M.FileDownloadUrl, M.LinkType, M.SmallIconUrl
    FROM dbo.Message AS M INNER JOIN
    dbo.Network AS N ON M.NetworkID = N.NetworkID INNER JOIN
    dbo.[User] AS U ON M.UserID = U.UserID
    GO
    The Network Table has an Index on Network ID, but it non clustered but I don't think that is the culprit.
    Corby

    I marked your response as answer because you gave me information I didn't have about the sort. I ended up rewriting the query to be a join instead of the In's and it improved dramatically, about one second on a very minimal Azure SQL database, and before
    it was 12 seconds on one network. We didn't notice the problem at all before we moved to Azure SQL, it was about one - three seconds at most.
    Here is the updated way that was much more efficient:
    CREATE PROCEDURE [dbo].[Procedure Name]
    -- Parameters
    @UserID int,
    @SourceMessageID int = 0
    AS
    BEGIN
    -- variable for @HomeNeworkUserID
    Declare @HomeNeworkUserID int
    -- Set the HomeNetworkID
    Set @HomeNeworkUserID = (Select HomeNetworkUserID From NetworkUser Where UserID = @UserID)
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.
    SET NOCOUNT ON
    ;With cteMessages As
    -- Begin Select Statement
    Select (Fields List)
    -- Join to Network Table
    From MessageView mv Inner Join NetworkUser nu on MV.NetworkID = nu.NetworKID -- Only Return Networks This User Has Selected
    Where nu.HomeNetworkUserID = @HomeNeworkUserID And AllowRecommendations = 1
    -- Do Not Return Any Messages Created By This User
    And mv.[UserID] != @UserID
    -- Do Not Return The MessageID
    And mv.[MessageID] != @SourceMessageID
    ), cteHistoryForThisUser As
    Select MessageID From MessageRecommendationHistory Where UserID = @UserID
    -- Begin Select Statement
    Select Top 40 (Fields List)
    -- Join to Network Table
    From cteMessages m Left Outer Join cteHistoryForThisUser h on m.MessageID = h.MessageID
    -- Do Not Return Any Items Where User Has Already been shown this Message
    Where h.MessageID Is Null
    -- An Order By Is Needed To Get The Best Content First
    Order By Score Desc
    END
    GO
    The Left Outer Join to test for null was the biggest improvement, but it also helped to join to the NetworkUser table instead of do the In sub query.

  • New Hard drive, can't access certain aspects. Help needed please

    Hi everyone.
    I have an HP Pavilion dv6-6052ea laptop.
    I've been having problems with the hard drive so got a new one installed.
    My main issues are since getting it back, I can't access any of the original HP installations etc (I've downloaded all the drivers I know about through HP).
    The 2 main things I'm missing are 2 things that came with the laptop.
    1: Beats Audio sound system 
    2: Video Graphics: AMD Radeon HD 6490M (1 GB DDR5)
    and I have no idea how to get them back. Can anyone help. Do I need to install specific drivers? I can't find any trace that they exist on my laptop now apart from the stickers on the laptop! Any help is greatly appreciated. 
    I never had any CD back ups for the laptop. I do have the old HP back up etc saved on a USB but I don't know enough about the folders and files to know what I need to look for. (I still have the old hardrive.)
    Again, any help is massively appreciated. Thank you!
    Tony 

    If you used your HP Recovery Media, all factory install drivers and software would have been installed. If you didn't create your HP Recovery Media when you first setup your computer, please contact official HP support in your region / country, via the HP Worldwide Support Portal, to see if HP Recovery Media is available for your computer.
    If a generic Windows 7 installation disc was used, you will need to install all HP specific driver for your computer. Please try IDT High-Definition (HD) Audio Driver, Intel High-Definition (HD) Graphics Driver, and AMD High-Definition Graphics Driver to resolve your missing drivers issues. Windows 7 64-bit driver for your computer can be found on the HP Pavilion dv6-6052ea Entertainment Notebook PC Drivers page.
    If you have any further questions, please don't hesitate to ask.
    Please click the White KUDOS "Thumbs Up" to show your appreciation
    Frank
    {------------ Please click the "White Kudos" Thumbs Up to say THANKS for helping.
    Please click the "Accept As Solution" on my post, if my assistance has solved your issue. ------------V
    This is a user supported forum. I am a volunteer and I don't work for HP.
    HP 15t-j100 (on loan from HP)
    HP 13 Split x2 (on loan from HP)
    HP Slate8 Pro (on loan from HP)
    HP a1632x - Windows 7, 4GB RAM, AMD Radeon HD 6450
    HP p6130y - Windows 7, 8GB RAM, AMD Radeon HD 6450
    HP p6320y - Windows 7, 8GB RAM, NVIDIA GT 240
    HP p7-1026 - Windows 7, 6GB RAM, AMD Radeon HD 6450
    HP p6787c - Windows 7, 8GB RAM, NVIDIA GT 240

  • "Best Practice" for a stored procedure that needs to access two schemas?

    Greetings all,
    When my company's application is deployed, two schema owners are typically created and all database objects divided between the two. I'll call them FIRST and SECOND.
    In a standard, vanilla implementation there is never any reason for the two to "talk to each other". No rights to objects in one schema are ever granted to the other.
    I am currently charged, however, with writing custom code to roll up data from one of the schemas and update tables in the other with the rollups. I have created a user whose job it is to run this process, and this user has the proper permissions to all necessary objects in both schemas. I'll call this user MRBATCH.
    Typically, any custom objects, whether they be additional staging tables, temp tables or stored procedures are saved in the FIRST schema. I tried to save this new stored procedure in the FIRST schema and compile it, but got "Insufficient priviliges" errors whenever the code in the stored procedure tried to access any tables in the SECOND schema. This surprised me a little bit because I had no plans to actually EXECUTE the stored procedure as FIRST, but I guess I can understand it from the point of view of, you ought be able to execute something you own.
    So which would be be "better" (assuming there's any difference): Grant FIRST all of the rights it needs in SECOND and save the stored procedure in FIRST, or could I just save the stored procedure in the MRBATCH schema? I'm not sure which would be "better practice".
    Is there a third option I'm overlooking perhaps?
    Thanks
    Joe

    In this case I would put it again into schema THIRD. This is a kind of API schema. There are procedures in it that allow some customized functionality. And since you grant only the right to execute those procedures (should be packages of cause) you won't get into any conflicts about allowing somebody too much.
    Note that this suggestion seems very similiar to putting the procedure directly to the executing user MRBATCH. It depends how this schemauser is used. I always prefer separating users from schemas.
    By definition the oracle object to represent a schema is identical to the oracle object representing a user (exception: externally defined users).
    my definition is:
    Schema => has objects (tables, packages) and uses tables space
    User => has priviledges (including create session and connect) and uses temp tablespace only. Might have synonyms and views.
    You can mix both, but sometimes it makes much sense to separate one from the other.
    Edited by: Sven W. on Aug 13, 2009 9:51 AM

  • JDBC Stored procedure help required

    Hi All,
    Please let me know simple blogs how to use JDBC Stored procedure or any other method  in receiver jdbc adapter to insert or select in 2 tables
    Please  let me know simple blogs how to use JDBC Stored procedure or any other method  in sender jdbc adapter to select from 2 tables
    Thanks

    Hi,
    I am also looking for JDBC Stored procedure or any other method in sender jdbc adapter to select data from 2 tables
    Thanks

  • Stored Procedure Help: Source does not have a runnable target

    I'm an MS-SQL guy, so I'm fairly familiar with T-SQL syntax, but am having one heck of a time trying to take code I've written for SQL and transform it to work with Oracle.
    Anyways, I'm using Oracle's SQL Developer, and I've got a stored procedure that calls the Alter Table statement and adds a column to it. I'm just trying to get this one to work before I move on to the other one's I have. I keep getting the message Source does not have a runnable target when I try running this command.
    create or replace PROCEDURE rta_conv_addcolumn(rtatablename1 in varchar(20),
    rtatablename2 in varchar(20),
    rtacolumnname in varchar(256),
    rtacolumninfo in varchar(256))
    AS
    DECLARE rtasql VARCHAR(4000);
    BEGIN
    IF EXISTS (SELECT * FROM user_tables WHERE table_name = rtatablename1)
    AND NOT EXISTS (SELECT * FROM user_tab_columns WHERE column_name = rtacolumnname
    AND table_name = rtatablename1)
    AND NOT EXISTS (SELECT * FROM user_tab_columns WHERE column_name = rtacolumnname
    AND table_name = rtatablename2)
    Then rtasql:= 'ALTER TABLE ['+rtatablename2+'] ADD ' + rtacolumnname + ' ' + rtacolumninfo;
    Execute (rtasql);
    END rta_conv_addcolumn;
    If I try compiling it I get the following messages, which don't make sense, since the syntax I'm using for declaring the input variables looks to be right.
    Error(1,54): PLS-00103: Encountered the symbol "(" when expecting one of the following: := . ) , @ % default character The symbol ":=" was substituted for "(" to continue.
    Error(2,29): PLS-00103: Encountered the symbol "(" when expecting one of the following: := . ) , @ % default character The symbol ":=" was substituted for "(" to continue.
    Error(3,29): PLS-00103: Encountered the symbol "(" when expecting one of the following: := . ) , @ % default character The symbol ":=" was substituted for "(" to continue.
    Error(4,29): PLS-00103: Encountered the symbol "(" when expecting one of the following: := . ) , @ % default character The symbol ":=" was substituted for "(" to continue.
    Error(6,1): PLS-00103: Encountered the symbol "DECLARE" when expecting one of the following: begin function package pragma procedure subtype type use <an identifier> <a double-quoted delimited-identifier> form current cursor external language The symbol "begin" was substituted for "DECLARE" to continue.
    Error(15,5): PLS-00103: Encountered the symbol "RTA_CONV_ADDCOLUMN" when expecting one of the following: if

    What table you want to add the column to? rtatablename1 or rtatablename2? I assumed 1 for now.
    I tried to preserve your code structure so you can familiarize with it.
    This piece should work, but you need to make sure you validate the parameters you concatenate to your strings when you use dynamic SQL.
    That's when SQL injection takes place: when you trust the parameters you are receiving and don't validate them.
    Also remember that DDL statements execute an implicit commit. Any previous DML operations you have pending will be commited by
    this EXECUTE IMMEDIATE call if it succeeds.
    I'd recommend some reading at the Oracle docs regarding those topics and the invoker's vs definer's rights for procedures.
    It basically means that as a default behaviour, the user running the procedure "borrows" the rights and privileges of the procedure owner,
    and that guy is usually super-privileged.
    http://download.oracle.com/docs/cd/E11882_01/appdev.112/e10472/subprograms.htm#LNPLS00809
    CREATE OR REPLACE PROCEDURE rta_conv_addcolumn
      rtatablename1 IN VARCHAR,
      rtatablename2 IN VARCHAR,
      rtacolumnname IN VARCHAR,
      rtacolumninfo IN VARCHAR
    ) AS
      rtasql VARCHAR(4000);
      v_count NUMBER;
    BEGIN
      SELECT COUNT(*)
        INTO v_count
        FROM user_tables
       WHERE table_name = upper(rtatablename1)
             AND NOT EXISTS (SELECT *
                               FROM user_tab_columns
                              WHERE column_name = upper(rtacolumnname)
                                    AND table_name = upper(rtatablename1))
             AND NOT EXISTS (SELECT *
                               FROM user_tab_columns
                              WHERE column_name = upper(rtacolumnname)
                                    AND table_name = upper(rtatablename2));
      IF v_count > 0
      THEN
        -- is it to the rtablename1 or 2 you want to add this column to?
        rtasql := 'ALTER TABLE ' || rtatablename1 ||' ADD ' || rtacolumnname || ' ' || rtacolumninfo;
        EXECUTE IMMEDIATE rtasql;
      END IF;
    END rta_conv_addcolumn;Edited by: fsitja on Dec 11, 2009 11:21 PM

  • Basic Stored Procedure Help - Not Returning Data

    Hello All:
    To be fair, I come from a SQL Server environment and have never written anything for PL/SQL / Oracle before, this is my first attempt, so if anything is better or more efficient, please let me know. The immediate problem I am having is, I have the Stored Procedure below, and all I want to do is return the data in the table, so that I can fill my DataSet in code. But when I run the code against this stored procedure, it always brings back no data (if I simply do a standard "SELECT * FROM lkAllocation", I get the results, so I know data is there and the connection is good). If run the procedure in my window in Oracle SQL Developer (call PAYSOL.spallocationselectall();), my results window shows no data as well. What is wrong with this Store Procedure?
    create or replace
    PROCEDURE spAllocationSelectAll IS
    AllocationID Integer;
    AllocationName Varchar2(50);
    BEGIN
    AllocationID := 0;
    AllocationName := '';
    SELECT
    AllocationID,
    AllocationName
    INTO
    AllocationID,
    AllocationName
    FROM
    lkAllocation
    ORDER BY
    AllocationName;
    EXCEPTION
    WHEN NO_DATA_FOUND THEN
    NULL;
    WHEN OTHERS THEN
    -- Consider logging the error and then re-raise
    RAISE;
    END spAllocationSelectAll;

    Hi and welcome to the forum.
    But when I run the code against this stored procedure, it always brings back no data I presume that your code will fail when having more than one record in your table.
    Did you check your error logging table?
    Anyway:
    Your approach will not give you your desired results.
    You're selecting two column values in two variables and nothing else happens.
    No OUT-parameters declared
    Perhaps you're better off using a function instead of a procedure etc,etc...
    When you have more than one record on your table, you'll run into a TOO_MANY_ROWS error this way...
    See:
    PL/SQL 101 : Understanding Ref Cursors
    and
    Re: Dynamic sql or ref cursor or what
    or
    How to return table value from stored procedure without ref cursor
    In short: do a search on this forum on 'REF CURSOR'...
    Also try to read, learn, do searches and understand a bit about Oracle, by studying the docs.
    http://www.oracle.com/pls/db102/homepage
    Concepts: http://download.oracle.com/docs/cd/B19306_01/server.102/b14220/toc.htm
    Fundamentals: http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14251/toc.htm
    And check out http://asktom.oracle.com as well...

  • HELP NEEDED PLEASE

    Hi everyone
    Programming help needed here. Any advice would be greatly appreciated!!!
    I have been assigned some work for a program called Processing 1.0 availale at http://processing.org/download
    I was give the 9 individual programs I needed to make however they were converted to Java files from .pde files. The program is based on Java but only runs .pde files and NOTHING else!
    I decompiled the files and got the source code, but it is a slight variation of the original someone made in processing, and needs some tidying to get it to run.
    I think the programs are very simple for a programmer, although I AM NOT.
    CODE is BELOW
    // Decompiled by DJ v3.10.10.93 Copyright 2007 Atanas Neshkov Date: 02/05/2009 13:15:00
    // Home Page: http://members.fortunecity.com/neshkov/dj.html http://www.neshkov.com/dj.html - Check often for new version!
    // Decompiler options: packimports(3)
    // Source File Name: Assign2_1.java
    import processing.core.PApplet;
    public class Assign2_1 extends PApplet
    public Assign2_1()
    SquareSide = 20;
    Rank = Nums.length;
    Side = SquareSide * Rank;
    Green = color(0, 255, 0);
    Yellow = color(255, 255, 0);
    BG = Yellow;
    public void setup()
    size(Side, Side);
    background(BG);
    fill(Green);
    for(int i = 0; i < Rank; i++)
    rect(i * SquareSide, 0.0F, SquareSide, SquareSide * Nums);
    public static void main(String args[])
    PApplet.main(new String[] {
    "--bgcolor=#ece9d8", "Assign2_1"
    int Nums[] = {
    6, 14, 8, 9, 2, 3, 4, 2, 8, 3,
    9, 2, 0, 5
    int SquareSide;
    int Rank;
    int Side;
    int Green;
    int Yellow;
    int BG;
    Edited by: chevy1 on May 2, 2009 7:32 AM

    HELP NEEDED PLEASEShouting is a good way ensure you don't get help. Also you should give a meaningful subject.
    Any advice would be greatly appreciated!!!I suggest you ask a question after providing enough information to be able to answer it.
    Also use CODE tags when posting code as it make the code more readable.
    We are more likely to help people who are trying to learn Java rather than someone who might be looking for an easy way out of doing an assignment.

  • ITunes corrupt file message - urgent help needed please

    I have an iPod video 30GB, i downloded the latest iTunes & Quicktime version, and updated my iPod also to the latest update. When i connect my iPod and start downloading music from the library in iTunes, the iPod keeps on disconnecting and restarting by itself, and i get a message that the file iTunes.exe is corrupt. I tried Apple support and did all what they said by downloading the latest updates and versions, and also did the Chkdsk utility on Windows, but still it did not work, the iPod keep on restarting and i cannot download anything on it, i had it now for a week and did not use it at all because of this problem, can somebody with a technical background help me please, i use Windows XP.

    I have an iPod video 30GB, i downloded the latest iTunes & Quicktime version, and updated my iPod also to the latest update. When i connect my iPod and start downloading music from the library in iTunes, the iPod keeps on disconnecting and restarting by itself, and i get a message that the file iTunes.exe is corrupt. I tried Apple support and did all what they said by downloading the latest updates and versions, and also did the Chkdsk utility on Windows, but still it did not work, the iPod keep on restarting and i cannot download anything on it, i had it now for a week and did not use it at all because of this problem, can somebody with a technical background help me please, i use Windows XP.

  • PHP Calling Stored Procedure Help!

    I have been messing with this code for weeks now and read a ton of forums and archives and I can't figure this out for the life of me.... I included the Stored Procedure and the PHP code and the ERROR I am getting below. Someone else in my company wrote the stored procedure. I am running PHP Version 4.3.9
    THANK YOU SO MUCH TO ANYONE IN ADVANCE!
    Oracle Stored Procedure
    Procedure GetDBCodes(appl_type In Varchar2,
    output_array Out str_varray,
    rtn_cd Out Number,
    rtn_errm Out Varchar2,
    rtn_spinfo Out Varchar2) As
    -- Program ID: GetDBCodes
    -- Author: Chris Calder
    -- Date Written: October 5, 2004
    -- System: Engage Thoughtware
    -- Purpose: Get the database codes for the application identified by appl_type
    -- Arguments: IN: appl_type 'ETW' = ThoughtTree
    -- 'ADM' = System Administration
    -- OUT output_array array of fixed length delimited output:
    -- company_name: 1 - 38
    -- user_name: 39 - 48
    -- db_code: 49 - 58
    -- db_version 59 - 66
    -- OUT rtn_cd: SQL return code
    -- OUT rtn_errm: Oracle error message text
    -- OUT rtn_spinfo: debugging info consisting of:
    -- procedure name and input parameter list,
    -- followed by the label of the SQL
    -- statement that caused the exception
    sql_stmt Varchar2(100);
    db_schema_name Varchar2(10);
    company_name Varchar2(40);
    db_version Varchar2(10);
    counter Number Default 0;
    lv_appl_type Varchar2(10);
    stmt_label Varchar2(40);
    data_error Exception;
    Begin
    stmt_label := '<<get_dbcodes>>';
    output_array := str_varray();
    lv_appl_type := appl_type || '%';
    For code_rec In (Select schema_name,
    db_code,
    dblink
    From etw$map.DBCode
    Where (dblink <> 'UTDEV' Or dblink Is Null)
    And schema_name Like lv_appl_type
    Order By substr(schema_name,
    4,
    3))
    Loop
    db_schema_name := 'ETWDB' || substr(code_rec.schema_name,
    4,
    3);
    If code_rec.dblink Is Null Then
    sql_stmt := 'select db_node_name, db_version from ' ||
    db_schema_name || '.masterprofile';
    Else
    sql_stmt := 'select db_node_name, db_version from ' ||
    db_schema_name || '.masterprofile' || '@' ||
    code_rec.dblink;
    End If;
    Execute Immediate sql_stmt
    Into company_name, db_version;
    -- add arrary extend and assignment here
    output_array.Extend;
    counter := counter + 1;
    output_array(counter) := rpad(company_name,
    38,
    ' ') || rpad(code_rec.schema_name,
    10,
    ' ') ||
    rpad(code_rec.db_code,
    10,
    ' ') || db_version;
    End Loop;
    Commit;
    rtn_errm := 'NONE';
    rtn_cd := Sqlcode;
    rtn_spinfo := 'CodeMap.GetDBCodes' || ' successful';
    Exception
    When data_error Then
    Rollback;
    rtn_errm := 'Appl_type value: ' || appl_type || ' is not valid';
    rtn_cd := -999;
    rtn_spinfo := 'CodeMap.GetDBCodes' || ' unsuccessful';
    When Others Then
    --** select from value table failed
    Rollback;
    rtn_errm := Sqlerrm;
    rtn_cd := Sqlcode;
    rtn_spinfo := 'CodeMap.GetDBCodes ' || stmt_label;
    End GetDBCodes;
    PHP Calling the Oracle Stored Procedure
    <?php header("cache-control: no-store, no-cache, must-revalidate"); header("Pragma: no-cache");
    $con = OCILogon('etw$map', 'pam$wte', 'LINUX_CONSONUS');
    $query = "BEGIN codemap.GETDBCODES('ETW',:results,:cd,:errm,:spinfo); END;";
    $stmt = OCIParse($con, $query) or die ('Can not parse query');
    OCIBindByName($stmt,":results", $output_array,-1);
    OCIBindByName($stmt,":cd", $rtn_cd,-1);
    OCIBindByName($stmt,":errm", $rtn_errm,-1);
    OCIBindByName($stmt,":spinfo", $rtn_spinfo,-1);
    OCIExecute($stmt);
    ?>
    ERROR I AM GETTING
    Warning: ociexecute(): OCIStmtExecute: ORA-06550: line 1, column 7: PLS-00306: wrong number or types of arguments in call to 'GETDBCODES' ORA-06550: line 1, column 7: PL/SQL: Statement ignored in c:\inetpub\wwwroot\Projects\PopUpRef\v2\php\testOracle.php on line 17

    Ok so I got the problem fixed,
    one of the output variables coming from the stored procedure was a custom defined object. So I had to use an ocinewcollection and set the typ to the custom type oracle was using and then bind it. So now everything is working great... I just thought I would post this for any one else that runs into this...
    here is my working code:
    <?php header("cache-control: no-store, no-cache, must-revalidate"); header("Pragma: no-cache");
    $con = OCILogon('user', 'pass', 'LINUX_CONSONUS');
    $query = "BEGIN codemap.GETDBCODES('ETW',:output_array,:cd,:errm,:spinfo); END;";
    $stmt = OCIParse($con, $query) or die ('Can not parse query');
    $output_array = ocinewcollection($con,"STR_VARRAY");
    OCIBindByName($stmt,":output_array", $output_array,5000,OCI_B_SQLT_NTY);
    OCIBindByName($stmt,":cd", $rtn_cd,6);
    OCIBindByName($stmt,":errm", $rtn_errm,200);
    OCIBindByName($stmt,":spinfo", $rtn_spinfo,200);
    OCIExecute($stmt);
    ?>
    So everything is working great. but I do have another question now how do I get data out of the ocinewcollection object?

Maybe you are looking for

  • I am having trouble opening files saved in CS 5.5 Indesign after spending time on the cloud. Help me please

    The last year(2013-2014) of school used CS5.5( I won and is on home computer) at home along with the cloud. School was using CS 6.I learned to save all files at home and at school in CS 4 or better. Saved files in each format so I could work on each

  • NVRAM issues, then dead screen

    My girlfriend's Macbook Pro, a 2009 Core 2 Duo 2.16ghz, went totally dead about a month ago. After doing some research, I found that resetting the NVRAM (Command+Option+P+R) seemed to get it running again. We'd have to do this once a week or so. And

  • ESS/MSS business packages "Deployed with Warning"

    Hello All,    We are on NW04s SP10 on MS SQL server and Windows server. The Database and portal installations or on different machines. I installed the business packages ESS 1.0, MSS 1.0 and the XSS components - 600 using the JSPM. After I deploy, I

  • How to set selected value in html:options that isusing HasMap Long,String

    So here is my problem I have a HashMap<Long,String> where key is the country id and value is the country name. So I am displaying it in the jsp using the below code <c-rt:set var="countriesMap" value="<%=countriesMap%>" target="java.util.HashMap<Long

  • "dynamic" String concat in Expression language

    I would like to do something like (in Java) String s = flag? "this" : value + "that";in EL it would be #{flag ? 'this' : value + 'that'} but this leads to an error because it tries to add as numbers and not concat as strings. how can I do this? thank