My first PL/SQL block not working with using Select query within begin

I am new to PL/SQL , just started with basics of BLOCKS .
I am having a query here in executing a block .
When i am doing a insert oprtation in Blocks Begin method everything is working fine , but when ever i tried to do select operation , some error is being thrown .
First of all This is my Table :
select from try :*
KEY      VALUE
Key     Value
Key1     Value1
Key2     Value2
Key3     Value3
======================
This is the code which is not working : Please see the code and tell me what is the problem .
DECLARE
v_KEY    VARCHAR2(20);
v_VALUE   VARCHAR2(20);
BEGIN
select key into v_KEY FROM try where v_value='Value' ;
dbms_output.put_line(v_KEY);
END;
When i run this code , it is saying Data Not Found on this line " select key into v_KEY FROM try where v_value='Value' ;"
wheer when i run tis individually it worked fine :
select KEY FROM try where VALUE='Value' ;"
please share your ideas .as why it isn't running ??
Edited by: user10503747 on Sep 20, 2010 3:16 AM

Hi,
user10503747 wrote:
I am new to PL/SQL , just started with basics of BLOCKS .
I am having a query here in executing a block .
When i am doing a insert oprtation in Blocks Begin method everything is working fine , but when ever i tried to do select operation , some error is being thrown .
First of all This is my Table :
select from try :*
KEY      VALUE
Key     Value
Key1     Value1
Key2     Value2
Key3     Value3
======================
This is the code which is not working : Please see the code and tell me what is the problem .
DECLARE
v_KEY    VARCHAR2(20);
v_VALUE   VARCHAR2(20);
BEGIN
select key into v_KEY FROM try where v_value='Value' ;
dbms_output.put_line(v_KEY);
END;
When i run this code , it is saying Data Not Found on this line " select key into v_KEY FROM try where v_value='Value' ;"
wheer when i run tis individually it worked fine :
select KEY FROM try where VALUE='Value' ;"
please share your ideas .as why it isn't running ??
Edited by: user10503747 on Sep 20, 2010 3:16 AMInstead of:
{code}
select key into v_KEY FROM try where v_value='Value' ;
{code}
perhaps you meant something like:
{code}
v_value := 'Value1';
select key into v_KEY FROM try where v_value=Value ; -- No quotes
{code}
Until you assign a vlue to a variable, like v_value, it is NULL, so your original statement was equivalent to
{code}
select KEY FROM try where NULL='Value' ;
{code}
In PL/SQL, a SELECT ... INTO statement must return exactly one row, or else you will get an error (either NO_DATA_FOUND or TOO_MANY_ROWS). This is different from SQL, where a query cn return any number of rows, including 0, without raising an error.

Similar Messages

  • Smart scan not working with Insert Select statements

    We have observed that smart scan is not working with insert select statements but works when select statements are execute alone.
    Can you please help us to explain this behavior?

    There is a specific exadata forum - you would do better to post the question there: Exadata
    I can't give you a definitive answer, but it's possible that this is simply a known limitation similar to the way that "Create table as select" won't run the select statement the same way as the basic select if it involves a distributed query.
    Regards
    Jonathan Lewis

  • My First while loop inside PL/SQL block not working , please help

    Hi ,
    I am new to PL/sql and struck at PL SQL blocks , please help to solve this .
    declare
    v_A number constant :=10 ;
    j number constant := 3 ;
    BEGIN
    WHILE j < v_A
    LOOP
    DBMS_OUTPUT.PUT_LINE('Hai');
    END LOOP;
    END;
    please help as how to resolve this .
    Thanks in advance .

    btw it's a useful habit to use indentation to highlight the block structure. Also it's worth deciding what your convention will be for keywords (I use uppercase, lowercase is also fine as far as I'm concerned but I've set up my editor to uppercase them) and variables, database object names etc (I use lowercase), e.g:
    DECLARE
       v_a CONSTANT PLS_INTEGER := 10;
       j   CONSTANT PLS_INTEGER := 3;
       i PLS_INTEGER := j;
    BEGIN
       WHILE i <= v_a LOOP
          DBMS_OUTPUT.PUT_LINE(i);
          i := i +1;
       END LOOP;
    END;or perhapsdeclare
       v_a constant pls_integer := 10;
       j   constant pls_integer := 3;
       i pls_integer := j;
    begin
       while i <= v_a loop
          dbms_output.put_line(i);
          i := i +1;
       end loop;
    end;When I see "declare" and "BEGIN" in the same block of code I worry about the standard of code I'm going to see...

  • My first generation Ipad does not work with Keynote.

    The program appears to run normally, but it won't project.  My colleague's identical ipad works with our projector, and my cable works on his ipad.  What is wrong?

    Here are some things to try:
    - Restart the iPad
    - Remove and reinstall Keynote
    - Restore the OS on the iPad
    One of those might fix the problem.
    Regards.

  • Search not working with multiple select in dropdown field

    Hello,
    Please first visit below site for searching form on left side.
    http://diventarepartner.unicaimmobili.com/home-page_copy_dynamic
    There is a field called Tipologia which is dropdown menu with checkbox (multiple select). Choose more than one checkbox and its automatic append with comma in text field which is customized using javascript. Now then if you submit button then its not working as our products.
    Now for this there is a custom field in admin in web apps items. This field is same for all items and values are different for all items like that which you can see above dropdown checkboxes value.
    Now my question Is it possible that for that one field in admin which has different value for different items and when i search from website and checked that cehck boxes and it search for all different items ??
    For example in admin suppose 2 items which has different value for that one field. Suppose one has value called Appartamento and other is Villa. Now from search form which is on website, that dropdown checkboxes, if i select these two values (Appartamento and Villa) from these and then search, it will display that both items from web apps ???
    Is it possible ??? Can you help me for this ???
    Waiting for reply. Thanks in advance.

    Your link doesn't work. Do you mind reporting it?

  • Sql command not working with date time??

    I am using my own sql query to fetch data in the sql command.
    Due to the problem I found - here is the basic example:
    The sql is:
    select to_number(to_date('10/11/2011 10:23:00','dd/mm/yyyy hh24:mi:ss') - to_date('10/11/2011 10:20:00','dd/mm/yyyy hh24:mi:ss'))  minu  from dual
    But I am not getting anything in Crystal Report tool!!
    In any sql tool I get results.
    When I am not using time part (hh24:mi:ss) :
    select to_number(to_date('10/11/2011','dd/mm/yyyy') - to_date('09/11/2011','dd/mm/yyyy'))  minu
    from dual
    I am getting data!!!!
    What is the problem??
    Initially I had it with parameters of type 'Date Time'
    Please, any one knows what the problem is?

    Hi,
    Sorry for the delay and thanks for answering.
    It was partial solution
    Moving to oracle driver, not (OLE DB), this specific one worked fine:
    select to_number(to_date('10/11/2011 10:23:00','dd/mm/yyyy hh24:mi:ss') - to_date('10/11/2011 10:20:00','dd/mm/yyyy hh24:mi:ss'))*100 minu from dual
    BUT
    When I tried to change one of the hardcoded values to be parameter of type 'Date Time' I couldn't pass the validation step - mostly the errors:
    "ORA 00900 Invalid sql statment"   and
    "ORA - 00907: Missing right parnthesis"
    No matter which format I used.
    Last version is:  
    select to_date('{?tsStartReport}','yyyy-mm-dd hh24:mi:ss') from dual
    Any idea why 'Date Time; is so problematic? How can I workaround it?

  • SQL Plus not work with domain user

    Hey guys,
    have a problem with sql plus in our network. when i started it with the admin it works. but when i started it with a user account, fill in the username, the password and the host and click on the ok button, the window closes and nothing happen. no error no new window, the window simply closes.
    what to do?
    regards

    Hi,
    There might be different reasons behind this.
    Check whether user is created in database or not.
    There might be possibility that, user is in different database.
    SELECT * FROM V$DATABASE; --This will help you to findout database name.
    SELECT * FROM DBA_USERS WHERE USERNAME = 'HR';  --HR is user present on database. If your user is present in database then user might not have connect privilege.
    GRANT CONNECT , RESOURCE TO HR; --HR is user. To execute this command, login as sys You can also try to login with command prompt.
    sqlplus user/password@host

  • Sql statement not working with for update

    Hi, iam facing an error fetch out of sequence
    when iam trying to execute a sql statement
    Statement st=con.createStatement();
    st.executeQuery(select mycolumn from table where jobno=1 for update);
    the statement works well without " for update ".
    any solutions????

    Hi,
    The fetch out of sequence error occurs usually when you are trying to read from a cursor that has no data left(like EOF).
    After executing the sql statement move the pointer to the first row (or the beginning of the resultset)
    This is actually an oracle error bearing number :ORA:01002
    Hope this helps.
    Thanks,
    Creator Team.

  • Problem with multi take drum tracks not working with group selection editing

    HI All
    Ive recently tracked drums into using 7 mics and doing multiple takes layered on top of each other, the 7 takes belong to the same group and i have enabled group editing in the settings.
    I think i changed the comp options at the end of the track and as a result audio tracks 1 and 2 edit between takes together fine. I.e. when i choose say take 5 with track it does the same selection for track 2.
    Tracks 3-7 work in the same way fine, im just wondering if anyone knows how to get them as a complete group again so that when i choose take 5 for example on the one audio track, it will make the same selection for all of them!
    thanks

    Colin,
    I did a multi camera edit of Act 1 of a taped performance and all went well. Moved on to Act 2, which ran longer and each camera needed a tape change. So I matched the clips from each camera on each video track and tried to move on to the sync & then create a multi camera sequence stage of the project. That's when I hit a road block. I could not sync the four video tracks. So I consulted Adobe's on line help and this was all I could find about my predicament:
    Note: Adobe Premiere Pro uses an overlay edit when  synchronizing clips. Take care not to overwrite adjacent clips if you have  multiple clips on the same track.
    So what was I to do next? I found your post and now know exactly what to do. Thanks for a great explaination and saving me a lot of head scratching.
    Why couldn't Adobe explain it as well?
    Thanks,
    Angelo

  • Column Aliases not working when using MS Query into Excel?

    I setup an Oracle ODBC connection from my desktop to an Oracle 9i DB, and created an MS Query sql:
    select sysdate as "Today" from dual;
    When I tried to run it and return it to Excel, it would ignore the column alias of 'Today' and keep putting in 'SYSDATE' as the column header.
    SYSDATE
    ==========================
    2007-04-18 11:55:54
    What I expected was:
    TODAY
    ==========================
    2007-04-18 11:55:54
    I've read some other reports out there on the web and tried changing a registry entry per the MSDN knowledge base, but that didn't help. Several of the existing threads in this forum only refer to exporting directly to an Excel file from Oracle, rather than pulling the information from the db into excel using an abstraction layer such as ODBC (ADO would be similar I'm sure).
    Just curious if other Oracle SQL guys have run into this same problem. I'm sure somebody's had to use a column alias in their Oracle->Excel results before..

    Are you using SQL plus? Have you tried Oracle's SQL
    developer? It is free, does not require an install
    on your computer (you can run it from a flash drive),
    and it exports pretty smoothly to excel.I'm not using SQL Plus -- this was purely excel / ODBC as the client and Oracle as the database layer.
    I had looked at SQL Developer, along with DB Visualizer (along the same lines , as a sql gui with some export capability to .csv and excel formats). However, I don't think it quite served my purpose in trying to have a workable data-source where I could pull from Excel and use VBScript or C# to do the manipulation and customized reporting/charting/pivot-tabling.
    My eventual workaround was to bypass MS Query altogether for creating the 'external data table' in Excel, and instead create the query through code.

  • Database Mail not working with SQL Server Agent

    I'm running SQL Server 2005 Standard edition 64 bit with SP2 on a 64 bit machine. 
    Database mail does not work with SQL Server Agent.  When I configure SQL Server Agent to use database mail the test email button is greyed out and inactive therefore I cannot send emails using operators or for jub success failure etc. 
    I've read that there was supposed to be a fix for this with SP1 but I have SP2 and still receive the same problem.  Please can somebody help as I do not wish to use SQL Mail as a work around due to this becomming redundant in future versions of SQL Server.
    Kind Regards

    The problems solved
    steps:
    1)we create a mail profile at at Managment->Database Mail ,of SQL Managment
    2)we set this account as "default" at Managment->Database Mail -> Configure Database Mail -> Manage profile security
    3)At tab "Alert System" of SQL Server Agent properties , we check the "Enable mail profile" , Mail System=Database Mail, Mail profile = "the profile we already create"
    4)we create a new operator at "Operators" of sql agent, where at "notification options" -> "Email name" we put the mail where we want to sent the agent the mails at failured job
    5)We go at a specific job, at tab "Notifications" ,we check the "email" check box and then we choose the operator we just create, at the text box next to check box.
    I hope not to forget something
    Thank You all for the help

  • Applets not working with Java 1.7.0_51 in MII 14.0 SP4 Patch 5

    Hi,
    I'm currently evaluating the migration of our MII 12.0 developments to MII 14.
    But I'm running in several issues just trying to use simple things like a SQL query template with an iGrid Display template in test mode.
    Used versions are: MII 14.0 SP4 Patch 5 and on client side the latest Mozilla Firefox with Java 1.7.0_51
    At first I always get a java security warning when the applet is being loaded about unsigned applications.
    At second the applet itself is not running. It always shows "No data available" and the java console shows the following errors (iResult is the id of the applet):
    iResult [ERROR] - Couldn't set query template: No Query Defined
    iResult [ERROR] - Couldn't set display template: null
    iResult [ERROR] - Couldn't set display template: null
    Is this perhaps a general problem, that the MII applets are not working with Java 1.7.x versions?
    If I call the same MII page from a client with Java 1.6.x it is working without errors.
    Do you have some suggestions for me?
    Regards Timo

    please clear your JAVA Cache. that should solve the JRE issue. thanks

  • PreparedStatement not working with Oracle

    Hi All,
    I am using preparedStatement in my JDBC code to fetch/insert values from oracle9i database.
    I am checking condition like if a given record does not exist then insert it else update it.
    First time it works when there is no row in database, however for subsequent run it's not able to return me the result though that row exist in database and this resulting in DuplicateKeyException becuase it try to create the row in db again.
    The code is working fine for MySQL DB2 and SQLServer but doesn't work in case oracle 9i
    Here is mycode
    //problem is here 1st time it works next time it is not retunring true though record is there in DB.
    if(isItemExist("1","CORP"))
    updateItem("1","CORP","DESC1");
    else
    insertItem("1","CORP","DESC1");
    public boolean isItemExist(String itemid, String storeid)
    String FIND_SQL = "SELECT item_desc from item where item_id = ? and store_id = ? ";          
    c = utils.getConnection();
    ps = c.prepareStatement();
    int i = 1;
    ps.setString(i++, storeid);
    ps.setString(i++, itemid);
    rs = ps.executeQuery();
    if(rs.next()){
         return true;
    utils.close(c, ps, rs);
    else{
         return false;
    utils.close(c, ps, rs);
    public void createItem(String itemid, String storeid, String item_desc)
    String INSERT_SQL = "INSERT INTO item(item_id,store_id,item_desc)values(?, ?, ?)";
    c = utils.getConnection();
    ps = c.prepareStatement();
    int i = 1;
    ps.setString(i++, itemid);
    ps.setString(i++, storeid);
    ps.setString(i++, item_desc);
    ps.executeUpdate();
    utils.close(c, ps, null);
    public void updateItem(String itemid, String storeid, String item_desc)
    String INSERT_SQL = "UPDATE item SET item_desc = ?, store_id=? WHERE item_id = ?";
    c = utils.getConnection();
    ps = c.prepareStatement();
    int i = 1;
    ps.setString(i++, item_desc);
    ps.setString(i++, storeid);
    ps.setString(i++, itemid);
    ps.executeUpdate();
    utils.close(c, ps, null);
    Kindly suggest what's wrong with code. because same code works with other databse like SQL Server, MySQL but it is not working with oracle9i.

    if(isItemExist("1","CORP"))
    updateItem("1","CORP","DESC1");
    else
    insertItem("1","CORP","DESC1");
    String FIND_SQL = "SELECT item_desc from item where item_id = ? and store_id = ? ";
    ps.setString(i++, storeid);
    ps.setString(i++, itemid);
    String INSERT_SQL = "INSERT INTO item(item_id,store_id,item_desc)values(?, ?, ?)";
    ps.setString(i++, itemid);
    ps.setString(i++, storeid);
    ps.setString(i++, item_desc);
    String INSERT_SQL = "UPDATE item SET item_desc = ?, store_id=? WHERE item_id = ?";
    ps.setString(i++, item_desc);
    ps.setString(i++, storeid);
    ps.setString(i++, itemid);My first guess, looking at the above snippets, would be that the item_id field is a number and not a string and so you should be calling ps.setInt instead of ps.setString when setting that parameter.
    This is only a guess, however, since you have not posted what the actual error is, which will probably give a hint to what the actual error is.

  • Two-finger pinch zoom not working with safari

    Suddenly, the two-finger pinch to zoom is not working with Safari. MBP 13", SL 10.6.8 andf Safari 5.1. The View Menu Zoom control works fine, and the Pinch gesture works once thereafter, but then not. I have reloaded the Safari .plist. Gesture works with the Desktop icons and iPhoto. Any suggestions?
    TIA
    Picman

    Ditto with the Newsstand-blocks-the-Home-Screen bug.
    I was eager to see the revised New York Times layout and disappointed when Newsstand wouldn't pinch closed.
    The irony is, we can finally "hide" the Newsstand in a folder but now it takes over our Home Screens. I'm hoping this will be fixed in the first update.

  • Flash player does not work with Ie or Firefox with win 8.1?

    Flash player does not work with Ie or Firefox with win 8.1 64, If i try and play a video I get the message to install Flashplayer.
    If I try and install it it says it is already installed. Your onsite  installer says it is not applicable to my machine.
    I have followed all the normal steps re enabling addons and active filters etc.
    all to no avail Pc is Dell 6 months old, Flashplayer has never worked on this machine. Last MS update mid Dec 2014.
    Version of flashplayer is 15....03.......

    Flash Player is a built-in component of Internet Explorer.  There's nothing separate to download or install.
    Firefox requires a different version of Flash Player (the NPAPI plug-in), which will be served to you if you go here: http://get.adobe.com/flashplayer using Firefox; however, there are some unique stability issues related to Firefox on Win8.1, and you're probably better off using Google Chrome if you want a more optimal experience with Flash Player.
    For problems where IE isn't being detected by sites that require Flash:
    First, confirm that ActiveX Filtering is configured to allow Flash content:
    https://forums.adobe.com/thread/867968
    Internet Explorer 11 introduces a number of changes both to how the browser identifies itself to remote web servers, and to how it processes JavaScript intended to target behaviors specific to Internet Explorer. Unfortunately, this means that content on some sites will be broken until the content provider changes their site to conform to the new development approach required by modern versions of IE.
    You can try to work around these issues by using Compatibility View:
    http://windows.microsoft.com/en-us/internet-explorer/use-compatibility-view#ie=ie-11

Maybe you are looking for

  • Capture failed in iStore sales order processing.

    Hi, I am using oracle 11i, When I ran our credit card capture process in iStore ,4 out of 11 transactions failed to capture but I do not see any specific issue with them,what is the reason for this ,please reply me ,this is very very critical The fol

  • Can I transfer books from a PC to an ipad

    I don't have an ipad now but I am thinking about getting an ipad mini. I have a lot of books on my PC. Is it possible to transfer the books that are on my PC to my new ipad (if I get one) ?

  • Edit in ... disabled?

    I have tried today to edit an image but Photoshop, as well as other editor and all other choices, are greyed out in the Develop module under Photo. I've certainly often used this and don't know why it's not working today. I'm using 2.3 under Win XP P

  • GVim color scheme - darkfix

    This is my custom gVim theme, based somewhat off of molokai. Optimized for PHP, HTML, CSS (still working on PHP, and Javascript). Download darkfix.vim http://theywillknow.us/uploads/darkfix-preview.png Last edited by ctruett (2010-10-11 17:59:40)

  • Itunes helper is corrupt...can't update itunes!!!

    Using the dreaded Vista, I have now tried to uninstall and reinstall the newest version of Itunes. My itunes/helper/resouces folder claims to be corrupt. When I try to empty all Itunes folders to start from scratch, I can't get rid of ituneshelper/re