Copy the result of Execute immediate result into a variable.

Hi All,
Is there any way to copy the result of execute immediate result into a variable.
am doing following steps but am getting an error.
varSQLstmt1:='select count(*) into'||vararch_ct||' from '||vararch_count;
dbms_output.put_line(varSQLstmt1);
execute immediate varSQLstmt1;
But am getting sql statement as select count(*) into from SALES
the variable(vararch_ct) is missing in select statement .
please help me to solve this issue. Or is there any way to insert the count of records into any variable.
Thanks
Sree

declare
varSQLstmt1    varchar2(4000);
v_count          number;
begin
varSQLstmt1:='select count(*) from '||vararch_count;
dbms_output.put_line(varSQLstmt1);   
execute immediate varSQLstmt1 into v_count;
dbms_output.put_line('Coutn :: ' || v_count);
end;

Similar Messages

  • Oracle 11G Copying a table using execute immediate

    I want to copy the contents of one table into another using execute immediate.
    This keeps failing with the following error
    ORA-00903: invalid table name
    ORA-06512: at "TABLE_COPY", line 6
    ORA-06512: at line 8
    create or replace
    procedure TABLE_COPY(
    TABLE1 varchar2,
    TABLE2 varchar2)
    is
    begin
    execute immediate 'insert into '||TABLE2||' (select * from '||TABLE1||')';
    end;
    Edited by: user9213000 on 24-Jan-2013 07:38

    user9213000 wrote:
    I want to copy the contents of one table into another using execute immediate.
    This keeps failing with the following error
    ORA-00903: invalid table name
    ORA-06512: at "TABLE_COPY", line 6
    ORA-06512: at line 8
    create or replace
    procedure TABLE_COPY(
    TABLE1 varchar2,
    TABLE2 varchar2)
    is
    begin
    execute immediate 'insert into '||TABLE2||' (select * from '||TABLE1||')';
    end;
    Edited by: user9213000 on 24-Jan-2013 07:38The standard advice when (ab)using EXECUTE IMMEDIATE is to compose the SQL statement in a single VARCHAR2 variable
    Then print the variable before passing it to EXECUTE IMMEDIATE.
    COPY the statement & PASTE into sqlplus to validate its correctness.

  • Put the query result of "EXECUTE IMMEDIATE" command in a local table

    Hi all.
    Is it possible to put the output of the "EXECUTE IMMEDIATE" command in a local table so that the ouput can be accessed through other procedures.
    Regards,
    Andila

    Hi Andila, well you could just make your dynamic sql statement an insert statement based on your select. See example below
    create column table test_table_1
    "COL1" nvarchar(10),
    "COL2" nvarchar(10)
    CREATE PROCEDURE INSERT_P() 
    LANGUAGE SQLSCRIPT AS 
      sql_string NVARCHAR(2000) := '';
    BEGIN 
      sql_string := 'insert into test_table_1 (select ''val1'', ''val2'' from dummy) ';
      EXECUTE IMMEDIATE (:sql_string); 
    END; 
    call insert_p();
    select * from test_table_1;
    However you may want to investigate other options instead of using dynamic SQL as this is not a recommended approach. Less optimized compared to standard sql.
    Peter

  • Transfer data from Result Set (Execute SQL Task) into Flat File

    Hi to all,
    My problem is this:
     -) I have a stored procedure which use a temporary table in join with another "real" table in select statement. In particular the stored procedure look like this:
    create table #tmp
    col1 varchar(20),
    col2 varchar(50)
    --PUT SOME VALUE IN #TMP
    insert into #tmp
    values ('abc','xyz')
    --SELECT SOME VALUE
    select rt.*
    from realTable rt, #tmp
    where rt.col1 = #tmp.col1
    -) I cannot modify the stored procedure because I'm not admin of database.
    -) I HAVE THE REQUIREMENT OF TRANSFER DATA OF SELECT STATEMENT OF SOTRED PROCEDURE INTO FLAT FILE
    -) THE PROBLEM is that if I use an OLEDB source Task within a Data Flow Task I'm not be able of mapping column from OLEDB source to flat file destination. The reason for this, is that in the "Column page" of OLEDB source task, SSIS do not retrieves
    any column when we using a temporary table. The reason for this, is that SSIS is not be able to retrieve metadata related to temporary table. 
    -) One possible solution to this problem is to use an Execute SQL Task to invoke the stored procedure, store the result returned from stored procedure in a Result Set through a Object type user variable.
    -) The problem now is: How to transfer data from result set to flat file?
    -) Reading here on this forum the solution look be like to use a Script task to transfer data from result set to flat file.
    QUESTIONS: How to transfer data from result set to flat file using a script task?? (I'm not an expert of vb .net) Is it really possible?? P.S.: The number of row returned of stored procedure is very high!
    thanks in advance.

    Hi  Visakh16<abbr
    class="affil"></abbr>
    thanks for the response.
    Your is a good Idea, but I do not have permission to use DDL statement on the database in production environment.

  • How to display result of execute immediate on sql prompt

    I wish to create a dynamic select statement where i will give table name and where condition as input parameters at runtime. for this i created following procedure:
    CREATE or replace PROCEDURE select_rows (
    table_name IN VARCHAR2,
    condition IN VARCHAR2 DEFAULT NULL)
    AS
    where_clause VARCHAR2(100) := ' WHERE ' || condition;
    BEGIN
    IF condition IS NULL THEN where_clause := NULL; END IF;
    EXECUTE IMMEDIATE 'select * FROM ' || table_name || where_clause;
    END;
    my procedure is successfully created.
    my problem is how to get select stmt output at screen (sql prompt)
    or how to spool the output in a file.
    plz. help me. I am learning oracle .
    thanx in adv.
    Mani

    You could use refcursors. Example :
    TEST@db102 > CREATE or replace PROCEDURE select_rows (
      2     table_name IN VARCHAR2,
      3     condition IN VARCHAR2 DEFAULT NULL,
      4     cur1 out sys_refcursor)
      5  AS
      6     where_clause VARCHAR2(100) := ' WHERE ' || condition;
      7  BEGIN
      8     IF condition IS NULL THEN where_clause := NULL; END IF;
      9     open cur1 for 'select * from '||table_name||where_clause;
    10  END;
    TEST@db102 > /
    Procedure created.
    TEST@db102 > var cur refcursor;
    TEST@db102 > exec select_rows('emp','deptno=20',:cur);
    PL/SQL procedure successfully completed.
    TEST@db102 > print cur
         EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM     DEPTNO
          7369 SMITH      CLERK           7902 17-DEC-80        800                    20
          7566 JONES      MANAGER         7839 02-APR-81       2975                    20
          7788 SCOTT      ANALYST         7566 09-DEC-82       3000                    20
          7876 ADAMS      CLERK           7788 12-JAN-83       1100                    20
          7902 FORD       ANALYST         7566 03-DEC-81       3000                    20
    TEST@db102 >

  • How to copy the attribute values of one instance  into another instance.

    Say I have 3 instances and two attributes name ,id.
    inst1 : id:1 ,name:abc
    inst2: id:2 ,name:bcd
    inst3: id:3 ,name:efg
    now I want
    inst: id:1 ,name:abc
    bcd
    efg
    i.e is need to abort instance inst2 & inst3 before that copy the names bcd & efg to inst1.
    Please let me know how to do this its very urgent.

    Hi,
    The tricky part of this is to provide your third instance a way to find the other two instances. Finding instances in a process is a bit like finding rows in a database. When doing a SELECT statement in a database, you have a primary key that will guarantee you that you'll only retrieve one row. In Oracle BPM there are a couple ways to do this. One way is to use the instance's id (the predefined variable id.id) to search for the two instances. Another is to use a "correlation" to find the instances.
    This example assumes you'd like to look at instances based on a search filter. This filter assumes that you have a customerId variable that both of the instances share. It only returns those instances currently inside the process (the SearchScope logic below being set to "StatusScope.ONLY_INPROCESS" in the logic below). The only incoming variable it needs is the "customerId" variable that has already been set to some value in the other instance. Note that this uses the Fuego.Papi.ClientBusinessProcess object. This logic creates a search filter and only returns instances that meet a certain criteria (the two instances in the process). Once you get the instance, the "getVar()" method retrieves the "name" instance variable. This assumes that you have an instance variable "customerNames" defined as a String array that you are using to store the names retrieved from the two instances. The "abort()" method aborts the two instances it finds in the search.
    cbp as ClientBusinessProcess = ClientBusinessProcess()
    connectTo(cbp, processId : "/NameOfYourProcessHere")
    instF as InstanceFilter = InstanceFilter()
    create(instF, processService : cbp.processService, viewId : "TypeSearch")
    instF.searchScope = SearchScope(participantScope : ParticipantScope.ALL,
                                  statusScope : StatusScope.ONLY_INPROCESS)
    logMessage "Customer Id is: " + customerId  using severity = DEBUG
    addAttributeTo(instF, variable : "customerId",
                              comparator : IS, value : customerId)
    for each inst in getInstancesByFilter(cbp, filter : instF) do
       // get the value of the order's amount for the instance
        instanceVarValue as Object = getVar(inst, var : "name")
        customerNames[] = String(instanceVarValue)
        logMessage "Customer name is: " + String(instanceVarValue) 
                 using severity = DEBUG
        // aborts the instance in the process
        inst.abort()
    endHope this helps,
    Dan

  • Input result from a SQL-query into a Variable in ProcessFlow

    I am trying to select a value from a table with file names.
    This file name should be input to an ftp function. I use a owb function to read the file name then I try to asign the result to a variable.
    The function GET_FILENAME looks like
    f_name varchar2(30);
    BEGIN
    select distinct FILENAME_SOURCE into f_name from CTL_SOURCE_FILES
    where FILEID = (select min(FILEID) from CTL_SOURCE_FILES where status is null);
    RETURN f_name;
    END;
    When running it as a SQL-script it returns only one row/name.
    When I am running it in the ProcessFlow the following message is found:
    RPE-02040: Internal error: GET_FILENAME cannot be converted to a constant value.

    Let me talk about this in context of a mapping:
    create a mapping :
    use a function within a mapping
    assign the output of the mapping to a mapping input variable"
    use this mapping within your process flow and see if it works.
    if you are directly going to use the output of a function in a process flow , the FTP should be able to accept the filename from the outparam of the function which i am not sure how it works.
    try using the first approach as it is relatively simple and straightforward.

  • My wife has iCloud on our computer and I want to break out and create my own account. Once I build the account how do I copy the address book from her account into mine?

    my wife has icloud on our computer and I want to break out and create my own icloud account. I've built the account but can't figure out how to COPY our joint address book onto my account so I can then weed out my own addresses. Please help!

    Welcome to the Apple Community.
    When you log out of the joint account, you should be asked if you want to keep the contacts, you do. When you log into your new account you should be asked if you want to merge contacts, you do.
    If you have already signed into your new account and not taken these options, the simplest thing to do might be to add your wife's account back as a secondary account in system preferences > mail, contacts & calendars. In groups in address book you can drag contacts from your wife's contacts onto your contact group to copy them.

  • Copy the existing output rom Z program into a  spool file

    Hi all,
    There's a Zprogram if its run in foreground a list gets created .(as per req, i want this list in a spool file and not the below spool file)
    If this program is run in background a spool file gets created.
    I dont want the existing spool result instaed i want the other result which is generated via se38  as a spool file.
    Pls suggest.
    One more question is i don't see any code in program where the existing spool file is written.similarly i have checked another program earlier where i dont see the code where exactly spool file gets created ,moreover no sub programs in that too.
    Thanks for the help.

    Hi ,
    I don't want existing spool data.
    But i need the list in foreground run to be saved as the spool file.
    will commenting out  the statements which writes to current spool file(yet to identify this part of the code) be a good option
    Or,
    If i can create another spool file ,how to do it.
    basically how to create 2 spool file in the same program,1 spool is already getting created..
    Thanks,

  • How to copy the value of default view textbox into another view textbox

    I create one form library and customizing in infopath 2010. on this default view one textbox is placed. in which user will enter his name.
    I create another view. in which i also place second textbox. I want when user put his name in default view textbox and save the form . then his name also copy into another view textbox .
    Kindly let me know how to do this ?

    Hi John,
    You can achieve in infopath. Steps are below:
    Default Text Box (Infopath Field A)
    Mirror Text Box (Infopath Field B)
    In Mirror Text Box, the default value would be the Field A. The default value you specified by right click on Mirror Text Box --> Properties...
    Thanks,

  • How do I copy the string portion of an enum into the string portion of a cluster?

    I want to do this for the an entire array of clusters.  I'm trying to use a for loop.  Can't figure out how to parse the string portion of the enum into the string portion of the cluster.
    Alternatively, I'd be happy if I could figure out some way to tie the enum to the array of clusters, but I figure that gets problematic.
    DH
    Solved!
    Go to Solution.

    Dark Hollow wrote:
    OK, let's say that the enumerated type has N elements.  I want to initialize an N element array of strings.  How do I reference each string in the enumerated type to get to each string?
    Easy way to do this is to use GetNumericInfo.vi, part of the Variant library, found in vi.lib\utility\VariantDataType\GetNumericInfo.vi.  Wire your enumeration to the Variant input; one of the outputs is an array of the strings in the enumerated type.
    The more complicated way is a for loop, in which you typecast the iterator terminal value to the enumerated type, then use Format Value.  You can get the maximum value of the enumeration by casting 0 to the enumerated type, then decrementing; cast that back to a numeric and add one to get the right value to wire to the N terminal.
    EDIT: just thought I'd add, since RavensFan's reply popped up while I was writing mine - I don't like the Strings[] approach because it doesn't work on RT targets, and I lost a lot of time once due to this trying to figure out why my code wouldn't run properly on an RT system but worked great on my development computer.

  • How can I copy the addressees of a sent mail into a fresh mail that I'm composing, with some addressees deleted?

    I want to be able to select the addressees of a new mail from those of a sent mail. I want to be able to copy some of the addressees from those of the previous mail, but not all. Is there a simple way of copying all the old addressees in one operation and then selecting some addressees for deletion in one operation?

    Please note that I also said "and then selecting some addressees for deletion in one operation". I had already seen and used "edit as new message", which solves the problem of reselecting the old addressees very well. Incidentally, I discovered (by accident) that if you click on "reply" for a sent message, it actually goes as a message from you to the same old addressees! However, it adds a bit of text at the beginning referring to the fact that you sent the previous message, mentioning date and time (and quotes the previous text), so if you don't want that to go you have to edit it out along with the the previous text and delete the attachments, exactly as you would have to do for "edit as new message".

  • Using a Mac and gmail, comcast & yahoo email clients. When I rcv links in my emails and I try to load them, they don't load into Firefox. I have to copy the link and paste it directly into the browser to activate it. Anybody have this same problem?

    Links not loading in Firefox when you select them in the body of the email

    Managed to solve this myself. Just went to properties > hidden.

  • :new and :old into record into record variable

    Hi,
    Can anyone tell me whether it is possible in 11g to copy the :new and :old records straight into record variables without having to explicitly copy every column?
    I would prefer to write this:
      create or replace trigger app1_tab1_biudr
      before insert or update or delete
      on table_1
      as
      declare
        r_tab1_old table_1%rowtype;
        r_tab1_new table_1%rowtype;
      begin
         r_tab1_new := :new;
         r_tab1_old := :old;
      end app1_tab1_biudr;instead of this
      create or replace trigger app1_tab1_biudr
      before insert or update or delete
      on table_1
      as
      declare
        r_tab1_old table_1%rowtype;
        r_tab1_new table_1%rowtype;
      begin
         r_tab1_new.col1 := :new.col1;
         r_tab1_new.col2 := :new.col2;
         r_tab1_new.col3 := :new.col3;
         -- ... etc.
         r_tab1_old.col1 := :old.col1;
         r_tab1_old.col2 := :old.col2;
         r_tab1_old.col3 := :old.col3;
         -- ... etc.
      end app1_tab1_biudr;Why? This is nonsense example, of course, but when we apply this to our table API's, it would make a big difference in the length and maintainability of the code.
    Thanks!
    Remco

    RemcoGoris wrote:
    Hi,
    Can anyone tell me whether it is possible in 11g to copy the :new and :old records straight into record variables without having to explicitly copy every column?I'm not sure with 11g if they've introduced it, but to the best of my knowledge, this has never been something that has been possible as the :new and :old are intrinsicly tied into the internals of the triggers (i.e. I think they, internally, hold more information about the changed rows than just being a simple rowtype structure)

  • Pass Pl/sql table into USING clause in EXECUTE IMMEDIATE statment

    Getting error when I try to pass the PL/SQL table into USING clause in EXECUTE IMMEDIATE statment:
    Declare
    result NUMBER;
    TYPE values_tab IS TABLE OF NUMBER INDEX BY BINARY_INTEGER;
    lv_tab values_tab;
    lv_exp varchar2(300);
    lv_exec varchar2(300);
    BEGIN
    lv_tab(1) := 5;
    lv_tab(2) := 48;
    lv_tab(3) := 7;
    lv_tab(4) := 6;
    lv_exp := ':b1+:b2+(:b3*:b4)';
    lv_exec := 'SELECT '||lv_exp ||' FROM DUAL';
    EXECUTE IMMEDIATE
    lv_exec
    INTO
    result
    USING
    lv_tab;
    DBMS_OUTPUT.PUT_LINE(result);
    END;
    Error at line 1
    ORA-06550: line 20, column 12:
    PLS-00457: expressions have to be of SQL types
    ORA-06550: line 15, column 8:
    PL/SQL: Statement ignored
    I am trying to evaluate the expression ":b1+:b2+(:b3*:b4)" which is stored in table. This table has different expressions (around 300 expressions). I want to use the bind variables in expression because each expression evaluated thousand of time may be more in some case. If I don't use bind variable then it fill shared pool.
    Is there any way I can pass the USING (IN) parameters dynamically instead of writing "USING lv_tab(1), lv_tab(2), lv_tab(3), lv_tab(4)"? As number of input parameters change depend on the expression in the table.
    If not possible please suggest any other ideas/approches
    Please help..
    Edited by: satnam on Jun 11, 2009 11:50 AM

    Well, you keep changing reqs faster I can keep up. Anyway, assuming N-th bind variable (left-to-right) corresponds to collection N-th element:
    Declare
        result NUMBER;
        lv_tab values_tab := values_tab();
        lv_exp varchar2(300);
        lv_exec varchar2(300);
        lv_i number := 0;
    BEGIN
        lv_tab.extend(4);
        lv_tab(1) := 5;
        lv_tab(2) := 48;
        lv_tab(3) := 7;
        lv_tab(4) := 6;
        lv_exp := ':5000135+:5403456+(:5900111*:5200456)';
        lv_exec := lv_exp;
        While regexp_like(lv_exec,':\d+') loop
          lv_i := lv_i + 1;
          lv_exec := REGEXP_REPLACE(lv_exec,':\d+',':b(' || lv_i || ')',1,1);
        end loop;
        lv_exec := 'BEGIN :a := ' || lv_exec || '; END;';
    DBMS_OUTPUT.PUT_LINE(lv_exec);
    EXECUTE IMMEDIATE lv_exec USING OUT result,IN lv_tab;
    DBMS_OUTPUT.PUT_LINE(result);
    END;
    BEGIN :a := :b(1)+:b(2)+(:b(3)*:b(4)); END;
    95
    PL/SQL procedure successfully completed.
    SQL> SY.

Maybe you are looking for

  • Wi-Fi Sharing doesn't work together with mini Display port

    Hello everyone! I can tell you fantstic problem. Sorry for my English - i'm from Russia! The problem: 1. Share Wi-Fi via bonjour to other devices such as iPad, iPhone, windows computers, etc. I'm using Mac os X Snow Leopard! Everything is fine! 2. Ju

  • KSV5 distribution reverse

    Hi Experts I have run distribution run for allocating the distrebuted expenses from one cost center (X) to some other cost centers. Than I have realized that one GL posting transaction was done by mistake for this cost center X, and so was distrebute

  • Reference array in object

    Forgive me, I a new to Java. All I am trying to do is have an array dedicated to an object, that is encapsulated inside it. But now I the compiler can't recognize the 'array' array. How do I call the array from a particular object? I tried the object

  • Adobe flash player not working properly

    I just tried to play a game, but  the game says i need flash player 8 or up. I have the latest version, so it shouldn't say that. So I tried to re-install both the game and flash player several times, but that didn't work. For the rest, flash player

  • HT1689 I bought an app and I got charged twice? Can I get the balance back?

    I lost almost 10$ from my account. Actually it's for my daughter.