Count(*) in the loop doesn't work and I really don't know why...

Hello,
I can't figure out why the following doesn't work. I cannot debug for I do not have privileges on this server.
The execution always fails on bolded line. If I substitute the variable with the table name itself it works. The variable is properly populated in each of the iterations as I can see it by using dbms_output package. The small but may be important detail may be I am connected as user A but the tables are in the schema B. However I can list the tables and their columns in all_tab_cols view and there are synonyms made in my schema which allow me to access the B tables without prefixing them.
I get the error:
Error report:
ORA-00900: invalid SQL statement
ORA-06512: at line 26
00900. 00000 - "invalid SQL statement"
*Cause:   
*Action:
I ran out of ideas and I do not have access to any of the Oracle instance to be able to debug right now.
Variable type for v_tables is wrong? I do not have some magic privilege to use execute immediate with variable?
Oracle server has a bad day today?
The crap is 11.1.0.7 if it has anything to do with my problem.
Please help if you can.
Grzegorz
declare
v_number number := 646989;
v_current_table nvarchar2(50);
v_itemno number;
type t is table of nvarchar2(50);
v_tables t;
begin
dbms_output.put_line('Working...');
select table_name bulk collect into v_tables from all_tab_cols where column_name = 'ITEMNO' order by table_name;
for i in 1 .. v_tables.count loop
dbms_output.put_line('Number: ' || i);
v_current_table := v_tables(i);
<b>execute immediate 'select count(*) from ' || v_current_table || ' where itemno = :a' into v_itemno using v_number;</b>
if (v_itemno > 0) then
dbms_output.put_line('Current table contains specific ITEMNO: ' || v_current_table);
end if;
end loop;
end;

In SQL Plus run this and see what SQL is your code returning. Then execute the SQL individually.
set serveroutput on
declare
     v_number number := 646989;
     v_current_table nvarchar2(50);
     v_itemno number;
     type t is table of nvarchar2(50);
     v_tables t;
     lSqlString varchar2(20000);
begin
     select table_name
       bulk collect into v_tables
       from all_tab_cols
      where column_name = 'ITEMNO'
      order by table_name;
     for i in 1 .. v_tables.count loop
          v_current_table := v_tables(i);
          lSqlString := 'select count(*) from ' || v_current_table || ' where itemno = :a';
          dbms_output.put_line(lSqlString);
          --execute immediate  lSqlString into v_itemno using v_number;
     end loop;
end;

Similar Messages

  • I have some problem with my computer because when i turn it up, the screen turns in a blue colour and the sound doesn't work and in this way i can't hear anything

    i have some problem with my computer because when i turn it up, the screen turns in a blue colour and the sound doesn't work and in this way i can't hear anything

    Will u help me or not?

  • How to I set an internal link in a PDF document using Preview?  After setting a link under the Tools/Annotations menu, the link doesn't work and no detailed instructions are provided.

    How to I set an internal link in a PDF document using Preview?  After setting a link under the Tools/Annotations menu, the link doesn't work and no detailed instructions are provided via the Help menu other than it showing the pull-down menu selection to make.

    No.  I am able to use the other features such as underlining, highlighting, adding rectangles and oval and save those changes.

  • I just upgraded the software on my iphone 4s and now the touchscreen doesn't work and i have the itunes logo an arrow and a plug on my screen

    I just upgraded the software on my iPhone 4s. Now the touchscreen doesn't work and on the screen is the itunes logo, an arrow and a plug. I have powered it off and on and nothing changes

    The iTunes icon and cable means that it's gone into recovery mode - you will need to connect the phone to your computer's iTunes and you should be able to use that to reset the phone, and you can then restore/resync your content to it

  • If your top bottom on the iPhone doesn't work and it's not insured can Apple do anything?

    If your top bottom on the iPhone doesn't work and it's not insured can Apple do anything?

    If you are talking about the sleep/wake button then the answer is yes. You will have to pay the out of warranty fee for replacement
    $149+tax

  • I keep getting "Unable to connect" for my firefox. It was working yesterday and I turned my computer off. I can get to the web using internet explorer 9. I don't know why my firefox is not working. Everything else is working. HELP....

    I keep getting "Unable to connect" for my firefox. It was working yesterday and I turned my computer off. I can get to the web using internet explorer 9. I don't know why my firefox is not working. Everything else is working.

    A possible cause is security software (firewall) that blocks or restricts Firefox or the plugin-container process without informing you, possibly after detecting changes (update) to the Firefox program.
    Remove all rules for Firefox from the permissions list in the firewall and let your firewall ask again for permission to get full unrestricted access to internet for Firefox and the plugin-container process and the updater process.
    See:
    *https://support.mozilla.com/kb/Server+not+found
    *https://support.mozilla.com/kb/Firewalls

  • Need help trying to use close button and i really like to know why it off

    need help trying to use close button and i really like to know why it off

    And in English? You need to explain better.
    Mylenium

  • Contact groups. My contacts get removed from the groups, not from All Contacts. I don't know why this happens. Anyone know why?

    Sometimes the contacts in certain groups are removed and the group is empty.  They do not get deleted, and are still in All Contacts, just get removed from the group.  Then I have to start all over again and add contacts to the groups.  This seems to happen randomly and I don't know why it does.  My contacts are synced with my Yahoo contacts.  I don't know if thats why.  Does this happen to anyone else?

    Thank You, thank You ...so much......that feature made me crazy!  
    Ocean20 wrote:
    This can be turned off in settings/accessibility/zoom. Then on the next screen turn off

  • The ScrollPane doesn't work, and the TextArea just keep getting bigger!

    Here is what I did: I made a Frame first. Then I made a TextArea. Then I made a Scroll. Then I made a panel.
    Then I add the TextArea and the Scroll to the Panel, and I add the Panel to the Frame, but the whole thing just doesn't work. Anyway, see for it yourself.
    Hope someone can find where I did wrong, thank you very much!
    import javax.swing.*;
    public class TextArea extends JFrame
         public static void main(String[] args)
              new TextArea();
         public TextArea()
              /*Frame*/
              this.setLocation(100, 100);
              this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              this.setResizable(false);
              /*TextArea*/
              JTextArea text = new JTextArea(10, 50);
              text.setLineWrap(true);
              text.setWrapStyleWord(true);
              text.setEditable(true);
              /*Scroll*/
              JScrollPane Scroll1 = new JScrollPane(text, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
              /*Panel*/
              JPanel panel = new JPanel();
              /*Add things together*/
              panel.add(text);
              panel.add(Scroll1);
              this.add(panel);
              this.pack();
              this.setVisible(true);
    }

    after you make this change, the reasons for your problem
    should become clear
        /*Add things together*/
        //panel.add(text);//<-------------remove line
        panel.add(Scroll1);

  • The volume doesn't work and just says headphones?

    We can't hear anything on the Ipad and when we push on the buttons to turn the volume up or down it just says 'headphones'

    A place to start, try giving it a reset. Hold down the sleep and home buttons, past when you see the red power down slider and until you see the silver apple. Let it reboot and try again.

  • In my ipad mini suddenly stoped saving photos and videos i don't know why

    My ipad nini suddenly stoped saving photos and videos i dont know why?,It is 8 months old product

    (A) Reset iPad
    Hold down the Sleep/Wake button and the Home button at the same time for at least ten seconds, until the Apple logo appears
    Note: Data will not be affected.
    (B) Reset all settings
    Settings>General>Reset>Reset all settings
    Note: Data will not be affected but settings will be reset.

  • My macbook air has no light in the display, the brightness doesn´t work and it flicks sometimes

    hello Im from mexico and i bought a macbook air 1 month ago and the brightness i too low I cant see anything on the display but I connect another display device by thunderbolt and it works, sometimes the display flicks when the macbook is some 30 minutes on, I adjust the brightness but nothing, i went to the store where I bought it and the said that is the lightback that i need to send a email to the apple and send it, someone has the email where i can ask?

    manolisevdalis wrote:
    When my Macbook is about to die,
    Are you letting the battery to be nearly totally discharged?  If so, that will dramatically shorten the battery life span.  Keep it attached to AC as much as possible.  Here is some battery information from Apple:
    http://support.apple.com/kb/ht1446
    Try a SMC reset:
    http://support.apple.com/kb/ht3964
    Ciao

  • Hi, I have an iPod and my cousin has a MacBook Pro, but whenever we try to FaceTime each other, it doesn't work. Plus, we don't know what to put besides our names in our contacts. What do I put for his contact number?

    How can I FaceTime him without getting, "This person is not availible?

    Settings > FaceTime. Be sure you have an Apple ID on file, and you should also see a header that says "You can be reached for video calls at:" where you can add an email address. The email address that is entered here is the email address you should use to FaceTime the other person.

  • Sony Xperia z1 sound on the left doesn't work

    Hello everybody,
    I have a problem with my sony xperia z1.
    On the left side the sound doesn't work anymore.
    I don't know if I put it out accidentally or if there's something broken.
    It is only with headphones.
    The right side just gives normal sound but the left side is completely shut off.
    If I just listen on the speaker there is no problem.
    Please help!
    Solved!
    Go to Solution.

    Check if there is something in the 3.5 mm input,some dirt or something.If that is not the problem,you might need new headphones.
    All we have to decide is what to do with the time that is given to us - J.R.R. Tolkien

  • My broadband wi-fi is chewing up MBs big time and I don't know why!

    Hi everyone Since yesterday for some unknown reason my 4G broadband wi-fi is chewing up MBs big time from my laptop and I really don't know why!  Even with the web browsers shut down, the broadband is chewing up at least 1MB per second and counting.  Maybe it's a malware problem?   I'm sure it's not a devious neighbour accessing the broadband because whenever I disconnect my laptop from the wi-fi, the wi-fi device stops chewing up MBs.  So it's something to do with my laptop.  I have a Sophos installed so I thought would have picked up any virus chewing up the MBs? Help anyone!  

    Has your laptop been downloading and updates? If you're using Windows, you can change the settings in control panel to stop it automatically downloading updates, you can choose which updates you want to install.
    If Mac, I'm not knowledgable with Apple devices. I would recommend chatting with wireless Bigpond Tech Support on 13 39 33 "wireless"

Maybe you are looking for

  • At&t to T-Mobile on unlocked Bold - Why does everything work? Will it keep on working?

    Due to at&t's lack of coverage at my house, I changed to T-Mobile.  I unlocked my Bold and simply put the T-Mobile sim card in. To my surprise, EVERYTHING works perfectly.   I am on the BES Data plan. The one thing that I don't understand is why my B

  • Flex 3 and connection to remote ubuntu server

    Good morning, I'm trying to retrieve the result from a SQL query to populate a datagrid. My server is a Ubuntu server on a virtual machine. I created the tables I want to extract information from using MySQLWorkbench and put them on my ubuntu server.

  • How can I get a listing of web orders entered by specific time period

    How can I get a listing of all the orders which has been entered via website using webtools. We need to make sure that all the orders which has been entered from website it is synced to B1 instead of looking at the synch error messages. The problem i

  • Execute a function c in pl-sql

    hi, i would like execute a c function in pl-sql int iCalculate ( int op1, int op2 ) return op1+op2; i would like compile a the function with gcc and creat .o file and after use this file in pl-sql. it's possible? The performance of this system?

  • How to deploy content of webdynpro- src- mimes via JDI ?

    Hello, maybe anyone has overcome this problem already. I am developing a webdynpro application using JDI scenario 2+ (dev in track). The application has a xml ini file and some pictures in the src->mimes->Components folder. When I build and deploy th