Sys Tables In Stored Procedure

How can I use Sys Table in Stored Procedure.
I want to use DBA_TAB_COLOUMNS, in stored procedure.
When I used this table in stored procedure I got an error
ORA - 00942 Table or View Does not exists.
Thanks,
Ahamed

From http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14251/adfns_packages.htm#i1006224
>
Note:
To create without errors (to compile the procedure or package successfully) requires the following additional privileges:
The owner of the procedure or package must be explicitly granted the necessary object privileges for all objects referenced within the body of the code.
The owner cannot obtain required privileges through roles.
>
You need to run
grant select on dba_tab_columns to <owner of procedure>;

Similar Messages

  • Drop and recreate table in stored procedure

    Hi all
    When creating tables using Transact-SQL scripts, I have always preferred to drop the table if it exists and then create it explicitly using CREATE TABLE.  For two reasons:
    1) It does not matter if it is the first time the SP is run ie. if I create the table manually in the first instance and just use TRUNCATE TABLE it could fail if the table is deleted
    2) I have control over the data types of the table fields
    Just recently though I discovered the error that can occur when dropping and creating a table in the same batch (see link below)
    Microsoft Website
    This causes me a problem when dropping and creating tables in stored procedures, as I understand that a stored procedure is in itself a single batch?
    Can I avoid this error in a stored procedure whilst continuing to drop and create tables?  Or should I be taking a different approach?
    Coding best practice advice would be greatly appreciated.
    Thank you

    Thanks Ronen
    Please see my second post immediately before your reply.
    Given that I need to store the data output in a physical table for use in QlikView, would you suggest truncating the table each time the SP runs?  And then having a script that handles both dropping and creating the physical table, and also creating
    the SP?
    >> QlikView
    QlikView is an Israeli company, right?
    In any case I am not familiar with QlikView's application, therefore I can only give you general information, based on assumptions regarding the application, and facts regarding the SQL Server.
    >> for use in QlikView
    I assume that external application use specific database structure (table
    structure) and it is change only in rare situations (for example CMS interface might change the tables if and when a module s update/install). In this case there is no need to drop the table and recreate it and TRUNCATE is the solution.
    >> would you suggest truncating the table each time the SP runs
    I am sorry but i cant recommend on TRUNCATE a table each time you execute SP, without know the exact reason for this logic. It sound to me, at this point of time (with the information that we have), that this
    is very bad logic (application architecture). As I wrote above, basing your application on TRUNCATING the table each time mean that you have problems with multi users. Thins about 2 people that try to execute the same SP at almost the same time. Think about
    locking in the SQL Server and bad data (one truncate while the other already inserted the new data and get no rows, if there is no locking).
    But TRUNCATE is much better in this case probably then DROP and DELETE, since it is faster, and locking will be shorter (hopefully the application use the correct locking). There are other reasons why TRUNCATE is better, and other people already mentioned
    most of them, but time in this scenario might be critical.
    >> having a script that handles both dropping and creating the physical table, and also creating the SP?
    I do not undestand what is this second step. we said that you truncate the table, so why do you need to
    dropping and creating the physical table and who
    creating the SP?
    Are you meaning that the application create the tables and SP?
    There are lot of application that during installation create the database structure. is this what you mean?
      Ronen Ariely
     [Personal Site]    [Blog]    [Facebook]

  • Using temporary tables in stored procedures

    Suppose that I have created a temporary table in a stored procedure using an "EXECUTE IMMEDIATE" statement. When I compile the procedure, that table is not created yet, so the compiler says that the table does not exist.
    What is the way of using temporary tables in stored procedures?

    It's a good practice to avoid using DDL statements being executed from stored procedures. "Truncate Table" via dynamic SQL from stored procedure is a different story and is useful in DSS environments.
    But if you insist on "creating" tables using Dynamic SQL from Stored Procedures then you must also embed your DML statements in Dynamic SQL to avoid compilation errors.
    Example:
    Create or Replace Procedure Proc_TestDynamicSQL is
    Begin
    Execute Immediate 'Create table myTable as select * from user_tables' ;
    Execute Immediate 'Update myTable set table_name = ''Test'' ' ; --two single quotes before and after the string "Test"
    End;
    In this case, Oracle wouldn't care about the table references during compilation.

  • Deleting records from sys.aud$ from stored procedure

    We have a stored procedure that is trying to move records from the sys.aud$ table to a historical table (in an attempt to keep sys.aud$ to a more manageable size, I guess -- full disclosure I did not write this proc). The basic flow is:
    select count(*) into rowcount from sys.aud$
    if (rowcount > 1000) {
    copy all rows from sys.aud$ to historical table
    delete from sys.aud$
    I am told this proc used to work just fine in the murky past (I am new to the client) but has now not worked for some time. When we try and compile the proc, we get the error
    "table or view does not exist," and the highlighted line is the "delete from sys.aud$". The "select count(*) from sys.aud$" line appears to cause no issue, but the proc will not compile as is. If I comment out the "delete from sys.aud$" line, however, the proc compiles just fine.
    Confusingly, if I log in as the same account that owns this proc, I can run both the select count(*) from sys.aud$ AND delete from sys.aud$ clauses with no complaints at all (altering slightly to work with only 1 record at a time, of course), but I cannot get the same to compile within a stored proc.
    I assume this is permissions related? Can anyone point me to the permissions the owner requires to be able to delete from sys.aud$ within a stored procedure? Or is there something else that needs to be done here? Any pointers much appreciated.
    Thanks.

    956928 wrote:
    We have a stored procedure that is trying to move records from the sys.aud$ table to a historical table (in an attempt to keep sys.aud$ to a more manageable size, I guess -- full disclosure I did not write this proc). The basic flow is:
    select count(*) into rowcount from sys.aud$
    if (rowcount > 1000) {
    copy all rows from sys.aud$ to historical table
    delete from sys.aud$
    I am told this proc used to work just fine in the murky past (I am new to the client) but has now not worked for some time. When we try and compile the proc, we get the error
    "table or view does not exist," and the highlighted line is the "delete from sys.aud$". The "select count(*) from sys.aud$" line appears to cause no issue, but the proc will not compile as is. If I comment out the "delete from sys.aud$" line, however, the proc compiles just fine.
    Confusingly, if I log in as the same account that owns this proc, I can run both the select count(*) from sys.aud$ AND delete from sys.aud$ clauses with no complaints at all (altering slightly to work with only 1 record at a time, of course), but I cannot get the same to compile within a stored proc.
    I assume this is permissions related? Can anyone point me to the permissions the owner requires to be able to delete from sys.aud$ within a stored procedure? Or is there something else that needs to be done here? Any pointers much appreciated.
    Thanks.privileges acquired via ROLE do NOT apply within named PL/SQL procedures.
    GRANT DELETE ON SYS.AUD$ TO <your_schema>;

  • When inserting 2 column details in a single table using Stored Procedure.Only 2 Column details getting inserted.1column details are not getting into the table.Please see the below script and help me to change.

    Line 390 Under the (Insert into SALES_TRADEIN Table)
    I need to insert (TradeIn_1_VIN) Values If there is no values in (TradeIn_1_VIN) then i have to insert (TradeIn_2_VIN) values to the (SALES_TRADEIN) Table.
    After i run then below script only (TradeIn_2_VIN) values are get inserted in the table. (TradeIn_1_VIN) are not getting loaded in to the table.
    I think there is the problem from Line No (404 to 414) Please help me change those particular lines to insert (TradeIn_1_VIN) Values also.If there is no details then (TradeIn_2_VIN) need to be inserted.
    -- =============================================
    -- Stored Procedure for Flatfile_Sales
    -- =============================================
    USE [IconicMarketing]
    ---==========Sales_Cursor
    --USE [IconicMarketing]
    --GO
    DECLARE
    @FileType
    varchar(50),
    @ACDealerID
    varchar(50),
    @ClientDealerID
    varchar(50),
    @DMSType
    varchar(50),
    @DealNumber
    varchar(50),
    @CustomerNumber
    varchar(50),
    @CustomerName
    varchar(50),
    @CustomerFirstName
    varchar(50),
    @CustomerLastName
    varchar(50),
    @CustomerAddress
    varchar(50),
    @CustomerCity
    varchar(50),
    @CustomerState
    varchar(50),
    @CustomerZip
    varchar(50),
    @CustomerCounty
    varchar(50),
    @CustomerHomePhone
    varchar(50),
    @CustomerWorkPhone
    varchar(50),
    @CustomerCellPhone
    varchar(50),
    @CustomerPagerPhone
    varchar(50),
    @CustomerEmail
    varchar(50),
    @CustomerBirthDate
    varchar(50),
    @MailBlock
    varchar(50),
    @CoBuyerName
    varchar(50),
    @CoBuyerFirstName
    varchar(50),
    @CoBuyerLastName
    varchar(50),
    @CoBuyerAddress
    varchar(50),
    @CoBuyerCity
    varchar(50),
    @CoBuyerState
    varchar(50),
    @CoBuyerZip
    varchar(50),
    @CoBuyerCounty
    varchar(50),
    @CoBuyerHomePhone
    varchar(50),
    @CoBuyerWorkPhone
    varchar(50),
    @CoBuyerBirthDate
    varchar(50),
    @Salesman_1_Number
    varchar(50),
    @Salesman_1_Name
    varchar(50),
    @Salesman_2_Number
    varchar(50),
    @Salesman_2_Name
    varchar(50),
    @ClosingManagerName
    varchar(50),
    @ClosingManagerNumber
    varchar(50),
    @F_AND_I_ManagerNumber
    varchar(50),
    @F_AND_I_ManagerName
    varchar(50),
    @SalesManagerNumber
    varchar(50),
    @SalesManagerName
    varchar(50),
    @EntryDate
    varchar(50),
    @DealBookDate
    varchar(50),
    @VehicleYear
    varchar(50),
    @VehicleMake
    varchar(50),
    @VehicleModel
    varchar(50),
    @VehicleStockNumber
    varchar(50),
    @VehicleVIN
    varchar(50),
    @VehicleExteriorColor
    varchar(50),
    @VehicleInteriorColor
    varchar(50),
    @VehicleMileage
    varchar(50),
    @VehicleType
    varchar(50),
    @InServiceDate
    varchar(50),
    @HoldBackAmount
    varchar(50),
    @DealType
    varchar(50),
    @SaleType
    varchar(50),
    @BankCode
    varchar(50),
    @BankName
    varchar(50),
    @SalesmanCommission
    varchar(50),
    @GrossProfitSale
    varchar(50),
    @FinanceReserve
    varchar(50),
    @CreditLifePremium
    varchar(50),
    @CreditLifeCommision
    varchar(50),
    @TotalInsuranceReserve
    varchar(50),
    @BalloonAmount
    varchar(50),
    @CashPrice
    varchar(50),
    @AmountFinanced
    varchar(50),
    @TotalOfPayments
    varchar(50),
    @MSRP varchar(50),
    @DownPayment
    varchar(50),
    @SecurityDesposit
    varchar(50),
    @Rebate
    varchar(50),
    @Term varchar(50),
    @RetailPayment
    varchar(50),
    @PaymentType
    varchar(50),
    @RetailFirstPayDate
    varchar(50),
    @LeaseFirstPayDate
    varchar(50),
    @DayToFirstPayment
    varchar(50),
    @LeaseAnnualMiles
    varchar(50),
    @MileageRate
    varchar(50),
    @APRRate
    varchar(50),
    @ResidualAmount
    varchar(50),
    @LicenseFee
    varchar(50),
    @RegistrationFee
    varchar(50),
    @TotalTax
    varchar(50),
    @ExtendedWarrantyName
    varchar(50),
    @ExtendedWarrantyTerm
    varchar(50),
    @ExtendedWarrantyLimitMiles
    varchar(50),
    @ExtendedWarrantyDollar
    varchar(50),
    @ExtendedWarrantyProfit
    varchar(50),
    @FrontGross
    varchar(50),
    @BackGross
    varchar(50),
    @TradeIn_1_VIN
    varchar(50),
    @TradeIn_2_VIN
    varchar(50),
    @TradeIn_1_Make
    varchar(50),
    @TradeIn_2_Make
    varchar(50),
    @TradeIn_1_Model
    varchar(50),
    @TradeIn_2_Model
    varchar(50),
    @TradeIn_1_ExteriorColor
    varchar(50),
    @TradeIn_2_ExteriorColor
    varchar(50),
    @TradeIn_1_Year
    varchar(50),
    @TradeIn_2_Year
    varchar(50),
    @TradeIn_1_Mileage
    varchar(50),
    @TradeIn_2_Mileage
    varchar(50),
    @TradeIn_1_Gross
    varchar(50),
    @TradeIn_2_Gross
    varchar(50),
    @TradeIn_1_Payoff
    varchar(50),
    @TradeIn_2_Payoff
    varchar(50),
    @TradeIn_1_ACV
    varchar(50),
    @TradeIn_2_ACV
    varchar(50),
    @Fee_1_Name
    varchar(50),
    @Fee_1_Fee
    varchar(50),
    @Fee_1_Commission
    varchar(50),
    @Fee_2_Name
    varchar(50),
    @Fee_2_Fee
    varchar(50),
    @Fee_2_Commission
    varchar(50),
    @Fee_3_Name
    varchar(50),
    @Fee_3_Fee
    varchar(50),
    @Fee_3_Commission
    varchar(50),
    @Fee_4_Name
    varchar(50),
    @Fee_4_Fee
    varchar(50),
    @Fee_4_Commission
    varchar(50),
    @Fee_5_Name
    varchar(50),
    @Fee_5_Fee
    varchar(50),
    @Fee_5_Commission
    varchar(50),
    @Fee_6_Name
    varchar(50),
    @Fee_6_Fee
    varchar(50),
    @Fee_6_Commission
    varchar(50),
    @Fee_7_Name
    varchar(50),
    @Fee_7_Fee
    varchar(50),
    @Fee_7_Commission
    varchar(50),
    @Fee_8_Name
    varchar(50),
    @Fee_8_Fee
    varchar(50),
    @Fee_8_Commission
    varchar(50),
    @Fee_9_Name
    varchar(50),
    @Fee_9_Fee
    varchar(50),
    @Fee_9_Commission
    varchar(50),
    @Fee_10_Name
    varchar(50),
    @Fee_10_Fee
    varchar(50),
    @Fee_10_Commission
    varchar(50),
    @ContractDate
    varchar(50),
    @InsuranceName
    varchar(50),
    @InsuranceAgentName
    varchar(50),
    @InsuranceAddress
    varchar(50),
    @InsuranceCity
    varchar(50),
    @InsuranceState
    varchar(50),
    @InsuranceZip
    varchar(50),
    @InsurancePhone
    varchar(50),
    @InsurancePolicyNumber
    varchar(50),
    @InsuranceEffectiveDate
    varchar(50),
    @InsuranceExpirationDate
    varchar(50),
    @InsuranceCompensationDeduction
    varchar(50),
    @TradeIn_1_InteriorColor
    varchar(50),
    @TradeIn_2_InteriorColor
    varchar(50),
    @PhoneBlock
    varchar(50),
    @LicensePlateNumber
    varchar(50),
    @Cost varchar(50),
    @InvoiceAmount
    varchar(50),
    @FinanceCharge
    varchar(50),
    @TotalPickupPayment
    varchar(50),
    @TotalAccessories
    varchar(50),
    @TotalDriveOffAmount
    varchar(50),
    @EmailBlock
    varchar(50),
    @ModelDescriptionOfCarSold
    varchar(50),
    @VehicleClassification
    varchar(50),
    @ModelNumberOfCarSold
    varchar(50),
    @GAPPremium
    varchar(50),
    @LastInstallmentDate
    varchar(50),
    @CashDeposit
    varchar(50),
    @AHPremium
    varchar(50),
    @LeaseRate
    varchar(50),
    @DealerSelect
    varchar(50),
    @LeasePayment
    varchar(50),
    @LeaseNetCapCost
    varchar(50),
    @LeaseTotalCapReduction
    varchar(50),
    @DealStatus
    varchar(50),
    @CustomerSuffix
    varchar(50),
    @CustomerSalutation
    varchar(50),
    @CustomerAddress2
    varchar(50),
    @CustomerMiddleName
    varchar(50),
    @GlobalOptOut
    varchar(50),
    @LeaseTerm
    varchar(50),
    @ExtendedWarrantyFlag
    varchar(50),
    @Salesman_3_Number
    varchar(50),
    @Salesman_3_Name
    varchar(50),
    @Salesman_4_Number
    varchar(50),
    @Salesman_4_Name
    varchar(50),
    @Salesman_5_Number
    varchar(50),
    @Salesman_5_Name
    varchar(50),
    @Salesman_6_Number
    varchar(50),
    @Salesman_6_Name
    varchar(50),
    @APRRate2
    varchar(50),
    @APRRate3
    varchar(50),
    @APRRate4
    varchar(50),
    @Term2
    varchar(50),
    @SecurityDeposit2
    varchar(50),
    @DownPayment2
    varchar(50),
    @TotalOfPayments2
    varchar(50),
    @BasePayment
    varchar(50),
    @JournalSaleAmount
    varchar(50),
    @IndividualBusinessFlag
    varchar(50),
    @InventoryDate
    varchar(50),
    @StatusDate
    varchar(50),
    @ListPrice
    varchar(50),
    @NetTradeAmount
    varchar(50),
    @TrimLevel
    varchar(50),
    @SubTrimLevel
    varchar(50),
    @BodyDescription
    varchar(50),
    @BodyDoorCount
    varchar(50),
    @TransmissionDesc
    varchar(50),
    @EngineDesc
    varchar(50),
    @TypeCode
    varchar(50),
    @SLCT2
    varchar(50),
    @DealDateOffset
    varchar(50),
    @AccountingDate
    varchar(50),
    @CoBuyerCustNum
    varchar(50),
    @CoBuyerCell
    varchar(50),
    @CoBuyerEmail
    varchar(50),
    @CoBuyerSalutation
    varchar(50),
    @CoBuyerPhoneBlock
    varchar(50),
    @CoBuyerMailBlock
    varchar(50),
    @CoBuyerEmailBlock
    varchar(50),
    @RealBookDate
    varchar(50),
    @CoBuyerMiddleName
    varchar(50),
    @CoBuyerCountry
    varchar(50),
    @CoBuyerAddress2
    varchar(50),
    @CoBuyerOptOut
    varchar(50),
    @CoBuyerOccupation
    varchar(50),
    @CoBuyerEmployer
    varchar(50),
    @Country
    varchar(50),
    @Occupation
    varchar(50),
    @Employer
    varchar(50),
    @Salesman2Commission
    varchar(50),
    @BankAddress
    varchar(50),
    @BankCity
    varchar(50),
    @BankState
    varchar(50),
    @BankZip
    varchar(50),
    @LeaseEstimatedMiles
    varchar(50),
    @AFTReserve
    varchar(50),
    @CreditLifePrem
    varchar(50),
    @CreditLifeRes
    varchar(50),
    @AHRes
    varchar(50),
    @Language
    varchar(50),
    @BuyRate
    varchar(50),
    @DMVAmount
    varchar(50),
    @Weight
    varchar(50),
    @StateDMVTotFee
    varchar(50),
    @ROSNumber
    varchar(50),
    @Incentives
    varchar(50),
    @CASS_STD_LINE1
    varchar(50),
    @CASS_STD_LINE2
    varchar(50),
    @CASS_STD_CITY
    varchar(50),
    @CASS_STD_STATE
    varchar(50),
    @CASS_STD_ZIP
    varchar(50),
    @CASS_STD_ZIP4
    varchar(50),
    @CASS_STD_DPBC
    varchar(50),
    @CASS_STD_CHKDGT
    varchar(50),
    @CASS_STD_CART
    varchar(50),
    @CASS_STD_LOT
    varchar(50),
    @CASS_STD_LOTORD
    varchar(50),
    @CASS_STD_URB
    varchar(50),
    @CASS_STD_FIPS
    varchar(50),
    @CASS_STD_EWS
    varchar(50),
    @CASS_STD_LACS
    varchar(50),
    @CASS_STD_ZIPMOV
    varchar(50),
    @CASS_STD_Z4LOM
    varchar(50),
    @CASS_STD_NDIAPT
    varchar(50),
    @CASS_STD_NDIRR
    varchar(50),
    @CASS_STD_LACSRT
    varchar(50),
    @CASS_STD_ERROR_CD
    varchar(50),
    @NCOA_AC_ID
    varchar(50),
    @NCOA_COA_ADDSRC
    varchar(50),
    @NCOA_COA_MATCH
    varchar(50),
    @NCOA_COA_MOVTYP
    varchar(50),
    @NCOA_COA_DATE
    varchar(50),
    @NCOA_COA_DELCD
    varchar(50),
    @NCOA_COA_RTYPE
    varchar(50),
    @NCOA_COA_RTNCD
    varchar(50),
    @NCOA_COA_LINE1
    varchar(50),
    @NCOA_COA_LINE2
    varchar(50),
    @NCOA_COA_CITY
    varchar(50),
    @NCOA_COA_STATE
    varchar(50),
    @NCOA_COA_ZIP
    varchar(50),
    @NCOA_COA_ZIP4
    varchar(50),
    @NCOA_COA_DPBC
    varchar(50),
    @NCOA_COA_CHKDGT
    varchar(50),
    @NCOA_COA_CART
    varchar(50),
    @NCOA_COA_LOT
    varchar(50),
    @NCOA_COA_LOTORD
    varchar(50),
    @NCOA_COA_URB
    varchar(50),
    @NCOA_COA_Z4LOM
    varchar(50),
    @NCOA_COA_ACTION
    varchar(50),
    @NCOA_COA_QNAME
    varchar(50),
    @NCOA_DPV_AA
    varchar(50),
    @NCOA_DPV_A1
    varchar(50),
    @NCOA_DPV_BB
    varchar(50),
    @NCOA_DPV_CC
    varchar(50),
    @NCOA_DPV_M1
    varchar(50),
    @NCOA_DPV_M3
    varchar(50),
    @NCOA_DPV_N1
    varchar(50),
    @NCOA_DPV_P1
    varchar(50),
    @NCOA_DPV_P3
    varchar(50),
    @NCOA_DPV_RR
    varchar(50),
    @NCOA_DPV_R1
    varchar(50),
    @NCOA_DPV_STATUS
    varchar(50),
    @NCOA_DPV_F1
    varchar(50),
    @NCOA_DPV_G1
    varchar(50),
    @NCOA_DPV_U1
    varchar(50),
    @myerror
    varchar(500),
    @SalesID
    int,
    @errornumber int,
                @errorseverity varchar(500),
                @errorstate int,
                @errorprocedure varchar(500),
                @errorline varchar(50),
                @errormessage varchar(1000);
    DECLARE Sales_Cursor CURSOR FOR 
    SELECT * from FLATFILE_SALES;
    OPEN Sales_Cursor;
     :r C:\Clients\BlackBook\BlackBookMarketing\Bharath\LOG_SALES_INSERT.sql
    WHILE @@FETCH_STATUS = 0
    BEGIN
    PRINT @VehicleVIN    ;
    --===============================================================================
    -- ****************** insert into Sales Table ***********
    BEGIN TRY
        INSERT INTO Sales 
    IconicDealerID,
    DealNumber,
    CustomerNumber,
    DMSType,
    ContractDate
    VALUES (@ClientDealerID,@DealNumber,@CustomerNumber,@DMSType,@ContractDate);
    END TRY
    BEGIN CATCH
         SELECT
            @errornumber = ERROR_NUMBER()
            ,@errorseverity = ERROR_SEVERITY() 
            ,@errorstate = ERROR_STATE() 
            ,@errorprocedure = ERROR_PROCEDURE() 
            ,@errorline = ERROR_LINE()
            ,@errormessage = ERROR_MESSAGE();
           :r C:\Clients\BlackBook\BlackBookMarketing\Bharath\LOG_SALES_INSERT.sql
    @errornumber ,
                @errorseverity ,
                @errorstate,
                @errorprocedure,
                @errorline,
                @errormessage);
    END CATCH
    PRINT @errornumber;
    PRINT @errorseverity;
    PRINT @errorprocedure;
    PRINT @errorline;
    PRINT @errormessage;
    PRINT @errorstate;
    set @myerror = @@ERROR;
        -- This PRINT statement prints 'Error = 0' because
        -- @@ERROR is reset in the IF statement above.
        PRINT N'Error = ' + @myerror;
    set @SalesID = scope_identity();
    PRINT @SalesID;
    --================================================================================
    --Insert into SALES_TRADEIN Table
    BEGIN TRY
    INSERT INTO SALES_TRADEIN
    SalesID,
    TradeIn_VIN,
    TradeIn_Make,
    TradeIn_Model,
    TradeIn_ExteriorColor,
    TradeIn_Year,
    TradeIn_Mileage,
    TradeIn_Gross,
    TradeIn_Payoff,
    TradeIn_ACV,
    TradeIn_InteriorColor
    VALUES
    @SalesID,
    case when  @TradeIn_1_VIN is not null then @TradeIn_2_VIN end,
    case when  @TradeIn_1_Make is not null  then @TradeIn_2_Make end,
    case when  @TradeIn_1_Model is not null  then @TradeIn_2_Model end,
    case when  @TradeIn_1_ExteriorColor is not null  then @TradeIn_2_ExteriorColor end,
    case when @TradeIn_1_Year is not null  then @TradeIn_2_Year end,
    case when  @TradeIn_1_Mileage is not null  then @TradeIn_2_Mileage end,
    case when @TradeIn_1_Gross is not null  then @TradeIn_2_Gross end,
    case when @TradeIn_1_Payoff is not null  then @TradeIn_2_Payoff end,
    case when @TradeIn_1_ACV is not null  then @TradeIn_2_ACV end,
    case when  @TradeIn_1_InteriorColor is not null  then @TradeIn_2_InteriorColor end
    END TRY
    BEGIN CATCH
    SELECT
            @errornumber = ERROR_NUMBER()
            ,@errorseverity = ERROR_SEVERITY() 
            ,@errorstate = ERROR_STATE() 
            ,@errorprocedure = ERROR_PROCEDURE() 
            ,@errorline = ERROR_LINE()
            ,@errormessage = ERROR_MESSAGE();
          :r C:\Clients\BlackBook\BlackBookMarketing\Bharath\LOG_SALES_INSERT.sql
    END CATCH

    This is what I've understood from your question. You want to replace @TradeIn_2_VIN value if @TradeIn_1_VIN
    is NULL, else the value of @TradeIn_1_VIN.
    If this is the requirement then, your CASE statement is missing ELSE part. You can re-write this as below
    case when  @TradeIn_1_VIN is null then @TradeIn_2_VIN
    ELSE @TradeIn_1_VIN end,
    or simply you can replace the CASE statement with the below
    COALESCE function,
    COALESCE(@TradeIn_1_VIN, @TradeIn_2_VIN),
    Krishnakumar S

  • Need to insert data in 2 tables thro stored procedure

    I need to create a stored procedure which will insert data in two tables. The procedure will get
    its inputs from an Oracle Developer Form which will be inserted into the tables.
    The 2 tables structure:
    1.FEES_MASTER
    Name Null? Type
    FEES_ID NOT NULL NUMBER(8) -- Primary Key
    CS_ID NOT NULL NUMBER(8) -- Class Student ID; An enrolled student
    REC_DATE NOT NULL DATE -- Fees receipt date
    REC_AMOUNT NOT NULL NUMBER(6) -- Fees receipt amount
    2.FEES_DETAIL
    Name Null? Type
    FEES_ID NOT NULL NUMBER(8) -- Foreign Key
    MONTH NOT NULL DATE -- First of each month to identify fee month
    Scenario:
    A student submits fees for 3 months through Master/Detail related blocks in a Developer Form as
    Under:
    Fees Master
    Fees ID : 11002
    Class Student ID : 356
    Receipt Date : 06-JAN-2001
    Receipt Amount : 1500
    Fees Detail
    Fees ID Fees Month
    11002 01-JAN-2001
    11002 01-FEB-2001
    11002 01-MAR-2001
    I need to check each fees detail record for fees month duplication as well before inserting new records.
    How can this be achieved?
    Thanks in advance.

    <BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by Fan Liu ([email protected]):
    create primary key in the detail table. i think it's FEES_ID + MONTH. then mark the columns in Forms as primary key property true, then call check_record_uniqueness built-in in on-check-unique trigger.<HR></BLOCKQUOTE>
    Thanks very much. But what I need is to ensure transaction integrity thro stored procedure. The system allows a certain CS_ID (i.e. Class Student ID, which is assigned a new one to every student annually) to submit fees for 12 months only, because a student stays in a class for a year. The 2 columns in the FEES_DETAIL table are composite primary key which only ensures that a certain FEES_ID will not be repeated for the same month. But suppose:
    1)this data already exist in the tables:
    Fees Master
    Fees ID : 11002
    Class Student ID : 356
    Receipt Date : 06-JAN-2001
    Receipt Amount : 1500
    Fees Detail
    Fees ID Fees Month
    11002 01-JAN-2001
    11002 01-FEB-2001
    11002 01-MAR-2001
    2)And this data is currently being inserted:
    Fees Master
    Fees ID : 11300
    Class Student ID : 356
    Receipt Date : 04-FEB-2001
    Receipt Amount : 1500
    Fees Detail
    Fees ID Fees Month
    11300 01-JAN-2001
    11300 01-FEB-2001
    11300 01-MAR-2001
    The data in the 2nd condition is perfectly valid but the application can't allow a student to submit fees for a month which he has already submitted. Now only a stored procedure can make sure after checking that the same student doesn't pay fees for duplicate months. Another reason for my emphasis on stored procedure is that what if a user tries to insert data thro an SQL* Plus session instead of the Form.
    PROBLEM: Now the problem I am having is I don't know how the procedure will take input for multiple records from the FEES_DETAIL block in the Form.
    Please assist in this regard. Thanks.

  • How to save images to table using stored procedures?

    hi all,
    i created a stored procedure
    create table members ( id number, name varchar2(30), avatar blob );
    create or replace add_ member ( id number, name varchar2, avatar blob )
    is
    begin
    insert into members values ( id, name, avatar);
    commit;
    end;i have 3 items in page..
    1. Hidden -> P1_ID
    2. Text field - > P1_NAME
    3. File Browse - P1_AVATAR
    but when invoking the procedure in Processes like
    begin
    add_member ( id => :P1_ID, name => :P1_NAME, avatar => :P1_AVATAR );
    end;i get an error
    1 error has occurred
        * ORA-06550: line 3, column 3: PLS-00306: wrong number or types of arguments in call to 'ADD_MEMBERR' ORA-06550: line 3, column 3: PL/SQL: Statement ignoredcan anyone tell me why it errors out?
    thanks
    allen

    Did you do as fac586 suggested:
    create table members ( id number, name varchar2(30), avatar blob );
    create or replace add_ member ( id number, name varchar2, avatar blob )
    is
    begin
    insert into members values ( id, name, avatar);
    commit;
    end;should be something like:
    create table members ( id number, name varchar2(30), avatar blob );
    create or replace add_ member ( id number, name varchar2, avatar blob )
    is
    begin
    insert into members (id, name, avatar) values ( id, name, avatar);
    commit;
    end;You need to specify the columns of the table that you will be inserting values into.
    Also, you should probably rename the parameters of your procedure so you can differentiate between the parameters, and the database columns.
    i.e.:
    create or replace add_ member ( p_id number, p_name varchar2, p_avatar blob )

  • Find tables in Stored Procedures

    Hi...
    Is there a way I can find the names of stored procedures where a certain table is referenced without having to look through all of them? I tried using dba_dependencies, but it did not return any rows even when I knew the table was referenced in two stored procs. No rows were returned. This is the query I issued:
    select
    referenced_name,
    referenced_type
    from
    dba_dependencies
    where
    name LIKE '%DATA.GL_Activity_Fact%'
    Any ideas? I need to modify all the stored procs which reference this table.
    Thanks so much!

    Assuming DATA is the schema name and GL_ACTIVITY_FACT is the table name
    1) You would want to use DBA_DEPENDENCIES to search for objects that reference the table, not for objects that are referenced by the table. So you'd want to search on REFERENCED_NAME and REFERENCED_OWNER, not the other way around.
    2) Regardless of how you specify the table in your code, the owner and object name will be stored separately in the data dictionary. And both will be all upper case (unless you happen to have created tables with case sensitive names).
    So you probably want
    SELECT owner, name, type
      FROM dba_dependencies
    WHERE referenced_owner = 'DATA'
       AND referenced_name = 'GL_ACTIVITY_FACT'
       AND referenced_type = 'TABLE'Be aware that if you use dynamic SQL to reference the table, there will be no entries in DBA_DEPENDENCIES for that.
    Justin

  • Visual Basic, DAO, Temp tables in stored procedures

    Client code currently uses DAO with SQLPassthrough option in VB to connect to SQl 6.5 db.
    I migrated all stored procedures with default options except Oracle 8i temp tables. For every procedure a package and a procedure was created. We use SQL server temporary tables extensively in a few hundred stored procedures. The ref cursor created refers to the temporary table. While migratiing, Create table statement is commented. How are SQL6.5 equivalent of temp tables handled in Oracle? Is there an alternative to temp tables?
    I also migrated to another oracle db using the INOUT type for stored procedures. This time only procedures were created. Can these procedures return a record set in DAO with SQLPAssthrough?
    How do you call a procedure using DAO in VB to get recordsets?
    What is the best way to migrate to Oracle with minimal client code changes?
    Thank you in advance.
    Umesh
    null

    Karthick_Arp wrote:
    BluShadow wrote:
    I agree with Karthick, there's no need for a temporary table in this situation.
    And to add, temporary tables should not be created at runtime, they should be part of the initial design of the database, created once and used as needed. Creating them at runtime is just wrong.The problem is the name oracle has given to GTT. The word Temporary mislead lot of SQL Server developers and they think its something same as the temporary table used in SQL Server :)Yeah, Ingres does something similar to SQL Server too, in that you can create a temporary table (Ingres assigned it a unique name and tells you what it is), and you set an expiry time on it (i.e. set it to expire in 1 days time), and then a background process is supposed to clean up the tables that have expired. Unlike Oracle, they are not session specific, but become visible to all once created.
    I think there's room for both types of temporary table, but Oracle's does the job (except when you want to use them from a stateless application front end).

  • Table Type  Stored Procedure in OBIEE Physical table properties

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

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

  • Problem with teporary table in stored procedure

    Hi,
    I have to execute a stored procedure in java , where the stored procedure has refcursor as out parameter and within the procedure the refcursor out parameter is populated from a temporary table
    when iam trying to get the resultset in my program iam getting object is no longer in use.
    I think this is becos the temporary table object is not available to my program
    can any one please help me

    I don't understand this part.
    Your procedure has "argSchemaName" as input parameter. Why do you have hardcoded owner name here in the cursor?
    >>
    CURSOR csrEligTables IS
    SELECT
    object_name
    FROM
    all_objects
    WHERE
    Owner = 'HI0XXX001'
    AND
    >>
    The anonymous block that you are running also has same owner name.

  • Problem with temporary table in stored procedure

    Hi,
    I have to execute a stored procedure in java , where the stored procedure has refcursor as out parameter and within the procedure the refcursor out parameter is populated from a temporary table
    when iam trying to get the resultset in my program iam getting the oracle error: ora-08103 object is no longer in use.
    I think this is becos the temporary table object is not available to my program
    can any one please help me

    I don't understand this part.
    Your procedure has "argSchemaName" as input parameter. Why do you have hardcoded owner name here in the cursor?
    >>
    CURSOR csrEligTables IS
    SELECT
    object_name
    FROM
    all_objects
    WHERE
    Owner = 'HI0XXX001'
    AND
    >>
    The anonymous block that you are running also has same owner name.

  • Temporary Tables in Stored Procedure

    Hi,
    I am writing a stored procedure that will get data from different sources and generates a spreadsheet finally. Initial select gets the basic data and following selects merges data.
    For this I have created a table in the database, I am populating data into that table using same procedure and finally selecting data from that table to generate spreadsheet.
    Now I am planning to use TEMPORARY table instead of creating table in database. Can anyone tell me where I can view samples for temp tables?
    Which one is the better option in performance wise?
    or
    can I handle the whole scenario with cursor? any examples?

    Hi,
    Why can't you use a regular table?
    Look up [Global Temporary|http://download.oracle.com/docs/cd/B28359_01/server.111/b28286/statements_7002.htm#sthref7247] in the diocumentation, including the SQL*Language manual, for an alternative.
    "Temporary" applies only to the data. A Global Temporary Table is created once, and stays until you DROP it, the same as any other table.
    The data in the table is temporary. If you create the table saying "ON COMMIT PRESERVE ROWS" (which sounds appropriate, based on your description) the the data will automatically be deleted when you end the database session.
    All data in Global Temporary Tables is session-specific. If two (or more) people are using the same table at the same time, each will only see the data they inserted themselves; they will never see rows inserted by the other session.
    Almost anything you can do with a regular table you can do with a Global Temporary Table. In particular, DML (such as MERGE) and cursors work exactly as they do on other tables.

  • Select from sys table in package procedure

    Is it possible to use a table in the SYS schema in a procedure defined in a package?
    Right now, these errors are raised:
    SQL> SHOW ERRORS PACKAGE BODY App_security_context;
    Errors for PACKAGE BODY APP_SECURITY_CONTEXT:
    LINE/COL ERROR
    17/3 PL/SQL: SQL Statement ignored
    18/8 PLS-00201: identifier 'SYS.DBA_ROLE_PRIVS' must be declared
    eg)
    CREATE OR REPLACE PACKAGE App_security_context IS
         PROCEDURE Set_restrictions;
    END App_security_context;
    CREATE OR REPLACE PACKAGE BODY App_security_context IS
    PROCEDURE Set_restrictions
    IS
    data_code VARCHAR2(16);
    BEGIN
    SELECT MD_SYS_USER_DATA_CODE.code_id INTO data_code
    FROM
    MD_SYS_USER_DATA_CODE
    , SYS.DBA_ROLE_PRIVS
    WHERE SYS.DBA_ROLE_PRIVS.grantee = SYS_CONTEXT('USERENV', 'SESSION_USER')
    AND SYS.DBA_ROLE_PRIVS.granted_role = MD_SYS_USER_DATA_CODE.role_id;
    DBMS_SESSION.SET_CONTEXT('app_entry', 'data_code', data_code);
    END Set_restrictions;
    END App_security_context;

    You need the select grant on the SYS view granted directly to you - not through a role. See here for more details:
    http://osi.oracle.com/~tkyte/Misc/RolesAndProcedures.html

  • Create Dates table as stored procedure

    I want to modify this statement to use todays date as the start date and add 50 years to insert into table instead of entering a date range and execute it as a stored procedure. Can someone help me to modify this? Thanks
    /**Drop Tables*/
    DROP TABLE [dbo].[DimDate]
    GO
    /** Create Date Dimension Table **/
    /* Create First numbers table for key generation */
    CREATE TABLE Numbers_Small (Number INT);
    INSERT INTO Numbers_Small
    VALUES (0)
    ,(1)
    ,(2)
    ,(3)
    ,(4)
    ,(5)
    ,(6)
    ,(7)
    ,(8)
    ,(9);
    GO
    /* Create Second numbers table for key generation */
    CREATE TABLE Numbers_Big (Number_Big BIGINT);
    INSERT INTO Numbers_Big (Number_Big)
    SELECT (tenthousands.number * 10000 + thousands.number * 1000 + hundreds.number * 100 + tens.number * 10 + ones.number) AS number_big
    FROM numbers_small tenthousands
    ,numbers_small thousands
    ,numbers_small hundreds
    ,numbers_small tens
    ,numbers_small ones;
    GO
    /* Create Date Dimension Table */
    CREATE TABLE [dbo].[DimDate] (
    [DateKey] [int] NOT NULL
    ,[Date] [datetime] NOT NULL
    ,[Day] [char](10) NULL
    ,[DayOfWeek] [smallint] NULL
    ,[DayOfMonth] [smallint] NULL
    ,[DayOfYear] [smallint] NULL
    ,[PreviousDay] [datetime] NULL
    ,[NextDay] [datetime] NULL
    ,[WeekOfYear] [smallint] NULL
    ,[Month] [char](10) NULL
    ,[MonthOfYear] [smallint] NULL
    ,[QuarterOfYear] [smallint] NULL
    ,[Year] [int] NULL
    GO
    /* Create Date Key and Date Fields */
    INSERT INTO [DimDate] (
    DateKey
    ,DATE
    SELECT number_big
    ,DATEADD(day, number_big, '1900-01-01') AS DATE
    FROM numbers_big
    WHERE DATEADD(day, number_big, '1900-01-01') BETWEEN '1900-01-01'
    AND '2050-12-31'
    ORDER BY number_big;
    GO
    /* Update all other fields with appropriate data. */
    UPDATE [DimDate]
    SET Day = DATENAME(DW, DATE)
    ,DayOfWeek = DATEPART(WEEKDAY, DATE)
    ,DayOfMonth = DAY(DATE)
    ,DayOfYear = DATEPART(DY, DATE)
    ,PreviousDay = DATEADD(DAY, - 1, DATE)
    ,NextDay = DATEADD(DAY, 1, DATE)
    ,WeekOfYear = DATEPART(WK, DATE)
    ,Month = DATENAME(MONTH, DATE)
    ,MonthOfYear = MONTH(DATE)
    ,QuarterOfYear = DATEPART(Q, DATE)
    ,Year = YEAR(DATE);
    GO
    /* Drop Temp Tables */
    DROP TABLE Numbers_Small;
    DROP TABLE Numbers_Big;

    SQL is a database language, so why do you want to re-compute constant data over and over, hundreds of times a day for years? UGH! 
    There are 365.2422 days per year, so a century of calender data is only 36,525 rows! Maybe 40 bytes per row? About 1.5 Kbytes  total? This will fit into main storage
    What you did post was wrong. DATE is a reserved word in SQL and it is  unit of temporal measurement. You also seem to confuse columns and fields. In SQL a field is a sub-unit of a temporal measurement (YEARS, MONTH, DAY, HOUR, MINUTE, SECOND). Please
    learn the ISO-11179 rules for data element names.
    You crammed too much in the table. The new DATE data type is only 3 bytes! Your other columns are mostly redundant and have attribute splitting problems.  Try this:
    CREATE TABLE Calendar 
    (cal_date DATE NOT NULL PRIMARY KEY,
     julian_date INTEGER NOT NULL, 
     julian_business_day INTEGER NOT NULL, 
     ordinal_date CHAR(8) NOT NULL
       CHECK (ordinal_date 
           LIKE '[12][0-9][0-9][0-9]-[0-9][0-9][0-9]') NOT NULL,
     week_date CHAR(9) NOT NULL
        CHECK (week_date LIKE '[12][0-9][0-9][0-9]W[0-5][0-9]-[0-7])
    The julianized date is a sequential number over the whole calendar. It makes temporal math easier. 
    ISO-8601 week_date is the week-within-year. This format is 'yyyyWww-d' where yyyy is the year, W is a separator token, ww is (01-53) week number and d is (1-7) day of the week. 
    There are several websites with calendars you can cut & paste, but you can start your search with: http://www.calendar-365.com/week-number.html 
    The Julian business day is a good trick. Number the days from whenever your calendar starts and repeat a number for a weekend or company holiday. 
    CREATE TABLE Calendar
    (cal_date DATE NOT NULL PRIMARY KEY, 
     julian_business_nbr INTEGER NOT NULL, 
    INSERT INTO Calendar 
    VALUES ('2007-04-05', 42), 
     ('2007-04-06', 43), -- good Friday 
     ('2007-04-07', 43), 
     ('2007-04-08', 43), -- Easter Sunday 
     ('2007-04-09', 44), 
     ('2007-04-10', 45); --Tuesday
    To compute the business days from Thursday of this week to next
     Tuesdays:
    SELECT (C2.julian_business_nbr - C1.julian_business_nbr)
      FROM Calendar AS C1, Calendar AS C2
     WHERE C1.cal_date = '2007-04-05',
       AND C2.cal_date = '2007-04-10'; 
    Why store things like the month name in the table? This is a display field, not a schema column value. It is language dependent! It is only part of a scalar value, too; why not normalize? 
    But if you need them, then use computed columns that are not materialized until needed. Also, use the SUBSTRING() for things that are not numeric. Why use SMALLINT for the day of the week?  Are you going to divide Thursday by 42? It is a name, not a numeric. 
    You saw the tricks with a Series table wanted to use them, but do not  be the boy with a new hammer who thinks everything is a nail. I find that a spreadsheet is the best way to create such a calendar table because they have so many temporal options and
    functions. 
    Also, putting the comma at the start of  a line is an old punchcard trick that we do not use any more. Back in the 1960's, it let us re-arrange the deck and re-use the cards. All it cost us was readable code –- your eyes expect to see a comma after a string,
    so this makes a twitch as you read. 
    --CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
    in Sets / Trees and Hierarchies in SQL

Maybe you are looking for

  • Copy files on import greyed out

    Hi I am testing PSE10 on Mac Lion before buying and one thing is stopping me buying it at the moment.  I want my original files to stay where they are and not copied into the PSE library.  Upon getting photos from folders option there is a "copy file

  • I forgot my pass code.

    So I changed my password & when I changed It I kind of had put thought that same instant to put my old password back because I didn't want to forget. when I did put the same new password on the pass code it didn't work. I have tried 8 attempts with t

  • Bring back Visual Basic 6.0 ! We all need it.

    Please reconsider introducing VB6 to the market. It is needed by many.

  • Hp pavillion Dv202130ea sound not completely muting

    Hi Guys & Girls I have a  intel  T5500   166 Mhz  dv2130ea  that i believe was running on xp i built it up from spares and keep it as a spare because we have quite a few laptops in our household for the grand children and my sons etc the problem with

  • Throw a message box when a special character is found...

    Again,, thought this would be pretty easy just looking to throw a message box if a special character is found..  Using this starter code, it works if only one special character is used, but with multiple characters, does not throw message box.  Examp