Can i include variable in select into statement?

Hi all,
Is it possible to include a variable name in the "select into" statement ? For ex:
"Select empname into variable_Name from employee" In this case variable_Name is the variable.Will this statement work by assigning empname to variable_Name if there is only one record in the employee table?please reply....c ya.

Surely you have to? You can hardly SELECT INTO a constant. Perhaps I'm missing something,

Similar Messages

  • Using SELECT INTO statement to transfer data from one DB to another?

    Hello,
    I need to move data from an SAP table to another downstream SQL server box without flat file in between. I have set up the DBCON interface, so that my ABAP code on SAP can connect to the remote SQL Server, then I can run INSERT command as Native SQL inside the ABAP.
    However, INSERT has performance problem. The best performer as I can find is SELECT INTO statement. But then I am stuck at how to use SELECT INTO to query my local SAP table and send (via INTO) to remote database. I am not even sure whether I should use Open SQL or Native SQL.
    Any suggestion? BTW, I understand the limitation of Native SQL, but we are OK to use it.
    Thanks!

    It appears that this is some kind of migration project due to the scope of the data contained in the single file? If so whatever you do is like ly to be trow away once the migration of data is completed.
    You have a couple of options:
    1) Get the data extracted from HFM in multiple files instead of one bulk file, broken down by scanario,year & period
    2) Take the single data dump file produced by FDM and manipulate it yourself to get the data in a more usuable format for processing through FDM.
    Option 2 could be achieved via any ETL tool or a custom file parsing script. What may be more attractive to you and allow you to fully leverage your investment in FDM is that you could use the PULL adapter that ships as part of the FDM adapter suite to perform this transformation exercise. The PULL adapter takes a flat file input and allows you to use all the in built functionality of FDM to transform it and output a modified flat file (or series of flat files). You could use it to produce multioload files or a series of files broken down by scenario,year,period.
    Whatever you do I would suggest that break the single data file down into smaller chunks as this will help with the iterative debugging process you will inevitably have to undetake whislt migrating the data to the new application.

  • Where clause in SELECT INTO statement

    Hi,
    I am using multiple conditions in where clause for my SELECT INTO statement as follows.
    SELECT count(DTLA.LOCATION_ID)
    INTO LOCATION_ID_count
    FROM DOC2_MGR.DOC_TYPE_LOB_ASSOC DTLA
    WHERE (DTLA.DOC_TYPE_ID = 'XYZ' AND DTLA.lob_code = 'ABC');
    It considers only first condition and returns the result i.e. DTLA.DOC_TYPE_ID = 'XYZ' only.
    Does select into statement suppose to consider only one condition in where clause???
    Thanks in advance!
    --Sandeep                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    I got it resolved. Here is list of things I noted
    1. I was using variable names same as column names. It was mixing up temp variable names with column name on the table, which doesn't make sense as I was referring column names in table.column format
    2. I had mixed few datatypes. Input param was suppose to be number where as I was passing it as Text
    Thanks anyway!
    --Sandeep                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • How can we include the property value into the News RSS?

    We have defined object property u201CDepartmentu201D that is used in News XML creating form. How can we include the property value into the News RSS (set value of the particular RSS XML tag)?

    We have solved the issue with NWDS

  • How to modify a Procedure "select into" statement to use a cursor

    The below code fails with exception too many rows. How do I modify the Procedure's Select Into statement to use a cursor?
    CREATE OR REPLACE PROCEDURE Track_Asset(
       business_date IN NUMBER DEFAULT NULL,
       missing_table_name  OUT VARCHAR2)
    IS
       ln_business_date NUMBER;
        incorrectdateformat EXCEPTION;
    BEGIN
       IF business_date < 0
       THEN
          RAISE incorrectdateformat;
       ELSE
          DECLARE
            ln_business_date NUMBER;
          BEGIN
             SELECT MAX(business_date)
             INTO ln_business_date
             FROM sproof ;
          EXCEPTION
            WHEN NO_DATA_FOUND THEN
             dbms_output.put_line('NO MATCH FOUND');
            WHEN OTHERS THEN
            dbms_output.put_line('ORACLE ERROR :' || SQLERRM);       
          END;
          DECLARE
            missedfeedfnd EXCEPTION;
          BEGIN
             SELECT 'Missing Value : ' || table_name
             INTO missing_table_name
             FROM (
                SELECT UPPER(table_name) table_name
                FROM filespec
                WHERE data_table_name IN ('TABLE1','TABLE2','TABLE3')
                MINUS (
                SELECT DISTINCT UPPER(first_table_name)
                FROM dpca
                WHERE business_date = ln_business_date
                AND first_table_name IN ('TABLE1','TABLE2','TABLE3')
                GROUP BY UPPER(first_table_name) UNION
                SELECT UPPER(first_table_name)
                FROM dpca
                WHERE business_dt_num = TO_NUMBER( SUBSTR('201111', 1, 6) || '01' )
                AND first_table_name = 'TABLE4'
                GROUP BY UPPER(first_table_name) ));
                IF missing_table_name  IS NOT NULL THEN
                   dbms_output.put_line('Missing Value : '|| missing_table_name);
                   RAISE missedfeedfnd;
                ELSE
                  NULL;
                END IF;
          EXCEPTION
             WHEN TOO_MANY_ROWS THEN
       DBMS_OUTPUT.PUT_LINE (' SELECT INTO statement retrieved multiple rows');
              WHEN missedfeedfnd THEN
              raise_application_error ( - 20003, 'Missed Feed');
          END;
        END IF;
          EXCEPTION
       WHEN incorrectdatevalue
       THEN
          raise_application_error ( - 20001, 'Incorrect/Bad Date Entered');
    END;

    ok try this - OUT param will be populated with comma separated list of table names:
    PROCEDURE Track_Asset(
       business_date IN NUMBER DEFAULT NULL,
       missing_table_name  OUT VARCHAR2)
    cursor c_table_names is
    select datatablename
    from   ( select upper(datatablename) datatablename
             from   filespec
             where  data_table_name in ('TABLE1','TABLE2','TABLE3'                                 )
            MINUS
            ( select upper(first_table_name)
              from   dpca
              where  business_dt_num = [-- this date is retrieved by getting the MAX(business_date) from sproof table]
                     and fus_data_table_name in ('TABLE1','TABLE2','TABLE3'
              group  by
                     upper(first_table_name)
             UNION
              select upper(first_table_name)
              from   dpca
              where  business_dt_num = to_number( substr('201111',1,6) || '01' )
                     and first_table_name = 'TABLE4'
              group  by
                     upper(first_table_name)
    begin
       for rec in c_table_names
       loop
           missing_table_name  := missing_table_name  || rec.datatablename ||',';
       end loop;
       missing_table_name  := rtim(missing_table_name , ',');
    end ;HTH
    Edited by: user130038 on Dec 28, 2011 8:46 AM

  • SELECT INTO statement

    Hello
    I have entered the following statement into the SQL Command Processor in HTML Db:
    select * into DEMO_CUSTOMERS_COPY from DEMO_CUSTOMERS
    I get the following error:
    ORA-00905: missing keyword
    Can anyone tell me why I'm getting this error? I think the syntax of the statement looks ok to me but I may be wrong
    Thanks,
    Simon

    Hi Simon,
    No problem...glad to help.
    Your original command (with a little modification) is the sort of thing you usually see in PL/SQL where you want to extract a column (or record) from a table, for example
    SQL> set serveroutput on;
    SQL>  declare
       v_value dual.dummy%TYPE;
    begin
      select
        dummy
      into
        v_value
      from dual;
      dbms_output.put_line('The value is: ' || v_value);
    end;
    The value is: XNote that "select..into" requires only one row to be returned, so if multiple rows are returned then you'll get a TOO_MANY_ROWS exception.
    Hope this helps.

  • How can  I include my database file into my jar file?

    Hi,
    I am doing several tests for the jar command....
    I tried to put the database file into my jar file, but when the program run, it just couldn't find the database file, so how may I include the database file into the jar file? Not only that, it also can't find the policy file etc.

    sorry, I think I found the solution, I should have had read the API more carefully.

  • Select Into statement in db function - query from granted schema table

    problem with "select into" in db function in 10.2
    There are two schemas. 'mdbdev' is the master database and 'devusr' is granted SELECT table access to execute queries in mdbdev schema.
    with devusr, in SQL, I'm able to execute the following query
    select wm_concat(strConcatedCountryList)
    from (select country_name as strConcatedCountryList from mdbdev.country_master mdbcm
    where mdbcm.country_ship_status = <param?>
    order by country_name)
    but when I use the same query in function/procedure with "select into", the compilation failed with error *"table or view does not exist"*
    FUNCTION GETCOUNTRYLISTTOSHIP (SHIP_STATUS IN NUMBER)
    RETURN VARCHAR2
    IS
    var2CountryList VARCHAR2(1000);
    BEGIN
    select wm_concat(strConcatedCountryList) INTO var2CountryList
    from (select country_name as strConcatedCountryList from mdbdev.country_master mdbcm
    where mdbcm.country_ship_status = <value of SHIP_STATUS>
    order by country_name);
    return var2CountryList;
    END;
    Please advise/help/hint :)

    David, Justine, Thank you. The facts from this forum post helped a lot to get the solution.
    The query helped a lot (select * from all_tab_privs_recd where owner = 'MDBDEV' and table_name = 'COUNTRY_MASTER").
    there was a grant using ???(donno wht DBA said) and no direct SELECT grant on that country_master to "devusr". grant command executed. Now, it works :)

  • Question  on select  into  statement

    hi,
    all oracle gurus,
    my requirement is as follows
    i have a select statement that should be executed dynamically.
    The records fetched by the select statement should be stored in a pl/sql table.
    my select statement is like this.
    Execute immediate'
    select null,rh.rec_no,p.lot,pr.each_qty,sl.color_zone,:p_comp_id,pr.unit_cube*(nvl(p.qty,0)/nvl(pr.each_qty,1)),
    sysdate,pr1.each_qty,p.prod_no,:p_ebiz_user_no,nvl(sl.wdth,0) * nvl(sl.dpth,0),decode(s.haz_mat_class,null,''N'',''Y''),
    sl.home_zone,''N'',r.line_no,p.end_loc, p.lp, nvl(p.access_aisle,''N''),round(nvl(p.qty,0)/nvl(pr.each_qty,1)),
    1, p.pkg_no, r.p_line_no, rh.po_no,r.putaway_strategy,p.qty,rh.rec_type,:p_site_id,s.sku, s.sku_desc1_35,
    s.prod_fam,s.prod_cat,p.prod_stat,2,sysdate, ''Handling'', bt.task_type,nvl(sl.type_stor_equip,''100''),
    p.uom,pr.unit_wght*(nvl(p.qty,0)/nvl(pr.each_qty,1)),:p_ebiz_appown_no
    from [email protected] s,mast_abbtype bt,mast_company bc,[email protected] pr,[email protected] sl,
    [email protected] r,[email protected] rh,[email protected] p,[email protected] pr1
    where p.end_time is not null
    and decode(bt.comp_id,null,:p_comp_id,bt.comp_id)= :p_comp_id
    and decode(bt.site_id,null,:p_site_id,bt.site_id)=:p_site_id
    and bt.task_type = :p_task_type
    and bc.comp_id = :p_comp_id
    and p.proc_cntrl_no =r.rec_cntrl_no
    and bc.ebiz_appown_no=61
    and bt.delete_flag=''N''
    and r.rec_cntrl_no = rh.rec_cntrl_no
    and p.proc_cntrl_no = nvl(:p_po_no,p.proc_cntrl_no)
    and p.prod_no = nvl(:p_ebiz_sku_no, p.prod_no)
    and nvl(p.prod_stat, ''~'') =nvl(:p_sku_status, nvl(p.prod_stat, ''~''))
    and p.lp = nvl(:p_lp, p.lp)
    and nvl(p.lot, ''~'') = nvl(:p_batch_no, nvl(p.lot, ''~''))
    and r.lp = p.lp
    and p.prod_no = s.prod_no
    and p.prod_no = pr.prod_no
    and p.pkg_no = pr.pkg_no
    and pr.logical_case_flg = ''Y''
    and p.end_loc = sl.loc
    and nvl(p.sku_key3,''A'') != ''1''
    and decode(''COMP'',''BYID'',s.buyer_id,s.comp_code) = bc.comp_id
    and bc.comp_id =:p_comp_id
    and r.cart_lp is null
    and trunc(p.date_time_created) between trunc(nvl(SYSDATE-10000,p.date_time_created))
    and trunc(nvl(SYSDATE,p.date_time_created))
    and trunc(p.date_time_created) >= trunc(bc.effective_date)
    and pr.prod_no = pr1.prod_no and pr.pkg_no = pr1.pkg_no and pr1.logical_plt_flg = ''Y'' '
    using p_comp_id,p_ebiz_user_no,p_site_id,p_ebiz_appown_no,p_comp_id,p_comp_id,p_site_id,p_site_id,p_task_type,p_comp_id,
    p_po_no,p_ebiz_sku_no,p_sku_status,p_lp,p_batch_no,p_comp_id;'
    what i want is the records selected by the select statement should be stored in a pl/sql table.
    pls treat this as urgent.
    ur valuable suggestions are always most welcome.
    regards
    RR

    Hi,
    Here's an exmaple that will help you do it :-
    DROP TABLE TABLE1;
    CREATE TABLE TABLE1( SYMBOL VARCHAR2(2) PRIMARY KEY, NAME VARCHAR2(10), QUANTITY NUMBER, PRICE NUMBER,  DATE_  DATE);
    INSERT INTO TABLE1(SYMBOL,NAME,QUANTITY,PRICE,DATE_) VALUES('10','Apples',100,10,SYSDATE);
    INSERT INTO TABLE1(SYMBOL,NAME,QUANTITY,PRICE,DATE_) VALUES('20','Oranges',100,10,SYSDATE);
    INSERT INTO TABLE1(SYMBOL,NAME,QUANTITY,PRICE,DATE_) VALUES('30','Mangoes',100,10,SYSDATE);
    COMMIT;
    DECLARE
                      RC1 SYS_REFCURSOR;
                   ln_NAME TABLE1.NAME%TYPE;
    BEGIN
                   OPEN RC1 FOR 'SELECT NAME FROM TABLE1';
                   FETCH RC1 INTO ln_NAME;
                   WHILE( RC1%FOUND )
                   LOOP
                                  DBMS_OUTPUT.PUT_LINE(ln_NAME);                  
                              FETCH RC1 INTO ln_NAME;
                   END LOOP;
                   CLOSE RC1;
    END;
    Apples
    Oranges
    MangoesRegards,
    Sandeep

  • Select into statement returns 0 or 1

    Hello, when i run the select statement below ,the result in count field is 0 when the record is not exist and 1 when the record is exist
    but the real value doesn't appear in the field , what the problem exactly .........i want to show the real value in the field.
    when_button_pressed
    BEGIN
    SELECT count into :add.count FROM storge
    where barcode=:add.barcode;
    END;

    M3ATH wrote:
    SELECT count into :add.count FROM storge
    where barcode=:add.barcode;
    END;Try this...
    BEGIN
    SELECT count(barcode) into :add.count FROM storge
    where barcode=:add.barcode;
    END;Hope this helps
    If someone's response is helpful or correct, please mark it accordingly.

  • How can I include Java Bean model into the model outside the component

    Hi All,
    I am new to SAP portal. I wanted to create a bean for storing the data and to include that into the application model.
    Please help me with an example .
    Regards,
    Saroj

    Hi,
      Check these blogs.
    The specified item was not found.
    Importing Complex JavaBean model into WebDynpro by creating relationships for the model classes
    JavaBean Model Import: when it really works
    Issue in Importing Java Bean Model
    Regards,
    Harini S
    Consider rewarding points for helpful answers. Post this thread in WD forums for more results.

  • "select into" query statements using the DI API

    I am trying to use the DI API (6.5) t create a temp table based on an existing table.  For example, here is a query string....
    select * into ORDR_TEMP from ORDR
    Code...
    oRecordSet := IRecordset(oCompany.GetBusinessObject(BoRecordset));
    oRecordset.DoQuery(sSql);
    Error I get...
    1). [Microsoft][ODBC SQL Server Driver][SQL Server]Cannot use SELECT INTO in browse mode. 2). [Microsoft][ODBC SQL Server Driver][SQL Server]Statement(s) could not be prepared
    For any other regular select statements the previous code works.  Does anyone know for sure if a "select into" statement is not possible using the DI API?

    Hi Bill,
    I´m not really sure if select into is avaiable. But here you´ve got a hint: You could use a user defined function to do it, and just call the function from your code.
    SELECT dbo.MyFunction()
    Having this function defined in your SQL Server:
    CREATE function MyFunction ()
    returns char(2)
    AS
    Begin
    select * into ORDR_TEMP from ORDR
    Return ('OK')
    End
    Hope this helps,
    Ibai Peñ

  • Select into aggregate function

    Hi,
    I have the following PL/SQL block that I am testing. The block reads a list of values from a local file and inserts the values into a select statement that uses an aggregate function. Here is my code:
    DECLARE
    f utl_file.file_type;
    n COLa%TYPE; --holds values from the file
    v COLb%TYPE; --holds value returned by select statement
    BEGIN
    f := utl_file.fopen(dir,file.txt,'R');
    loop -- loop through file
         utl_file.get_line(f,n);
         if length(n) <> 0 then
              SELECT max(A0.COLa) into v
              FROM (SELECT AOB.COLa, A0.COLb
              FROM TAB1 A0,TAB2 A0B
              WHERE (A0.PK=A0B.PK) and A0B.COLa = n) A0;          
              IF SQL%rowcount = 0 THEN
                   dbms_output.put_line('no rows);
              else
                   dbms_output.put_line(v);
              end if;                    
         end if;     
    end loop;
         utl_file.fclose(f);     
    end;
    Here is the error I get:
    declare
    ERROR at line 1:
    ORA-01403: no data found
    ORA-06512: at "SYS.UTL_FILE", line 98
    ORA-06512: at "SYS.UTL_FILE", line 656
    ORA-06512: at line 12
    I checked the database for the first couple of values in the list and got rows. I also ran a simple PL/sql code to print values in the file successfully. So I dont know why it is returning no data found. From what I understand select into statement using aggregate functions will never raise this exception, so why I am getting this error?
    Thanks.

    Hi,
    Actually, the SELECT ... INTO isn't the problem here.
    Look at the error message:
    ERROR at line 1:
    ORA-01403: no data found
    ORA-06512: at "SYS.UTL_FILE", line 98
    ORA-06512: at "SYS.UTL_FILE", line 656
    ORA-06512: at line 12The error is ocurring inside utl_file, which is being called at line 12 of your code. (That must be
    utl_file.get_line(f,n);)
    Utl_file.get_line raises NO_DATA_FOUND when it reaches the end of the file. (If it didn't you'd have an infinite loop, since your code doesn't have any exit strategy.)
    You can put the call to get_line in its won BEGIN-EXCEPTION-END block, and trap the NO_DATA_FOUND error.
    For example:
    end_of_file := 0;
    WHILE  end_of_file = 0;
    loop -- loop through file
        BEGIN
            utl_file.get_line(f,n);
            if length(n) != 0 then          -- Use !=, because you can't post &lt;&gt; on this site
                SELECT  max(A0B.COLa)     -- No sub-query needed
                into    v
                FROM    TAB1 A0
                ,         TAB2 A0B
                WHERE   (A0.PK   = A0B.PK)
                and         A0B.COLa = n;
                IF SQL%rowcount = 0 THEN     -- Not needed: SELECT MAX ... without GROUP BY always returns 1 row
                    dbms_output.put_line('no rows);
                else
                    dbms_output.put_line(v);
                end if;
            end if;
        EXCEPTION
            WHEN  NO_DATA_FOUND
            THEN
                end_of_file = 1;
        END;
    end loop;Edited by: Frank Kulash on Jul 17, 2009 2:51 PM

  • Anonymous Block with Variable and SELECT

    Hi Guys,
    I am struggling to connect the material I am learning. I read about anonymous blocks and variables so I want to write a
    nice and neat select with all the fancy stuff (variables, exceptions) to get it right and to it as I read in the book.
    DECLARE
    MYSTRING VARCHAR(10);
    MYSTIRNG := 'X';     
    BEGIN
    SELECT * FROM DUAL WHERE DUMMY = MYSTRING
    END;
    but....this causes one error after the other. Am I getting the concept wrong here or is it a syntax error?

    cant I just get the result without using variable to store the result in the first place???Perhaps you're better off using a REF CURSOR (a.k.a. cursor variable).
    That way you'll pass a resultset to the caller and you don't need any variables to select into.
    You can read about them here:
    http://www.oracle-base.com/articles/misc/UsingRefCursorsToReturnRecordsets.php
    Re: PL/SQL 101 : Understanding Ref Cursors
    http://download.oracle.com/docs/cd/E11882_01/appdev.112/e10766/tdddg_subprograms.htm#TDDDG99939

  • Dynamic Pivot with Select Into

    I have this Dynamic Pivot which works fine.
    DECLARE @query VARCHAR(4000)
    DECLARE @years VARCHAR(2000)
    SELECT @years = STUFF(( SELECT DISTINCT'],[' + [factor_label]
    FROM [TEMP_lacp_factors]
    ORDER BY '],[' + [factor_label]
    FOR XML PATH('')
    ), 1, 2, '') + ']'
    SET @query =
    'SELECT * FROM
    SELECT [date_],[issue_id],[cusip],[Factor_value],[factor_label]
    FROM [TEMP_lacp_factors]
    )t
    PIVOT (MAX([factor_value]) FOR [factor_label]
    IN ('+@years+')) AS pvt'
    EXECUTE (@query)
    I'm trying to take the results of that and do a SELECT INTO, so I can move the results to another table.  Is this possible?  I didn't find a whole lot online.
    The error that I'm getting is this.
    Caused by: Column name or number of supplied values does not match table definition.
    How can I do this?  Is it even possible?
    Knowledge is the only thing that I can give you, and still retain, and we are both better off for it.

    Sure, you can create a table with SELECT INTO, but it cannot be a #temptable. Well, it can be a #temptable, but it will disappear as soon as you exit the scope it was created it, that is the dynamic SQL.
    The question is only, what would you do with this table later? Since you don't know the column names, about all work will have to be done through dynamic SQL.
    A dynamic pivot is a non-relational operation. A SELECT statement produces a table, and a table describes a distinct entity, of which the column are distinct and well-defined attributes. Something which your dynamic pivot does not adhere to.
    There is only one thing you can do with your dynamic pivot: returning the data to the client. I don't know what you want to do with that table, but probably you should do that manipulation before the dynamic pivot, because as I said: that is always your
    last step.
    Erland Sommarskog, SQL Server MVP, [email protected]

Maybe you are looking for