Table name at run time in Stored procedure

I have a SQl statement within my stored procedure as :
SELECT LastModifiedDate INTO v_Date FROM TABLE1 WHERE ID = v_ID;
Can I use a variable vTableName instead of directly putting the
value "TABLE1" (that is actual name of the table ).
Please excuse me if the question sounds trivial.
Cheers!!

You need to use Dynamic Sql. In your procedure
DECLARE
v_sql_stmt varchar2(2000);
v_Date       DATE ;
begin
v_sql_stmt :=  'SELECT LastModifiedDate FROM TABLE1 WHERE ID = :1 ' ;
execute immediate v_sql_stmt into v_Date  using v_ID ;
end;

Similar Messages

  • How to Use Table name at run time

    Hi All
    I have created a function that accepts a table name as a parameter and returns the maximam sequence number, but in my function body i can not write the parameter name as a table i.e.
    CREATE OR REPLACE FUNCTION MAX_ID(TAB_NAME Varchar)
    RETURN Number IS
    max_id Number;
    CURSOR curSalPoint IS
         SELECT MAX(EMP_NUMBER)
         FROM TAB_NAME ;
    BEGIN
    max_id:=0;
    OPEN curSalPoint ;
         FETCH curSalPoint INTO max_id;
         CLOSE curSalPoint;
    RETURN max_id
    END
    But it will give an error saying
    (1):PL/SQL: ORA-00942: table or view does not exist
    for "TAB_NAME"
    Any help would be appreciate ........

    Yes, as i contcatinated table name with the original statement, so you can also continate fields' names with your statment and execute immediate the statement.
    Sorry i forgot this statement in my function, to execute the statement you need to include following statement
    CREATE OR REPLACE FUNCTION MAX_ID(TAB_NAME Varchar)
    RETURN Number IS
    max_id Number;
    query varchar2(200);
    BEGIN
    max_id:=0;
    query:=null;
    query := query || 'select max(empno) into max_id from'|| tab_name;
    EXECUTE IMMEDIATE query;
    RETURN max_id;
    END;
    Message was edited by:
    Salman Qureshi

  • Problem in running a java stored procedure&optimum settings for this needed

    hi
    we are using java stored procedures to read huge data from database tables and transfer them to another system.
    the procedure is running fine but it fails after transferring 60000 records, the execution of procedure here does not terminate but keeps running with out performing any data transfer....since it does not give any error it is difficult for us to know what the actual problem is !!!!!!
    i have checked the code many a time and i dont see any infinite loops in that code.
    please give any pointers on why this might be happening?
    please also give all the parameters which need to be taken care of while running a java stored procedure
    thanks
    regards
    asif

    But the same thing works fine with a jdbc program
    the table name is converted
    The same convert.transform method is being used to do the conversion
    please help
    ISQL is similar to SQL prompt inOracle
    it is like,
    ISQL>
    Regards
    khurram

  • Multiple runs of same stored procedure

    I am an SSIS newbie so please excuse how little I know.
    We have a manual job that I would like to automate in SSIS.
    We run the same stored procedure six times with different parameters. Each run creates a csv file that we load into excel and then mail the attachments to the user. Can SSIS run the SP, and in a send mail task, send the six outputs?

    You seem to imply that your stored proc is also creating the CSV with data. Usually I'd just let the stored proc populate a staging table with the data and let SSIS tasks to handle the export to CSV and the email part.
    You can use an SSIS Execute SQL Task to run the stored proc with parameters. Then use an SSIS Data Flow Task (DFT) to export data to a CSV and use Send Mail Task (SMT) to send the CSV as an attachment. The path to the CSV file needs to
    be in an SSIS variable. This variable can be populated via a config file, parameters or expression. The destination File Connection and the SMT will use this variable to set their File Path and Attachment properties respectively.
    - Aalamjeet Rangi | (Blog)

  • How do I merge data from table1 on server 1 to final table on server 2 with a stored procedure to execute every 4 hours.

    How do I merge data from table1 on server 1 to final table on server 2 with a stored procedure to execute every so many hours.

    Hello,
    If you had configure server2 as
    linked server on the server1, you can run the following statement inside stored proceduce to copy table data. And then create a job to the run stored proceduce every 4 hours.
    Insert Into Server2.Database2.dbo.Table2
    (Cols)
    Select Cols From Server1.Database1.dbo.Table1
    Or you can use the SQL Server Import and Export Wizard to export the data from server1 to server2, save the SSIS package created by the wizard on the SQL Server, create a job to run the SSIS package. 
    Reference:http://technet.microsoft.com/en-us/library/ms141209.aspx
    Regards,
    Fanny Liu
    Fanny Liu
    TechNet Community Support

  • Is it possible to pass TABLE as the output parameter in stored procedure

    Hey Experts,
      Is it possible to pass TABLE as the output parameter in stored procedure.
    eg
    create procedure spGetData
    @tableName as TABLE(intValue INT NOT NUL)
    as 

    You can use OPENQUERY or OPENROWSET, as mentioned above, to make stored procedure results table like. There are
    some limitations with these methods:
    http://technet.microsoft.com/en-us/library/ms188427.aspx
    In OPENQUERY this-sql-server-instance can be used instead of a linked server name. It requires setting data accces server option:
    exec sp_serveroption @server = 'PRODSVR\SQL2012'
    ,@optname = 'DATA ACCESS'
    ,@optvalue = 'TRUE'
    LINK: http://www.sqlusa.com/bestpractices/select-into/
    Kalman Toth Database & OLAP Architect
    SELECT Video Tutorials 4 Hours
    New Book / Kindle: Exam 70-461 Bootcamp: Querying Microsoft SQL Server 2012

  • Reading from a file. How to ask the user for file name at run time????

    I have the code to read from a file but my problem is how to prompt the user for the file name at run time.
    import java.io.File;
    import java.io.FileNotFoundException;
    import java.util.InputMismatchException;
    import java.util.Scanner;
    public class FileRead {
        public static void main(String args[]) {
            Scanner scan = null;
            File file = new File("Results.txt");
            String number;
            try {
                scan = new Scanner(file);
                while (scan.hasNext()){
                number = scan.next();
                System.out.println(number);}
            catch (FileNotFoundException ex1){
                System.out.println("No such file");
            catch (IllegalStateException ex2){
                System.out.println("Did you close the read by mistake");
            catch (InputMismatchException ex){
                System.out.println("File structure incorrect");
            finally{
                scan.close();}
    }Any hints would be greatly appreciated. Thank you in advance

    I have read through some of the tutorials that you have directed me too and they are very useful, thank you. however there are still a few things that i am not clear about. I am using net beans 5.0 I have placed a text file named Results.txt into the project at the root so the program can view it.
    When I use the code that you provided me with, does it matter where the file is, or will it look through everywhere on the hard drive to find a match?
    This code compiles but at run time it comes up with this error
    run-single:
    java.lang.NoClassDefFoundError: NamedFile
    Exception in thread "main"
    Java Result: 1
    BUILD SUCCESSFUL (total time: 3 seconds)
    import java.util.Scanner;
    import java.io.*;
    class NamedFileInput
      public static void main (String[] args) throws IOException
        int num, square;   
        // this Scanner is used to read what the user enters
        Scanner user = new Scanner( System.in );
        String  fileName;
        System.out.print("File Name: ");
        fileName = user.nextLine().trim();
        File file = new File( fileName );     // create a File object
        // this Scanner is used to read from the file
        Scanner scan = new Scanner( file );     
        while( scan.hasNextInt() )   // is there more data to process?
          num = scan.nextInt();
          square = num * num ;     
          System.out.println("The square of " + num + " is " + square);
    }his is the code that i used. It is the same as the code you posted for me (on chapter 23 I/O using Scanner and PrintStream) Sorry im just really stuck on this!!

  • Date/Time Format Stored Procedure Calls in ADVANCE MODE in JDBC ADAPTER

    Hi Experts,
    What is significance of Date/Time Format Stored Procedure Calls in ADVANCE MODE in JDBC ADAPTER.
    Thanks,
    ABDUR

    I guess this would be applicable for the folowing formats - DATE, TIME, TIMESTAMP.
    This is the correct link
    http://help.sap.com/saphelp_nw04/helpdata/en/64/ce4e886334ec4ea7c2712e11cc567c/content.htm
    Regards,
    Prateek

  • Update step limit name at run-time

    I need to run through some test steps in a TestStand sequence multiple times.  This wouldn't be a loop on a single step or group of steps but probably a goto a label "for" loop in TestStand.  BTW, TestStand 2.0.1 calling code from a LabWindows/CVI DLL via the standard prototype adapter.  Each iteration I need to have the test step limit names be updated with a different suffix.  So step1 might have results0 and results1 and on the 2nd run results0 would be renamed to results0b.  How do I update the limit names, at run-time, from a LabWindows/CVI function?  I.e. the first test in the sequence's Main would update the steps below it to update the suffix.  I started down the path of using TS_SeqContextGetProperty to get the sequence handle
    TS_SeqContextGetProperty( testData->seqContextCVI, &errorInfo, TS_SeqContextSequence, CAVT_OBJHANDLE, &seq_hndl );
    then using TS_SequenceGetNumSteps( seq_hndl, &errorInfo, TS_StepGroup_Main, &num_steps ) to determine the number of steps in the Main tab.  
    Enter a for loop:
    TS_PropertyGetValString( testData->seqContextCVI, &errorInfo, buf, TS_PropOption_NoOptions, ( char ** )&rslt_name ) with buf as "Sequence.Main[0].Result.Measurement[0]" errors out with an invalid name message.  The idea is to get this value, update it based on the iteration in TestStand ( this is already acquired and working ), and then set the value back.  Then, move on to the next step and so forth.
    Any suggestions?
    Thanks.
    -G-
    Solved!
    Go to Solution.

    So, I tried the example and it works but only for a single step.  I've tried two options:  1. having a single step that programmatically changes all the result names in all the other steps in the sequence. 2. having each step update the result names itself.  For thought 1 the loop would run and the changes would occur but when the function was exited I'd get an exception from TestStand.  No real information in the details as it looked like a memory corruption error.  I then examined the details of what occurred and tried more experiments.  If I had the loop have more than 1 iteration this behavior occurred.  If I comment out the set function it still occurs.  Then, for thought 2, it works like a champ on all the steps until I loop back to the top of the sequence.  Then, on the first step ( 2nd time through ) it bombs out.
    Attached is the code for the 2nd possible solution.
    Does anyone know what the problem is or if there's a way to do this?
    -G-
    Attachments:
    Change Step Name.txt ‏7 KB

  • Execution Times of Stored Procedures Called from Other Stored Procedures

    If I execute sys.dm_exec_procedure_stats, it will produce execution times of my stored procedures executed recently.
    However, stored procedures called from other stored procedures do not show up.
    Is there code that can return the execution times of stored procedures even though they are called from other stored procedures.

    Look at the example. It is counting nested execution.
    CREATE PROC z1SP AS SELECT * FROM Production.Product;
    GO
    CREATE PROC z2SP AS SELECT * FROM Production.Product WHERE Color is not null; EXEC z1SP;
    GO
    SELECT object_name(2002822197), object_name(2034822311);
    --z1SP z2SP
    EXEC z1SP; EXEC z2SP;
    GO 10
    SELECT * from sys.dm_exec_procedure_stats
    database_id object_id type type_desc cached_time last_execution_time execution_count
    16 2002822197 P SQL_STORED_PROCEDURE 2014-12-16 13:02:45.170 2014-12-16 13:02:46.717 20
    16 2034822311 P SQL_STORED_PROCEDURE 2014-12-16 13:02:45.460 2014-12-16 13:02:46.687 10
    Kalman Toth Database & OLAP Architect
    SQL Server 2014 Database Design
    New Book / Kindle: Beginner Database Design & SQL Programming Using Microsoft SQL Server 2014

  • How to pass column name at run time in function.

    how to pass column name at run time in function as parameter.
    thank in advance
    pramod patel

    Hello,
    Using dynamic sql you can pass column name to function. well I am not getting what you really want to do ? Please write in more detail. By the way I am providing one example here. see it uses dynamic sql.
    Create or replace function fun_updtest (p_columnname_varchar2 in varchar2,
    p_value_number in number)
    return number is
    v_stmt varchar2(500);
    begin
    v_stmt := 'update emp
    set '||p_columnname_varchar2||' = '||to_char(p_value_number)||'
              where empno = 7369';
    execute immediate v_stmt;
    return 0;
    commit;
    end;
    call to this function can be like this..
    declare
    v_number               number;
    begin
    v_number := fun_updtest('SAL',5000);
    end;
    Adinath Kamode

  • No entry in table T001P when running time eval

    Hi,
    Can someone tell me, why this error occurs. "No entry in table T001P" when running time evaluation PT60. I checked his Infotype 1 and has the Personal Area/Subarea assigned.
    Thanks,
    Swarna.

    Hi,
    Please check these tables:
    V_001P_ALL
    V_503_AL
    Or try creating a blank entry in table T001P.
    Hope this helps,
    Reward points if helpful,
    Thank You,

  • Table name where the text attachments stored

    Hi folks,
             I have created an text attachment while creatng PR. where do these attachments store. In which table can  i see the attachments that i have made while creating PR.Please suggest.
    Shyam.

    Hi Abhishek,
                   thanks for your anshwer. But, If it is just text we can read using READ_TEXT, but i need to check whehter is attachment is created for a specific PR or not. Any input on the table name, where the attachments are stored..
                        Thanks,
                        Shyam.

  • How do I merge data from table1 on server 1 to final table on server 2 with a stored procedure to execute every so many hours.

    How do I merge data from table1 on server 1 to final table on server 2 with a stored procedure to execute every so
    many hours.

    How big is the table on server B? Is that possible to bring the all data into a server A and merge the data locally?
    Best Regards,Uri Dimant SQL Server MVP,
    http://sqlblog.com/blogs/uri_dimant/
    MS SQL optimization: MS SQL Development and Optimization
    MS SQL Consulting:
    Large scale of database and data cleansing
    Remote DBA Services:
    Improves MS SQL Database Performance
    SQL Server Integration Services:
    Business Intelligence

  • How to get sequence name in run time.

    hi
    I have several sub sequence called in the main sequence in TestStand. Those sub sequences have different sequence names, which i wanted to display by string indicator on the Labview Operator Interface. Is there a simple way to show the current calling sub sequence name during run time(run main).
    thanks.
    Message Edited by Appledoll on 07-12-2007 10:12 AM

    Hi,
    The easiest way is to use the NameOf() function. In this case where you wish to get the name of the current sequence the syntax NameOf(RunState.Sequence) yields the name. I attach a very simple example also.
    Getting the Name of Any TestStand Property Programmatically in TestStand
    Hope this helps
    Pelle S
    District Sales Manager
    National Instruments Sweden
    Attachments:
    Get sequence name.vi ‏15 KB

Maybe you are looking for

  • Users are not removed from role using UME API

    Hello, I am using this code to remove users from a batch of roles that I have. Everything is running OK, no exception is thrown and at the System.out I see all the actions that needs to be taken correctly. The problem is that if I'll go later to one

  • Change background color  for JFrame

    hi, i want to change background color of JFrame. In my application i didn't create any panels. my code like this, Frame myFrame = new JFrame ( " Grid Layout Frame ");      myFrame.setSize(500,500);      myFrame.getContentPane().setBackground(Color.wh

  • MSI VOX TV Tuner

    Ok ppl heres the story Ive just ordered the vox tv tuner and ive then decided to research it, and what ive found out is ive made a big mistake lol, i basicaly was posting to find out if anyone has got  this tv tuner working in the uk? Thanx Baka!

  • How to check BO Log an Bo configuration

    Post Author: Srividya CA Forum: Deployment How to check whether the BO log is enabled? As we are very new to BO, can you please tell us the steps to check the same. Can you tell us the steps to get BO Configuration details from server.

  • A guide for Licensing of ES3 Modules?

    We have difficulties in preparing/configuring LC ES3 modules based on prospects' requirements. Is there a "Licensing Guide" for LC ES3 that will help us in configuring the modules? Regards, Haluk Cavusoglu Innovatech