Using select * in pl/sql

Hi,
Yesterday Karthick mentioned that using SELECT * in PL/SQL is not a good idea. But I tried by creating a table and different procedures with selecting all columns using * and specifying the columns individually. Later I altered the table and both procedures became invalid. Can some one give a simple example to demonstrate the behaviour.
At present I dont have Oracle in my PC to post what I have tried yesterday.
Cheers,
Suri

When I run the following script, the 2nd time the test1 procedure runs, it fails with "PLS-00905: object TEST1 is invalid", whereas test2 runs fine both times.
Feel free to try it yourself!
create table boneist_test (col1 number, col2 varchar2(10));
insert into boneist_test values (1, 'a');
commit;
create procedure test1
is
  v_num number;
  v_var varchar2(10);
begin
  select *
  into v_num, v_var
  from boneist_test
  where rownum = 1;
end test1;
create procedure test2
is
  v_num number;
  v_var varchar2(10);
begin
  select col1, col2
  into v_num, v_var
  from boneist_test
  where rownum = 1;
end test2;
begin
  test1;
end;
begin
  test2;
end;
alter table boneist_test add (col3 number);
begin
  test1;
end;
begin
  test2;
end;
drop table boneist_test;
drop procedure test1;
drop procedure test2;

Similar Messages

  • Error while retrieving data from PL/SQL Table using SELECT st. (Urgent!!!)

    Hi Friends,
    I am using Oracle 8.1.6 Server, & facing problems while retrieving data from a PL/SQL Table:
    CREATE or REPLACE PROCEDURE test_proc IS
    TYPE tP2 is TABLE of varchar2(10); --declared a collection
    dt2 tP2 := tP2('a','b','c');
    i NUMBER(8);
    begin
    SELECT COUNT(*) INTO i FROM TABLE(CAST(dt2 as tP2));
    DBMS_OUTPUT.PUT_LINE('**'||i);
    end;
    While executing the above procedure, I encountered foll. error:
    ERROR at line 1:
    ORA-00600: internal error code, arguments: [15419], [severe error during PL/SQL execution], [], [],
    ORA-06544: PL/SQL: internal error, arguments: [pfrrun.c:pfrbnd1()], [], [], [], [], [], [], []
    ORA-06553: PLS-801: internal error [0]
    Can anyone please help me, where the problem is??
    Is it Possible to retrieve data from PL/SQL TABLE using SELECT statement? & How ?
    Thanks in advance.
    Best Regards,
    Jay Raval.

    Thanks Roger for the Update.
    It means that have to first CREATE TYPE .. TABLE in database then only I can fire a Select statement on that TYPE.
    Actually I wanted to fire a Select statement on the TABLE TYPE, defined & declared in PLSQL stored procedure using DECLARE TYPE .. TABLE & not using CREATE TYPE .. TABLE.
    I was eager to know this, because my organization is reluctant in using CREATE TYPE .. TABLE defined in the database, so I was looking out for another alternative to access PL/SQL TABLE using Select statement without defining it database. It would have been good if I could access a PLSQL TABLE using Select statement Declared locally in the stored procedure.
    Can I summarize that to access a PL/SQL TABLE using SELECT statement, I have to first CREATE TYPE .. TABLE?
    If someone have any other idea on this, please do let me know.
    Thanks a lot for all help.
    Best Regards,
    Jay Raval.
    You have to define a database type...
    create type tP2 is table of varchar2(10)
    CREATE OR REPLACE PROCEDURE TEST_PROC
    IS
    dt2 tP2 := tP2('a','b','c');
    i NUMBER(8);
    begin
    SELECT COUNT(*) INTO i FROM TABLE(CAST (dt2 AS tP2));
    DBMS_OUTPUT.PUT_LINE('**'||i);
    end;
    This will work.
    Roger

  • Using Select option in Native SQL

    Hi,
    Can any one tell me, how to use select option value in native SQL.
    ie.,
    I want to use select option in where condition. Need to select all the records from table(non-SAP) where date in given range.
    Please suggest.
    Thanks,
    Amal

    Hi
    No!
    U need to find a way to convert a range of select-option to a range for Native SQL, probably it should be better doesn't use a select-option for the date but two parameters: one for date from and one for date to.
    Max

  • Using Select statement in IF condition?

    hi all,
    Can i use select statement in IF COndition in pl sql ?
    eg like- if( select 1 from ASD) then
    end if;

    There is no way to do any kind of select statement inside if conditions.
    Why don't test simple cases like this first?
    An example to show it.
    SQL> begin
      2   if exists (select 1 from dual) then
      3    dbms_output.put_line('ok');
      4   end if;
      5  end;
      6  /
    if exists (select 1 from dual) then
    ERRORE alla riga 2:
    ORA-06550: line 2, column 5:
    PLS-00204: function or pseudo-column 'EXISTS' may be used inside a SQL
    statement only
    ORA-06550: line 2, column 2:
    PL/SQL: Statement ignored
    SQL> begin
      2   if ( (select count(*) from dual) > 0 ) then
      3    dbms_output.put_line('ok');
      4   end if;
      5  end;
      6  /
    if ( (select count(*) from dual) > 0 ) then
    ERRORE alla riga 2:
    ORA-06550: line 2, column 8:
    PLS-00103: Encountered the symbol "SELECT" when expecting one of the following:
    ( - + case mod new not null others <an identifier>
    <a double-quoted delimited-identifier> <a bind variable> avg
    count current exists max min prior sql stddev sum variance
    execute forall merge time timestamp interval date
    <a string literal with character set specification>
    <a number> <a single-quoted SQL string> pipe
    <an alternatively-quoted string literal with character set specification>
    <an alternativ
    ORA-06550: line 2, column 33:
    PLS-00103: Encountered the symbol ")" when expecting one of the following:
    . , @ ; for <an identifier>
    <a double-quoted delimited-identifier> group having intersect
    minus order partition start subpartition union where connect
    SQL> begin
      2   if ( 0 in (select count(*) from dual) ) then
      3    dbms_output.put_line('ok');
      4   end if;
      5  end;
      6  /
    if ( 0 in (select count(*) from dual) ) then
    ERRORE alla riga 2:
    ORA-06550: line 2, column 12:
    PLS-00405: subquery not allowed in this context
    ORA-06550: line 2, column 2:
    PL/SQL: Statement ignoredBye Alessandro

  • How to get multiple records using fn-bea:execute-sql()

    Hi,
    I created Proxy service(ALSB3.0) to get records from DB table. I have used Xquery function(fn-bea:execute-sql()). Using simple SQL query I got single record, but my table having multiple records. Please suggest how to get multiple records using fn-bea:execute-sql() and how to assign them in ALSB variable.
    Regards,
    Nagaraju
    Edited by: user10373980 on Sep 29, 2008 6:11 AM

    Hi,
    Am facing the same issue stated above that I couldnt get all the records in the table that am querying in the Proxyservice.
    For example:
    fn-bea:execute-sql('EsbDataSource', 'student', 'select Name from StudentList' ) is the query that am using to fetch the records from the table called StudentList which contains more than one records like
    Id Name
    01 XXX
    02 YYY
    03 ZZZ
    I tried to assign the result of the above query in a variable and while trying to log the variable, I can see the below
    <student>
    <Name>XXX</Name>
    </student>
    I want to have all the records from my table in xml format but it's not coming up. I get the value only from the first row of my table.
    Please suggest.
    regards,
    Venkat

  • Using a custom PL/SQL to populate the primary key in a tabular form

    I want to use a Custom PL/SQL Function to populate the primary key when I insert a new record into a tabular form. I want to get the value from a hidden page Item. The code I am using for the primary key source is:
    BEGIN
    INSERT INTO TEAM_MEMBERS(TEAM_ID)
    VALUES(:P75_TEAM_ID);
    END;
    When I try to insert a new record I get the following error:
    Error      ERR-1904 Unable to compute item default: type = Function Body computation_type= BEGIN INSERT INTO TEAM_MEMBERS(TEAM_ID) VALUES(:P75_TEAM_ID); END; .
    ORA-06550: line 5, column 2: PLS-00103: Encountered the symbol ";" when expecting one of the following: begin case declare end exception exit for goto if loop mod null pragma raise return select update while with << close current delete fetch lock insert open rollback savepoint set sql execute commit forall merge pipe The symbol "exit" was substit
    Any ideas what I am doing wrong?
    Thanks!

    Brian - Sometimes whitespace at the end of the block causes this. Be sure to trim everything after the last semicolon including tabs and newlines.
    Scott

  • How to use the EBS PL/SQL API from outside PL/SQL

    Hi,
    our attempts to call the stored procedures/functions of the EBS PL/SQL API via JDBC revealed the following issues:
    1. Logical values cannot be exchanged through boolean parameters as the OCI has no notion of this type. Instead we need to write PL/SQL wrappers converting boolean to integer and vice versa. Is that true or are we missing something?
    2. Complex values cannot be exchanged through record types as only PL/SQL code has a notion of this type. Instead we need to write PL/SQL wrappers converting record values to object type values. Is that true or are we missing something?
    3. Types must be defined outside of packages, i.e. in the schema, for whatever reason. Instead we need to write PL/SQL wrappers converting values of types defined in packages to values of types defined in the schema. Is that true or are we missing something?
    4. It is possible to let functions return tables so the results can be queried using SELECT * FROM TABLE. Such functions are called "table functions". Is there something similar for the other direction, i.e. is it possible to call a stored procedure and pass in a table value through an sql INSERT statement?
    5. Do we really have to write all those wrapper routines on our own or is there a PL/SQL library providing such? If not, is there some kind of code generation facility that can generate such wrappers?
    Thanks and Regards,
    Konrad

    Hi Helios,
    I belive its better to move your issue on Forum Home » Database » SQL and PL/SQL which you can get more quick responseYou are probably right! I was thinking about a different forum but I did not see this one. I just posted the question there...
    Still, if somebody has an idea here as well, just let me know ;-)
    Konrad

  • Exception while using select

    I trying to select 31 column in my table using select query but an exception is thrown
    java.sql.SQLException: ORA-00904: "US"."BRANCH_ID": invalid identifier
    i am able to select the 30 column but not the 31st or 32nd colum.
    help needed, i have tried using Statment and prepared Statement both but its not working.

    This is an Oracle Error, not JDBC. I have a feeling that your SQL statement is invalid. Check this first.

  • Using xslt in pl/sql

    Hi!
    I have a simple question: how can I use xslt in pl/sql?
    I've tried this:
    DECLARE
      v_XML  XMLTYPE;
      v_XSLT XMLTYPE;
    BEGIN
      SELECT XMLCol --it's a valid XML.
        INTO v_XML
        FROM tb_Controle;
      SELECT XSLTCol --I don't know how to use XSLT.
        INTO v_XSLT
        FROM tb_XSLT;
      DBMS_OUTPUT.PUT_LINE(XMLTYPE.TRANSFORM(v_XML,v_XSLT).GETSTRINGVAL());
    END;But it returns the error:
    ERROR at line 1:
    ORA-31011: XML parsing failed
    ORA-19202: Error occurred in XML processing
    ORA-06512: at "SYS.XMLTYPE", line 174
    ORA-06512: at line 13When a xlst has import and include tags, how the files are found? Is there something like the xsd schema registration?
      <xsl:import href="cte.xslt" />
      <xsl:include href="../functions.xslt"/> Another question: after applying the style sheet, the result is a text? 'cause I need to send the result as a text.
    Thanks!

    how can I use xslt in pl/sql?
    declare
      v_xml  xmltype;
      v_xslt xmltype;
      v_xml_result xmltype;
    begin
      select xmlcol --it's a valid XML.
        into v_xml
        from tb_controle;
      select xsltcol --I don't know how to use XSLT.
        into v_xslt
        from tb_xslt;
      select xmltype.transform(v_xml,v_xslt) into  v_xml_result from dual;
      dbms_output.put_line(v_xml_result.getstringval());
    end;

  • Using PPR in PL/SQL generated webpages

    I have a question about using PPR with web pages written in PL/SQL.
    I have a dropdown menu that I want to limit by the value selected in the preceding dropdown (pick-list).
    So far I have not found much information on PPR other than on OTN, and was unable to find any PL/SQL coding samples; so I guess I should ask...
        - Is it possible to use PPR in a webpage generated from a stored PL/SQL procedure/package?
        - If so, how do I make use of PPR in PL/SQL?
        - If it is NOT possible to use PPR with PL/SQL, what other methods could I make use of other than JavaScript?
    Thank you in advance,
    Charlie

    When I run the following script, the 2nd time the test1 procedure runs, it fails with "PLS-00905: object TEST1 is invalid", whereas test2 runs fine both times.
    Feel free to try it yourself!
    create table boneist_test (col1 number, col2 varchar2(10));
    insert into boneist_test values (1, 'a');
    commit;
    create procedure test1
    is
      v_num number;
      v_var varchar2(10);
    begin
      select *
      into v_num, v_var
      from boneist_test
      where rownum = 1;
    end test1;
    create procedure test2
    is
      v_num number;
      v_var varchar2(10);
    begin
      select col1, col2
      into v_num, v_var
      from boneist_test
      where rownum = 1;
    end test2;
    begin
      test1;
    end;
    begin
      test2;
    end;
    alter table boneist_test add (col3 number);
    begin
      test1;
    end;
    begin
      test2;
    end;
    drop table boneist_test;
    drop procedure test1;
    drop procedure test2;

  • Using Bind variables in SQL PLUS Report

    using Bind variables in SQL PLUS Report. This report gets the arguments from the application concurrent program. Now my need is to convert the start_date and end_date to bind Variables to improve the performance. I have commented the original code in 'prompt List of Unapproved Adjustments' and used my Bind Variable but it is giving an error
    error: Bind Variable "ENDING_DATE" not declared
    Report Date and Time:
    26-OCT-2010 15:44:13
    List of Unapproved Adjustments
    Bind Variable 'ENDING_DATE" not declared
    Please see below the code for the sql plus report:
    define p_org_id           = '&1'
    define p_fy_begin_date = '&2'
    define p_start_date = '&3'
    define p_end_date = '&4'
    define p_conversion = '&5'
    declare
    variable begin_date date;
    exec :begin_date := p_start_date;
    variable ending_date date;
    exec :ending_date := p_end_date;
    /* Begin
    :begin_date := to_date('&p_start_date','YYYY/MM/DD HH24:MI:SS');
    :ending_date := to_date('&p_end_date','YYYY/MM/DD HH24:MI:SS');
    End; */
    set newpage none
    set termout off
    set pagesize 55
    set linesize 180
    set heading on
    set feedback off
    set wrap off
    set space 1
    set heading on
    begin
    dbms_application_info.set_client_info('&p_org_id');
    end;
    prompt
    prompt Report Date and Time:
    prompt ----------------------
    select to_char(sysdate,'DD-MON-YYYY HH24:MI:SS')
    from dual ;
    prompt
    prompt List of Unapproved Adjustments
    prompt -------------------------------
    select b.trx_number,
    a.adjustment_number,
    f.user_name created_by
    from apps.ar_adjustments a,
    apps.ra_customer_trx b,
    apps.fnd_user f
    where a.customer_trx_id = b.customer_trx_id
    and a.status <> 'A'
    and a.created_by = f.user_id
    and a.creation_date between :begin_date
    and :ending_date
    -- and a.creation_Date between to_date('&p_start_date','YYYY/MM/DD HH24:MI:SS')
    -- and to_date('&p_end_date','YYYY/MM/DD HH24:MI:SS')
    order by
    b.trx_number ;

    Hi
    Please go to customization part of the report and verify..You have set a default value out there ..And also verify your lov and look at the values ..If it is again giving you the problem ..pl delete the report and develop it again from the scratch it will be solved...
    vishnu
    null

  • Number of rows inserted is different in bulk insert using select statement

    I am facing a problem in bulk insert using SELECT statement.
    My sql statement is like below.
    strQuery :='INSERT INTO TAB3
    (SELECT t1.c1,t2.c2
    FROM TAB1 t1, TAB2 t2
    WHERE t1.c1 = t2.c1
    AND t1.c3 between 10 and 15 AND)' ....... some other conditions.
    EXECUTE IMMEDIATE strQuery ;
    These SQL statements are inside a procedure. And this procedure is called from C#.
    The number of rows returned by the "SELECT" query is 70.
    On the very first time call of this procedure, the number rows inserted using strQuery is *70*.
    But in the next time call (in the same transaction) of the procedure, the number rows inserted is only *50*.
    And further if we are repeating calling this procedure, it will insert sometimes 70 or 50 etc. It is showing some inconsistency.
    On my initial analysis it is found that, the default optimizer is "ALL_ROWS". When i changed the optimizer mode to "rule", this issue is not coming.
    Anybody faced these kind of issues?
    Can anyone tell what would be the reason of this issue..? any other work around for this...?
    I am using Oracle 10g R2 version.
    Edited by: user13339527 on Jun 29, 2010 3:55 AM
    Edited by: user13339527 on Jun 29, 2010 3:56 AM

    You have very likely concurrent transactions on the database:
    >
    By default, Oracle Database permits concurrently running transactions to modify, add, or delete rows in the same table, and in the same data block. Changes made by one transaction are not seen by another concurrent transaction until the transaction that made the changes commits.
    >
    If you want to make sure that the same query always retrieves the same rows in a given transaction you need to use transaction isolation level serializable instead of read committed which is the default in Oracle.
    Please read http://download.oracle.com/docs/cd/E11882_01/appdev.112/e10471/adfns_sqlproc.htm#ADFNS00204.
    You can try to run your test with:
    set  transaction isolation level  serializable;If the problem is not solved, you need to search possible Oracle bugs on My Oracle Support with keywords
    like:
    wrong results 10.2Edited by: P. Forstmann on 29 juin 2010 13:46

  • 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.

  • DIfferent # of rows return using select * & select count(*)

    In debugging some code (OWB generated PL/SQL) I came across the situation where by a query with count(*) returns a value of 600 rows. The same where clause using select * reports only 300 rows selected. There are 600 rows to select.
    Any ideas why the difference ???
    The code:
    SELECT *
    FROM "STG_SYSTEM_CUSTOMER_V" "STG_SYSTEM_CUSTOMER_V",
    DW_REPRESENTATIVE INGRP8
    where "STG_SYSTEM_CUSTOMER_V"."PILLAR_STATE_CD" IN 'VIC'
    AND "STG_SYSTEM_CUSTOMER_V"."BUS_PILLAR_CD" = 'IGA'
    AND ( "STG_SYSTEM_CUSTOMER_V"."MN_COMP_CD" = "INGRP8"."MN_COMP_CD" (+) )
    AND ( "STG_SYSTEM_CUSTOMER_V"."COUNTRY_CD" = "INGRP8"."COUNTRY_CD" (+) )
    AND ( "STG_SYSTEM_CUSTOMER_V"."COMP_CD" = "INGRP8"."COMP_CD" (+) )
    AND ( "STG_SYSTEM_CUSTOMER_V"."BUS_PILLAR_CD" = "INGRP8"."BUS_PILLAR_CD" (+) )
    AND ( "STG_SYSTEM_CUSTOMER_V"."PILLAR_STATE_CD" = "INGRP8"."PILLAR_STATE_CD" (+) )
    AND ( "STG_SYSTEM_CUSTOMER_V"."SUPP_DIVISION_CD" = "INGRP8"."DIVISION_CD" (+) )
    AND ( "STG_SYSTEM_CUSTOMER_V"."ALM_REP_NUM" = "INGRP8"."REP_NUM" (+) )
    Cheers
    Pav

    You're sure that the only difference between the two statelents is that "*" is replaced with "count(*)"? Assuming there are no transactions going on simultaneously, that would be a bug. Have you installed the latest patchset to your database?
    Justin
    Distributed Database Consulting, Inc.
    www.ddbcinc.com

  • How to use bind variables using in  clause in SQL

    Hi
    Can any one help me in regards Bind variables usage using in clause in sql for String data?
    thans

    Are you looking for a dynamic IN list? As in something like this:
    SELECT ... FROM .. WHERE some_col IN (<dynamic list of stuff that is always changing>)If so check this out:
    [ How can I do a variable IN list?|http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:210612357425]

Maybe you are looking for

  • Inbound IDOC FINSTA01 status Change

    Hi, Actually we are posting in bound idco for lockbox using Idoc Finsta01,Depending on the header and item amount ,ie if both are not equal  need to post the idoc with 64  status with custome message. Any User Exit ? Thanks, Madhu

  • Can anyone answer this????

    I have a java application that interacts with a Microsoft Access database that houses movie information. Such things include (Title,description,rating..etc). I am using this application to catalog my movies. Instead of using the information off the b

  • Quicktime Pro shuts down immediately after I push "play" button.

    I just purchased Quicktime Pro for Windows, and whenever I open a video and hit the "play" button, the program crashes. I have tried more than one video and all result in the same thing. These are .avi movies from my video camera. I uninstalled QT Pr

  • EWS 2.0 (Exchange 2007 ) - How to Bulk Update Contacts

    Hi  I have  afew hundred contacts that I need to auto-refresh in Exchange 2007 via EWS 2.0. Speed is not that great. Can someone please provide an example of how I could bulk update 25 contacts and clearly identify which ones failed because they did

  • ACR 4.1 Installation stalls

    MacBook Pro OS 10.4.9 Photoshop CS3 update downloads the new ACR 4.1 I initiate the install process but it always get hung-up about 3/4 the way through the install. I've let the installer run for 30+ minutes. Any suggestions of how to get the install