Select * into table_name in oracle

Hi,
I would like to create a table in Oracle much like the way I do it in Sybase
SELECT * INTO mytable FROM t WHERE 1 = 2
gothanks,
Ashok

Try this (CTAS)
CREATE TABLE t AS SELECT * FROM mytable WHERE 1 = 2;Note that unlike Sybase where you need database option 'SELECT INTO' turned on for SELECT INTO, the above wiil work with no issue in Oracle.
As usual ensure that you have enough free space in Oracle database. CTAS will not create any other DDL statement like primary key constaint or indexes as they were on the original table (mytable).
HTH,
Mich

Similar Messages

  • MS-SQL - Oracle SELECT INTO conversion problem...

    Under MS-SQL (T-SQL) Select statement is defined as follows:
    SELECT select_list
    [INTO new_table_]
    ^^^^^^^^^^^^^^^^^^^^^
    FROM table_source
    [WHERE search_condition]
    [GROUP BY group_by_expression]
    [HAVING search_condition]
    [ORDER BY order_expression [ASC | DESC] ]
    Q:How under PL/SQL can one redirect sorted (ORDERed BY) results
    from SELECT query to another table.
    Slawek
    null

    I have asked the question because of the following reason:
    I have a large select query that returns rows from a table in
    different sort orders depending on user inputs, and I wonder if
    there is any way to return just the rows between two specified
    positions.
    I figured that I'm going to either create one temporary table
    with all the data (1000 records for example), sort the data in
    the prefered order and use the rownum method to obtain the row
    range (works fine under T-SQL). Other way is to try an inline
    view that return the rownumber. I can then restrict the numer of
    fields, e.g.
    select empid, rowNumber from emp,
    (select empid as id, rownum as rowNumber from emp) x
    where empid = id
    and rowNumber between 2 and 5
    The problem is that under Oracle the subquery is not allowed to
    have an ORDER BY clause (even if it had, rownum reflects row
    numbers before they were sorted) and there is no SELECT into
    TABLE_NAME.
    Michael Malicky (guest) wrote:
    : Slawek (guest) wrote:
    : : Under MS-SQL (T-SQL) Select statement is defined as follows:
    : : SELECT select_list
    : : [INTO new_table_]
    : : ^^^^^^^^^^^^^^^^^^^^^
    : : FROM table_source
    : : [WHERE search_condition]
    : : [GROUP BY group_by_expression]
    : : [HAVING search_condition]
    : : [ORDER BY order_expression [ASC | DESC] ]
    : : Q:How under PL/SQL can one redirect sorted (ORDERed BY)
    results
    : : from SELECT query to another table.
    : : Slawek
    : Order by is irrelevant when creating a new table out of a
    : query, as the rows are NOT stored in any order in a table.
    : The syntax for creating a new table out of an existing one
    : is:
    : CREATE TABLE new_table AS
    : SELECT select_list FROM old_table
    : WHERE ...
    : etc.
    : /mike
    null

  • Converting MS-Access select * into... to run in Oracle

    I have this stored procedure in MS Access:
    create procedure foo as
    begin
    if exists(select name from sysobjects where name='cif_retail)
    drop table 'cif_retail'
    select * into cif_retail from cif where cstresf=1
    end
    The above stored procedure checks if table cif_retail exists and if it exists it drops it and then it creates a new table cif_retail with data from cif with the condition cstresf=1.
    How can I do the above in Oracle SQL? I tried the following but it comlains about the drop command, and when i remove it, it complains about the create table command too. Please help:
    create or replace procedure foo as
    begin
    drop table w;
    CREATE TABLE w AS SELECT * FROM x;
    end;
    Thanks,
    Theodora

    You can Also Use
    FORMS_DLL
    Example
    PROCEDURE Create_N_Column_Number_Table (n NUMBER) IS
    my_stmt VARCHAR2(2000);
    BEGIN
    my_stmt := 'create table tmp(COL1 NUMBER';
    FOR I in 2..N LOOP
    my_stmt := my_stmt||',COL'||TO_CHAR(i)||' NUMBER';
    END LOOP;
    my_stmt := my_stmt||')';
    ** Now, create the table...
    Forms_DDL(my_stmt);
    IF NOT Form_Success THEN
    Message ('Table Creation Failed');
    ELSE
    Message ('Table Created');
    END IF;
    END;

  • Use variables in a SELECT INTO FROM command

    Hi,
    How do I use variables within a select into from command? I want to loop through SYS.DBA_TABLES using a cursor and count the number of rows in a
    selection of tables an then insert into a cardinality table.
    The count of rows will be stored in a variable called CNT, that bit is easy however I need a variable in the FROM clause because that
    value changes with every iteration of the cursor.
    e.g.
    CNT := 0;
    TN := "MyTable";
    select count(*) into CNT FROM TN;
    insert into cardinality (table_name, row_count) values (TN, CNT);
    This is Oracle 9i and I need the row counts in a separate table as they are shipped over to a different environment for analysis purposes.
    Any ideas?
    Regards
    Dave
    Edited by: Yorky001 on Sep 15, 2010 10:32 AM

    Hi,
    Thanks for the info, unfortunately I can get neither example to work on this 9i system, could well be pilot error as I only ever get
    to do any Oracle about once per year. In the first query I have tried both "user_tables" and SYS.DBA_TABLES, same result.
    set serveroutput on size 1000000;
    DECLARE
    row_count INTEGER;
    vstr VARCHAR2(500);
    vstr1 VARCHAR2(500);
    BEGIN
    vstr := 'SELECT count(*) FROM ';
    dbms_output.put_line(vstr);
    FOR i IN (SELECT table_name FROM user_tables WHERE rownum < 10) LOOP
    vstr1 := vstr || i.table_name;
    EXECUTE IMMEDIATE vstr1
    INTO row_count;
    dbms_output.put_line(i.table_name || ':' || row_count);
    END LOOP;
    END;
    This one complains about the execute immediate line.
    Error report:
    ORA-00933: SQL command not properly ended
    ORA-06512: at line 12
    00933. 00000 - "SQL command not properly ended"
    *Cause:   
    *Action:
    BEGIN
    FOR i IN (select
    table_name,
    to_number(
    extractvalue(
    xmltype(
    dbms_xmlgen.getxml('select count(*) c from '||table_name))
    ,'/ROWSET/ROW/C')) count
    from user_tables
    where rownum<6) LOOP
    dbms_output.put_line(i.table_name || ':' || i.count);
    END LOOP;
    END;
    ORA-19206: Invalid value for query or REF CURSOR parameter
    ORA-06512: at "SYS.DBMS_XMLGEN", line 121
    ORA-06512: at line 1
    ORA-06512: at line 2
    19206. 00000 - "Invalid value for query or REF CURSOR parameter"
    *Cause:    The queryString argument passed to DBMS_XMLGEN.newContext was not a valid query, or REF CURSOR.
    *Action:   Rewrite the query so that the queryString argument is a valid query or REF CURSOR.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • 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 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 :)

  • SELECT INTO ( variable ) STATEMENTS NOT WORKING FOR SYBASE TABLE AS VIEW

    Dear Experts,
    We have connected our 9i db with Sybase db using Hs connectivity.
    and then we have create the view in oracle db for SYBASE_TABLE as SYBASE_TABLE_VIEW.
    ALL THE INSERT, UPDATE AND DELETE COMMANDS ARE WORKING BUT THE
    select Into (variable) is not working.
    Please help to resolve the select into statment which is in BOLD in the below routine
    PLEASE NOTE! FORM WAS COMPILED SUCCESSFULLY AND FORM IS RUNNING BUT SELECT INTO COMMAND IS NOT WORKING.
    Thanks & Regards
    Eidy
    PROCEDURE SRBL_INSERT IS
    CURSOR SRBL IS
         SELECT impno,impcod,impnam
         from oracle_table1 a, oracle_table2 b
         WHERE a.impcod=b.empcod
         v_srpcod varchar2(5);
    BEGIN     
    FOR rec in SRBL loop     
         begin
    select "im_code" into v_impcod                    
         from SYBASE_TABLE_VIEW
         where "im_code"=rec.impcod;
    exception when no_data_found then
         v_srpcod:=null;
    end;
    END LOOP;
    END;
    Edited by: Eidy on Aug 16, 2010 11:28 AM

    hellow
    try this.
    select "im_code" into v_impcod
    from SYBASE_TABLE_VIEW
    where "im_code"=rec.impcod;
    v_srpcod := v_impcod ;
    ........

  • SELECT-INTO prepared statement?

    Hi,
    I have a single-row select to execute. I don't know if the multi-row select functionality (ResultSets, etc.) should be used for a single-select.
    Here's from the Oracle JDBC Documentation on a prepared statement with input variables:
    PreparedStatement pstmt =
    conn.prepareStatement ("insert into EMP (EMPNO, ENAME) values (?, ?)");
    pstmt.setInt (1, 1500); // The first ? is for EMPNO
    pstmt.setString (2, "LESLIE"); // The second ? is for ENAME
    pstmt.execute ();
    What I would like to do is have a PreparedStatement for output variables in a SELECT-INTO:
    pstmt= conn.prepareStatement("select max(sal) into ? from emp;");
    but there appears to be no bind variable functionality.
    Callable statements apparently are only for stored procedures.
    Basically, should I just use the multirow select for this?
    Thanks,
    Glen

    pstmt= conn.prepareStatement("select max(sal) into ?
    from emp;");
    but there appears to be no bind variable
    functionality.You might be able to bind this as an output parameter, but it seems like extra work (just getting a ResultSet for "select max(sal) from emp" would be a lot more straight forward).
    >
    Callable statements apparently are only for stored
    procedures.Not really, I execute PL/SQL blocks using prepared statements all the time. Sometimes it's the only way to get the data into a format that JDBC can handle.
    Here's an example:
        /** This is the SQL used to call the API ... */
        public static final String spSQL =  
        "declare " +
            "t_warranty_tbl apps.cib_devo_wrapper.wartbltyp; " +
            "x_warranty_tbl apps.cib_devo_wartbltyp; " +
            "x_return_text VARCHAR2(2000); " +
        "begin " +
            "apps.cib_devo_wrapper.cib_get_warranty_info(" +
                "P_SERIAL_NUMBER => ?,"
                "X_WARRANTY_TBL => t_warranty_tbl," +
                "X_RETURN_TEXT => x_return_text," +
                "x_row_count => ?); " +
            // Convert to a table of objects ...
            "x_warranty_tbl := apps.cib_devo_wrapper.cib_warranty_casttowartbltyp(t_warranty_tbl); " +
            // Get the cursor with order by ...
            "OPEN ? FOR SELECT * FROM TABLE(CAST(x_warranty_tbl AS apps.CIB_DEVO_WarTblTyp)) tbl " +
                "WHERE tbl.entitlementReturnCode != apps.cib_devo_wrapper.g_ent_ret_code_08 " +
                "ORDER BY tbl.INSTALLEDAT_CUSTOMER_NAME, tbl.SITE_NAME, tbl.SITE_ID, " +
                          "tbl.PRODUCT_FAMILY, tbl.PRODUCT_NAME, tbl.SERIAL_NUMBER; " +
           "?:=x_return_text; " +
        "end;";In this example, I declare a few variables, call a stored procedure,
    do some more PL/SQL to reduce the results before I finally bring them back.
    The first placeholder (question mark) is the input serial number, the second one is an output parameter that gives the row count. The third
    question mark is the cursor that contains the data I need, and the fourth is a reference to a status message.
    As you can see, the PL/SQL isn't exclusively stored procedure calls.
    >
    Basically, should I just use the multirow select for
    this?I think you'd need code that looks something like:
    DECLARE
    myCount NUMBER;
    BEGIN
    select max(sal) into myCount
    from emp;
    ? := myCount
    END;Although wrapping the select in a BEGIN..END block may be enough.

  • Cannot SELECT into a user-defined type variable

    Hi All,
    Oracle 11.2 on Linux.
    See the steps below. I am not able to insert/select into a TYPE variable. I do not want to do a TABLE declaration in my PL/SQL block, but want to use a user defined type. Is it possible ?
    SQL> create or replace type sample_obj_rec as object
      2  (
      3     object_id    number,
      4     object_name  varchar2(32),
      5     object_type  varchar2(32)
      6  );
      7  /
    Type created.
    SQL> create or replace type sample_obj_tab as table of sample_obj_rec ;
      2  /
    Type created.
    -- ------------   CASE 1 ---------------------
    SQL> declare
      2      v_tab   sample_obj_tab := sample_obj_tab() ;
      3  begin
      4      select object_id, object_name, object_type
      5      bulk   collect into v_tab
      6      from   dba_objects
      7      where  rownum < 11 ;
      8  end ;
      9  /
        from   dba_objects
    ERROR at line 6:
    ORA-06550: line 6, column 5:
    PL/SQL: ORA-00947: not enough values
    ORA-06550: line 4, column 5:
    PL/SQL: SQL Statement ignored
    -- ------------   CASE 2 ---------------------
    SQL> declare
      2      v_rec   sample_obj_rec;
      3  begin
      4      select object_id, object_name, object_type
      5      into   v_rec
      6      from   dba_objects
      7      where  rownum = 1;
      8  end ;
      9  /
        from   dba_objects
    ERROR at line 6:
    ORA-06550: line 6, column 5:
    PL/SQL: ORA-00947: not enough values
    ORA-06550: line 4, column 5:
    PL/SQL: SQL Statement ignoredWhat is the issue with both the above cases? what am I missing here?
    Thanks in advance.

    One small detail in the SELECT.
    SQL> create or replace type sample_obj_rec as object
      2  (object_id    number,
      3   object_name  varchar2(32),
      4   object_type  varchar2(32));
      5  /
    Type created.
    SQL>
    SQL> create or replace type sample_obj_tab as table of sample_obj_rec ;
      2  /
    Type created.
    SQL>
    SQL> declare
      2     v_tab   sample_obj_tab := sample_obj_tab() ;
      3  begin
      4     select sample_obj_rec(object_id, object_name, object_type)
      5     bulk   collect into v_tab
      6     from   dba_objects
      7     where  rownum < 11 ;
      8  end ;
      9  /
    PL/SQL procedure successfully completed.
    SQL>

  • Selecting only time in oracle forms

    Hi all,
    like date picker in oracle forms can i select the time in oracle forms into a text item.
    i want to display the time in this format 10:10:30 a.m. and also i want to insert into the table
    i have taken the data type of this column as varchar2(15) if i take date can i insert the time or varchar2 is ok.
    my oracle forms version is 10g.
    please reply...

    Hi, extreme
    extreme wrote:
    Hi all,
    like date picker in oracle forms can i select the time in oracle forms into a text item.
    i want to display the time in this format 10:10:30 a.m. and also i want to insert into the table
    i have taken the data type of this column as varchar2(15) if i take date can i insert the time or varchar2 is ok.Better take column having data type date. You can insert date and time in the date field.
    Just you need to change in forms.
    Change the Data type Date to Datetime
    to show only time, use format mask.
    Hope this helps

  • Split Output from Select into 2 different Cols

    Hi,
    I am new to oracle dev. Env Oracle 10g R2
    I need a help with the following.
    I have a select query that returns comma separated values.
    Column LIST1 in table svp_1.
    This needs to hold that data returned by the select query.
    Datatype of Column LIST1 varchar2(4000)
    I get the follwing error.
    ORA-19011: Character string buffer too small
    CREATE OR REPLACE PROCEDURE
    sale_temp( pType in Char,lDate in date) as
    cnt number;
    v_error_code NUMBER;
    v_error_msg VARCHAR2(2000);
    cursor c1 is select svp
    from sale
    where type = pType
    var1 c1%ROWTYPE;
    BEGIN
    UPDATE svp_1
    SET LIST1 = ( SELECT LTRIM( xmlagg (xmlelement (c, RTRIM(RELATED_SVP) || ',')).extract ('//text()'), ',' ) AS RELATED_SVP from (
    SELECT rtrim(BASE_SVP) BASE_SVP,
    rtrim(RELATED_SVP) RELATED_SVP
    from
    svp_enc se
    where
    se.effective date<= pDate
    and (se.expiration_date is null or se.expiration_date > plDate )
    and se.base_svp in
    ( var1.svp
    and se.RELATION_TYPE = '4'
    )group by base_svp)
    WHERE type = pType
    commit;
    dbms_output.put_line('UPDATE done' );
    end;
    end loop;
    close c1;
    END ;
    My requirement :
    In need to capture the data from the select query and update the column.
    The data needs to be returned as comma separated values.
    This data can also be split into 2 columns.....ie data split and updated into 2 cols ie LIST1 AND LIST2 ( can be added to existing table).
    What is the best way to do this?
    Is the below approach possilble?
    LOOP through cursor ...check the length of data....for the select query ....check length .if > 3990 byte.....then write into 2 plsql variables.....and update 2 cols....
    Is this apporach right, if so how to do that in the procedure ? Please give an example...
    Are there any other approaches...?
    All I need is to Split Output from Select into 2 different columns and avoid the ORA-19011: Character string buffer too small error.
    Thanks in advance.

    Re: ORA-19011: Character string buffer too small

  • Select into ?

    I am trying to write an sql query, but I want to use a variable in the query. So I wrote the following procedure, just as a test:
    declare l_block_size number(10);
    begin
    select value
    into l_block_size
    from v$parameter
    where name = 'db_block_size';
    select owner, table_name, blocks
    from dba_tables
    where tablespace_name = '&tablespace'
    order by 3;
    end;
    Remember, this is just a test query, and logically doesn't make sense now (a query in progress).
    There are 2 queries. The 1st one selects the block_size of my database into a variable. The 2nd one I just wanted to output to the screen, but I get the error:
    PLS-00428: an INTO clause is expected in this SELECT statement
    Can I do a select here without an INTO clause ? I don't want to create a procedure - just wanted to write a query I can run in SQLPLUS - using a variable.

    PRE
    myquery.sql
    set serveroutput on;
    DECLARE
    l_block_size number(10);
    -- TYPE x
    -- IS RECORD (
    -- owner varchar2(30),
    -- table_name varchar2(30),
    -- blocks number
    begin
    select value
    into l_block_size
    from v$parameter
    where name = 'db_block_size';
    for x in (select owner, table_name, blocks*l_block_size size
    from dba_tables
    where tablespace_name = '&tablespace'
    order by 3)
    loop
    dbms_output.put_line('Owner: ' || x.owner);
    dbms_output.put_line('Table: ' || x.table_name);
    dbms_output.put_line('Size: ' || x.size);
    dbms_output.put_line('/');
    end loop;
    end;
    @myquery
    Enter value for tablespace: ADMIN_LARGE
    old 19: where tablespace_name = '&tablespace'
    new 19: where tablespace_name = 'ADMIN_LARGE'
    for x in (select owner, table_name, blocks*l_block_size size
    ERROR at line 17:
    ORA-06550: line 17, column 56:
    PL/SQL: ORA-00923: FROM keyword not found where expected
    ORA-06550: line 17, column 10:
    PL/SQL: SQL Statement ignored
    ORA-06550: line 24, column 38:
    PLS-00103: Encountered the symbol "SIZE" when expecting one of the following:
    <an identifier> <a double-quoted delimited-identifier> delete
    exists prior
    The symbol "<an identifier> was inserted before "SIZE" to continue.
    /PRE

  • Why do I have to use SELECT INTO clause in a Stored Proc ?

    Hi,
    I'm new to oracle. I've bought Oracle Database 10g SQL and Oracle Database 10 A beginner's Guide, two books from Oracle press but I can't find any answer for that.
    Why when I'm writing a Stored Procedure with a SELECT statement do I have to use an INTO clause ?? And why when the select returns more than one row do I have to use a cursor ? By the way is this the only way to return more than one row from a stored procedure ?
    Any help will be appreciated.
    Regards.
    S. Nunes

    Sounds like you may have some experience with other databases (SQL Server, maybe?) which allow you to create stored procedures which implicitly return result sets simply by embedding select statements.
    In Oracle, the correct way to do this is using ref cursors.
    See the following link for a good explanation:
    http://osi.oracle.com/~tkyte/ResultSets/index.html

  • SQL: select into

    Hello. In both sybase and sql server, you
    can create on-the-fly tables in sql by
    simply doing a
    select column
    into newtable
    from oldtable
    where blahblahblah
    When I do the same in sql (not pl/sql)
    I get the following error:
    SQL> select empno
    2 into myemp
    3 from emp
    4 where ename = 'SMITH';
    into myemp
    ERROR at line 2:
    ORA-00905: missing keyword
    Is it possible to do this kind of select into
    in Oracle?
    Thanks!

    I believe the syntax you're looking for is:
    create table <tablename>
    as select *
    from (<original statement>)
    More examples are available in the Migration Workbench docs

  • Export into xls from oracle web toolkit.

    select * from emp;
    i want export the above query into xls from oracle web toolkit.
    can anybody help me please

    hi
    instead of exporting to excel why not import into excel using InProcServer
    here is a code snippet that i am using to generate reports for my bank
    Dim OraSession As OraSession
    Dim OraDatabase As OraDatabase
    Dim OraDynaset As OraDynaset
    Dim sql1, sql2, sql3
    Dim SQLSTMT
    Dim myarray()
    SQLSTMT="select * from emp"
    Set OraSession = CreateObject("OracleInProcServer.XOraSession")
    'Create the OraDatabase Object by opening a connection to Oracle.
    Set OraDatabase = OraSession.OpenDatabase("report", "report/report", 0&)   ' (hoststring,user/password,0&)
    Set OraDynaset = OraDatabase.CreateDynaset(SQLSTMT, 0&)
    If OraDynaset.RecordCount > 0 Then
    ReDim myarray(0 To OraDynaset.RecordCount - 1)
    Else
    MsgBox "Zero Records Found", vbOKCancel, "Error"
    Unload Me
    End If
    Debug.Print UBound(myarray, 1)
    '***********************populating myarray********
    If OraDynaset.RecordCount > 0 Then
            OraDynaset.MoveFirst
            'For x = 0 To OraDynaset.Fields.Count - 1
             '   Cells(1, x + 1) = OraDynaset.Fields(x).Name
                'Cells(1, x + 1).Format = Bold
            'Next
    For n = rng1.Columns.Count To (UBound(heading, 1) + 1) Step -1
    rng1.Cells(1, n).Select
    ActiveCell.EntireColumn.Delete
    Next
            For m = 1 To rng1.Columns.Count
                rng1.Cells(1, m).Select
                rng1.Cells(1, m).ClearContents
            Next
                For a = LBound(heading, 1) To UBound(heading, 1)
                Cells(1, a).Select
                Cells(1, a) = heading(a)
                                    With Selection
                                        .HorizontalAlignment = xlLeft
                                        .VerticalAlignment = xlCenter
                                        .WrapText = True
                                        .Orientation = 0
                                        .AddIndent = False
                                        .IndentLevel = 0
                                        .ShrinkToFit = False
                                        .ReadingOrder = xlContext
                                        .MergeCells = False
                                    End With
                                    With Selection.Borders(xlEdgeRight)
                                        .LineStyle = xlContinuous
                                        .ThemeColor = 1
                                        .TintAndShade = 0
                                        .Weight = xlThick
                                    End With
                                    With Selection.Font
                                        .Name = "Arial Rounded MT Bold"
                                        .FontStyle = "Regular"
                                        .Size = 11
                                        .Strikethrough = False
                                        .Superscript = False
                                        .Subscript = False
                                        .OutlineFont = False
                                        .Shadow = False
                                        .Underline = xlUnderlineStyleNone
                                        .ThemeColor = xlThemeColorDark1
                                        .TintAndShade = 0
                                        .ThemeFont = xlThemeFontNone
                                    End With
                                    With Selection.Interior
                                        .Pattern = xlSolid
                                        .PatternColorIndex = xlAutomatic
                                        .ThemeColor = xlThemeColorLight1
                                        .TintAndShade = 0
                                        .PatternTintAndShade = 0
                                    End With
                                Next a
            For y = 0 To OraDynaset.RecordCount - 1
                For x = 0 To OraDynaset.Fields.Count - 1
                    m_split = Split(OraDynaset.Fields(x).Value, "|", -1, vbTextCompare)
                    For m = LBound(m_split, 1) To UBound(m_split, 1)
                        Cells(y + 2, x + m + 1) = m_split(m)
                    Next m
                    'Cells(y + 2, x + 1) = OraDynaset.Fields(x).Value
                Next
                OraDynaset.MoveNext
            Next
        End Ifsee if this serves your purpose
    hemu

Maybe you are looking for

  • IPhone not recognised by iTunes 10.4

    Since downloading iTunes 10.4 my Mac no longer recognises my iPhones.  I just upgraded to Lion OSX 10.7 in the hope that would fix it.  Alas, I still can't see my phones in iTunes, so I can't sync them. I've tried everything including reinstalling iT

  • Selection screen validation when using PNP LDB

    Hi guys, I want to validate my selection screen parameters.Thats is if somebody wants to run the program without giving any input parameters to the selection screen(trying to run the report with a blank screen) I want to pop up an error/information m

  • Axis SOAP Adapter + Certificate

    Hi, We developed an interface where the receiver adapter access a web service (https), which uses user and certificate authentication. Firstly we configured the "Transport Protocol" as "HTTP", but we got the error "Peer certificate rejected by ChainV

  • Valuation Class / GI and Profit Center

    Respected MM Experts, We created a new valuation class, however when I post goods issue to COGS instead of posting to the profit center found at the material level it post to an unallocated profit center that we don't want. We created a sales order p

  • SharePoint Designer: Error when connecting to my customer production server

    Every time I try to connect to any SharePoint site running on my customer server I get the following error. An error occurred accessing your Microsoft SharePoint Foundation site files. Authors - if authoring against a Web server, please contact the W