Two questions relating to a so-called simple dynamic SQL

Version: 10 gr 2

Question1. Why is - this simple anonymous block to return the names of the tables and their stats collected date does not?
declare
v_rs date;

begin
     for i in (select table_name from user_tables)
          loop
          execute immediate 'select last_analyzed from user_tables where table_name = ' || i.table_name||  ' into v_rs';
          dbms_output.put_line('i.table_name '||v_rs);
     end loop;
end;
See the error of the actual execution below.




Question 2 of SQL * Plus formatting:

If you look at the performance below, you may notice that despite long lines at 5000, why is the line with immediate execution IE.
execute immediate 'select last_analyzed from user_tables where table_name = ' || i.table_name||  ' into v_rs';
go to the second line
7    execute immediate 'select last_analyzed from user_tables where table_name = ' || i.table_name
||  ' into v_rs';
The actual execution
SQL> set pages 100
SQL> set lines 5000
SQL> declare
  2  v_rs date;
  3  
  4  begin
  5   for i in (select table_name from user_tables)
  6    loop
  7    execute immediate 'select last_analyzed from user_tables where table_name = ' || i.table_name
||  ' into v_rs';
  8    dbms_output.put_line('i.table_name '||v_rs);
  9   end loop;
 10  end;
 11  /
declare
*
ERROR at line 1:
ORA-00933: SQL command not properly ended
ORA-06512: at line 7

You should always use EXECUTE IMMEDIATE!

Like this:

declare
  v_rs date;
  v_sql varchar2(600);
  v_table_name varchar2(200);
begin
  v_table_name := 'DEPT';
  v_sql:= 'select last_analyzed from user_tables where table_name = ''' || v_table_name||'''';

  dbms_output.put_line(v_sql);

  EXECUTE IMMEDIATE v_sql into v_rs;  

  dbms_output.put_line(to_char(v_rs, 'dd/mm/yyyy hh24:mi:ss'));
--  dbms_output.put_line(i.table_name ||v_rs);
end;
/

Tags: Database

Similar Questions

  • Two questions relating to the signature using restricted code API: s

    First question

    I have a library that contains classes that requires the signature in order to use API:s. limited one of the functions in the library uses "persistent storage". My application accesses the library import library module, then instanciates and calls the function that I need.

    Is it enough to have signed library or don't call asking the library must sign too?

    Second question

    Is it possible to configure the simulator so it actually tests that the modules using API: s limits are signed correctly?

    Check the Simulator definition "activate the safety of the device. When this setting is enabled, the Simulator checks would be signatures almost like a true pocket computer. For your application, which should be pretty good. If your module is missing a required signature, the simulated Pocket will complain even as would a normal hand.

  • Two Questions, sure enough the answer is simple.

    Hello
    I get the following error on a trigger, I wrote.

    LINE/COL ERROR
    15/49 PLS-00103: encountered the symbol "FIND" when expecting one of
    What follows:
    in like LIKE2_ LIKE4_ LIKEC_ between members SUBMULTISET_

    I was wondering what causes this error and how would approach I set?

    The trigger in question is
    -----
    CREATE OR REPLACE TRIGGER old_job_analyst
    BEFORE the update job ON emp
    FOR EACH LINE
    WHERE (old.job = 'ANALYST')
    DECLARE
    v_minsal sal.losal%TYPE;
    BEGIN
    It SELECT
    IN v_minsal
    BY sal
    WHERE rank = 5;

    IF new.sal < v_minsal then
    RAISE_APPLICATION_ERROR (-20002, ' remuneration must be at least 5 class ");
    END IF;

    EXCEPTION
    WHEN NO_DATA_FOUND THEN
    RAISE_APPLICATION_ERROR (-20001, could not find the salary classes, contact support!');

    WHILE OTHERS THEN
    RAISE_APPLICATION_ERROR (-20000, 'Database error');

    END;
    /
    -----
    The other error I get is

    LINE/COL ERROR
    10/7 PLS-00049: bad bind variable "V_COUNT.

    Since the following trigger
    -----
    CREATE OR REPLACE TRIGGER s1
    BEFORE insertion or update OF moduleid WE studentallocation
    FOR EACH LINE
    WHERE (new.stuid = 'S1')
    DECLARE
    v_count number (1);
    BEGIN

    SELECT count (*)
    IN v_count
    OF studentallocation
    WHERE stuid = "S1" AND moduleid = "M5" GOLD stuid = "S1" AND the moduleid = "M6".

    If: v_count = 1 then
    RAISE_APPLICATION_ERROR (-20001, 'Student S1 can't take the two M5 AND M6');
    end if;
    END;
    /
    -----
    Any help would be appreciated, but it would be very helpful if you could explain to me what has caused these errors, so I can fix it myself in the future.

    Thank you very much
    Joe

    Try

    create or replace trigger old_job_analyst
       before update of job
       on emp
       for each row
       when (old.job = 'ANALYST')
    declare
       v_minsal   sal.losal%type;
    begin
       select losal
         into v_minsal
         from sal
        where grade = 5;
    
       if new.sal < v_minsal
       then
          raise_application_error (-20002, 'Pay needs to be at least grade 5');
       end if;
    exception
       when no_data_found
       then
          raise_application_error (-20001,
                                   'could NOT find pay grades, contact support!'
                                  );
       when others
       then
          raise_application_error (-20000, 'database error');
    end;
    /
    
    create or replace trigger s1
       before insert or update of moduleid
       on studentallocation
       for each row
       when (new.stuid = 'S1')
    declare
       v_count   number (1);
    begin
       select count (*)
         into v_count
         from studentallocation
        where stuid = 'S1' and moduleid = 'M5'
              or stuid = 'S1' and moduleid = 'M6';
    
       if v_count = 1
       then
          raise_application_error (-20001,
                                   'Student S1 cannot take both M5 AND M6'
                                  );
       end if;
    end;
    /
    
  • two questions relating to the OBIEE 11 g Linux installer

    Hello

    1. do we need to install JDK 1.6 and above before installing OBIEE? as in below post what OBIEE uses it's own JDK.

    OBIEE 11 g on Windows 7 (64-bit)

    2 we need configure the DHCP in Linux loopback adapter as well as we do in windows? If yes how to do it in Linux?



    Please let me know the answers as soon as POSSIBLE.

    Thank you
    Jay.

    Hi Jay,.

    1. do we need to install JDK 1.6 and above before installing OBIEE?

    Not required

    2 we need configure the DHCP in Linux loopback adapter as well as we do in windows? If yes how to do it in Linux?

    On Linux x 86 operating systems, configure the host to resolve to the IP address of the loopback host names by editing the file/etc/hosts to contain the following entries:

    127.0.0.1 nomhote.nomdomaine hostname
    127.0.0.1 localhost.localdomain localhost

    After that, make sure that the host name resolves to the loopback IP address by typing the following command:

    / bin/ping nomhote.nomdomaine

    Kind regards
    DpKa

  • Two questions relating to the archive redo logs with RMAN backup

    DB version: 11g

    I am new to RMAN.

    My database is in ARCHIVELOG mode. I intend to make a weekly backup for my db (02:00 every Monday). There will be all the incremental backups between these windows(Monday-to-Monday) of backup that I have would function for retrieving archived redo logs.


    Question1.
    I want to save the archived logs every day (for example at 23:00). How can I configure that?

    These are the configuration setting, that I intend to implement. I don't know how to set up the archive log backup
    configure default device type to disk;
    configure retention policy to redundancy;
    configure device type disk parallelism 1;
    configure channel 1 device type disk clear;
    configure channel 2 device type disk clear;
    configure channel 1 device type disk format '/u05/rman1/datafiles/rmnabackup1_%U';
    configure channel 2 device type disk format '/u05/rman2/datafiles/rmnabackup2_%U';
    configure controlfile autobackup on;
    configure controlfile autobackup format for device type disk to '/u05/rman1/control_files/rmnabackup1_%U';
    Question2.
    After that a new full backup is taken at 02:00 on Mondays, the archived redo logs accumulated since the last 7 days become unnecessary. How can I automate the removal of the archive redo logs with RMAN?

    Archive the log delete them all input command will take the destination of the log archiving log backup archive and delete this destination.

    In the log archive destination he has archived log in the sequence 1 to 100 then will he take the backup and delete any of the destination (Monday 23:00).

    In the log archive destination he has archived sequence journal 101 to 150 then will he take the backup and remove those in the destination (Tuesday 23:00).

    In the log archive destination he has archived log in the sequence from 151 to 180 so will he take the backup and delete any of the destination (Wednesday 10:00).

    It will continue like that.

    Concerning
    Asif Kabir

    -If you help brand the response as correct/useful.

  • Need to (variable substitution) very simple dynamic SQL syntax

    I have a radio button component called P34_RADIO with two buttons (for the sake of discussion). The first button returns the string LONG_REPORT. The second button returns the string SHORT_REPORT. LONG_REPORT and SHORT_REPORT are the names of two tables in my database schema.

    When you build a standard report (non-interactive), I care about her source of little code that essentially says: select * from & P34_RADIO. When the user selects the button of LONG_REPORT radio, the report would go select * from long_report. When the user selects the button of SHORT_REPORT radio, the report would go select * from short_report.

    I tried select * from
    & P34_RADIO
    & & P34_RADIO
    : P34_RADIO
    #P34_RADIO #.
    & P34_RADIO.

    No matter what I tried, the result is the same:

    Query cannot be parsed in the generator. If you believe that your query is syntactically correct, check the generic "columns" box below the source of the region without analysis. ORA-00903: invalid table name

    I boiled the situation down to its basic components in this post. The real problem is quite a bit bigger than that and it's not as common I did look. But I can solve the larger problem, if I can learn how to accomplish this override of table name.

    Apex 4.1.0.00.32 (apex.oracle.com) running.

    Thank you!

    Hi Marc,

    Try to give below the pl/sql code in the classic rpt
    return ' select * from '. v ('P34_RADIO');

    Concerning
    Jean Claude

  • Simple dynamic SQL, eating my lunch

    I have a variable called that contains this string simply sql:

    < cfset insertstatement = "INSERT INTO parts (partname, unitprice, partdescription) values ('Screw'. 35, 'InsertScrew')" > ".

    If I output the sql and run the sql on the DB, it works fine.
    If I use the variable in a cfquery, he explodes:

    "< name cfquery =" "datasource =" "password =" ">
    #insertstatement #.
    < / cfquery >

    It is said:
    Run database query error.
    [Macromedia] [SQLServer JDBC Driver] [SQL Server] Incorrect syntax near 'screws '.


    Underneath, it says:
    SQLSTATE HY000
    SQL INSERT INTO parts (partname, unitprice, partdescription) values ("live",. 35, "InsertScrew")
    VENDORERRORCODE 102

    I don't know how he got in single quotes to double quotes, but I think that my being my problem.
    Any ideas?

    I didn't know that I needed to use the function preservesinglequotes. It works now.

  • Dynamic SQL question. What are these apostrophes for?

    Here is a solution provided by Boneist in the two questions relating to a so-called simple dynamic SQL thread
    declare
    v_rs date;
    
    begin
    for i in (select table_name from user_tables)
         loop
         execute immediate 'select last_analyzed from user_tables where table_name = ''' || i.table_name||''''  into v_rs;
         dbms_output.put_line(i.table_name ||'----'||v_rs);
    end loop;
    end;
    When a tablename is extracted, it should be in single quotes as "DEPT". My question is about the quotes surrounding i.table_name (three quotes on the left) and 4 quotes on the right of the concatenation
    ''' || i.table_name||''''
    First quote on the left is the final quote from SELECT (' select last_analyzed)

    Second quote from left to right - I think this is the quote from beginning to the name of the table ("DEPT)

    Quote from third starting on the left -?



    I have not understant what 4 quotes on the right of the concatenation of c. I know one of them is the quotation from the end (right) for the name of the table (like DEPT')

    JOE_humble wrote:
    When a tablename is extracted, it should be in single quotes as "DEPT". My question is about the quotes surrounding i.table_name (three quotes on the left) and 4 quotes on the right of the concatenation

    Actually 4 quotes on the left quotation marks and 4 right...

    execute immediate 'select last_analyzed from user_tables where table_name = ''' || i.table_name||''''  into v_rs;
                      ^                                                         ^^^                  ^^^^
                      |                                                         |||                  ||||
                       \________________________________________________________///                  \||/
                                                  |                                                   \|
                                                4 quotes                                            4 quotes
    

    Maybe better if you look at it like this...

    Suppose we use a character # to indicate the beginning and the end of our strings...

    execute immediate #select last_analyzed from user_tables where table_name = ''# || i.table_name||#''#  into v_rs;
    

    Now, you can see that we have two strings concatenated with the variable string representing the table name concatenated together.

    Within each of these channels, we have two single quotes. When the parser crosses the two single quotes like this, in the string, which converts a quotation mark in the resulting string, rather than taking this means the end of the string itself.

  • Question related to the spam/hoax calls

    I frequently receive phone calls from an Asian voice claiming to be Microsoft support widows. He claims to have detected the virus and all kinds of horrible things on my computer. It will ask then as I turn my computer on and wait until the home screen is visible. It then asks me to press some buttons, which, out of suspicion, I refuse to do. I'm wrong. And if so, what might happen.

    Thank you in anticipation

    Bill

    Original title: am I paranoid

    Wednesday, January 21, 2015 16:17:35 + 0000, WilliamHolland1947 wrote:

    I frequently receive phone calls from an Asian voice claiming to be Microsoft support widows. He claims to have detected the virus and all kinds of horrible things on my computer. It will ask then as I turn my computer on and wait until the home screen is visible. It then asks me to press some buttons, which, out of suspicion, I refuse to do. I'm wrong. And if so, what might happen.

    Yes, you are right.

    It was a scam and with all the names and phone numbers, one who has
    become very frequent lately. See
    http://www.troyhunt.com/2012/08/virus-scams-social-engineering-victims.html
    and
    http://www.howtogeek.com/176605/tell-your-relatives-no-Microsoft-wont-call-you-about-your-computer/
    and
    http://www.howtogeek.com/180514/the-%E2%80%9ctech-support%E2%80%9D-scammers-called-Htg-so-we-had-fun-with-them/

    In addition to their money get on your part to do anything of any value,
    If you leave them in your computer, who knows what they were doing or where
    What confidential information they stole.

    So if you have done so, I highly recommend that you do both of the following
    immediately:

    1 do a clean reinstall of Windows.

    2. after reinstallation of Windows, change all your passwords.
    especially the banks or other
    financial sites.

  • I forgot my answers to the two questions iTunes how can I reset it please

    I forgot my answers to the two questions iTunes how can I reset it please

    You have to ask Apple to reset your security questions. To do this, click here and choose a method; If this page does not list one for your country or if you are unable to call, complete and submit this form.

    (139632)

  • My new Thinkpad S1 Yoga has two questions

    I got myself a Thinkpad S1 Yoga (20cd) and I have two questions;

    (1) the wireless lan driver fails and booting. (Dual band AC 7260)

    (2) the trackpad acts as a simple mouse. (ultranav driver is installed)

    I am running Windows 8.1pro (x 64). All the drivers are updated and updated the BIOS.

    Driver wireless lan starts normally when I disable the USB3 support in the bios or disable it "Intel (r) USB 3.0 eXtensible Host Controller - 0100 (Microsoft)" in Device Manager of.

    When I enable and disable the driver lan wireless driver again operating normally.

    The trackpad does not support actions such as scrolling.

    Kind regards

    Roberto

    Well the ultrapads issue is resolved. I uninstalled the ultrapads driver and the driver synaptics windows. After the reboot, the pavement was a standard ps/2 mouse to the microsoft driver. Change install the latest driver from ultrapads I have a thinkpad tab in the mouse control panel.

  • Custom menu item at the request of Message: two questions

    I try to add a custom menu to the Blackberry message request and get two questions:

    1. When you click the custom menu, the "Application.getApplication () .requestForeground (); method call does not call the main() method of my application "DemoMI".
    2. If I changed the method of

    Application.getApplication () .requestForeground)

    TO

    ApplicationManager.getApplicationManager () .runApplication (app); Where app is the "DemoMI" application descriptor

    Will be called the main() method. However, how can I make the subject of the Message around in the method "run" for the application "com.demo.DemoApp"?  I tried to use a static variable 'mi ContactsDemoMenuItem', but I've always had "null" value when the "main()" is called.

    My environment:

    • JDE: 4.2.0
    • Feature: Pearl 8100 with OS 4.2.0
    import net.rim.device.api.system.*;
    import net.rim.device.api.ui.component.Dialog.*;
    import net.rim.blackberry.api.menuitem.*;
    import net.rim.blackberry.api.pdap.*;
    import javax.microedition.pim.*;
    import net.rim.blackberry.api.mail.Message;
    import net.rim.device.api.ui.UiApplication;
    import net.rim.device.api.ui.*;
    import net.rim.device.api.ui.component.*;
    import net.rim.device.api.ui.container.*;
    
    public final class DemoMI extends Application
    {
        private static final String ARG_LAUNCH_CONTACT_DEMO = "1";
        private static  ContactsDemoMenuItem mi;
        public static void main(String[] args)
        {
            if(args == null || args.length == 0)
            {
                DemoMI app = new DemoMI();
                app.enterEventDispatcher();
            }else
            {
                String appToLaunch = args[0];
                if(ARG_LAUNCH_CONTACT_DEMO.equals(appToLaunch))
                {
                   new com.demo.DemoApp(mi.getMessage()).enterEventDispatcher();
                }
            }
        }
    
        DemoMI()
        {
            long locationToAddMenuItem = ApplicationMenuItemRepository.MENUITEM_EMAIL_VIEW ;
            ApplicationMenuItemRepository amir = ApplicationMenuItemRepository.getInstance();
            ApplicationDescriptor app = ApplicationDescriptor.currentApplicationDescriptor();
    
            app = new ApplicationDescriptor(app, new String[]{ARG_LAUNCH_CONTACT_DEMO});
            mi = new ContactsDemoMenuItem(app);
            amir.addMenuItem(locationToAddMenuItem, mi);
            System.exit(0);
        }
    
        private static class ContactsDemoMenuItem extends ApplicationMenuItem
        {
            ApplicationDescriptor app;
            Message msg;
            ContactsDemoMenuItem(ApplicationDescriptor app)
            {
                super(20);
                this.app = app;
            }
    
            public String toString()
            {
                return "My Menu Item";
            }
    
            public Message getMessage()
            {
                return msg;
            }      
    
            public Object run(Object context)
            {
                if ( context instanceof Message )
                {
                    msg = (Message)context;
                    try
                    {
    
                        Application.getApplication.requestForeground();
                        //ApplicationManager.getApplicationManager().runApplication(app);
                    }catch(Exception e)
                    {
                        e.printStackTrace();
                    }
    
                 } else
                 {
                    throw new IllegalStateException( "Context is null, expected a Contact instance");
                 }
                 return null;
            }
        }
    }
    

    What you see is the expected behavior.  The ApplicationMenuItem runs in a different process where your application was run.  You have two options.

    You can store the subject of the Message in the RuntimeStore when the ApplicationMenuItem is called.  Your application you are undertaking could then read the subject of the Message of the RuntimeStore.

    Or you can create an application based on the drawing below:

    How to allow - a listener in the background to detect and update a GUI application
    Article number: DB-00406

    http://www.BlackBerry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800451/800783/How_To _...

  • pdf export two questions please!

    Hello

    I have success attached a pdf file to my module, but now I have two questions:

    1 when the user clicks or rolls over the link does not change the point mouse to display that link is there.

    2 I tried my module on our server but not load the attached pdf file.  I clicked on the box in the pdf attached to the publication stage and it did download it but it changed its name to the name of the course.  When I looked at the link in the browser window, he looked at the folder in which I was initially to help to save my work.

    Help!

    Hello Devon,

    1. I guess you used a click box to make the connection. In this case, you can open the properties of the click box and go to the Options tab. You'll find the setting 'display the cursor hand on 'hit' area '. Activate it, and then your first problem is resolved.

    2. the link to the PDF file must be the relative path - not the absolute path. If your PDF file is located in the same directory as your Captivate swf main then just enter the name and no path ("mypdf.pdf").

    / Michael

    Click here to visit the blog of www.captivate4.com

  • two questions, hands on the record and SR/PR prometric IDs?

    I sent my questions to ocpexam_ww and get contradictory answers. I have two questions.

    1. in the past five years, I took the following courses: RAC, Linux for the DBAs, GRID, Performance Tuning, backup/restore, Admin workshop I, Admin Workshop II in different cities. I have certificates and registration IDs (even if we have a sticker quillogy gold covering the registration ID). I presented the eligible courses qualifications 'Hands on' on my account prometric I intend to get the oca, ocp, linux, network and perhaps rac certifications over the next five years. My account shows that two registered practical courses and anyone ranked my comments for other courses them marked as failed. I asked ocpexam, and they say that the first two are enough for the OCP. I know and understand that, but rather that the other doesn't have a marking would it not better mark their past for the qualifications of potential future certification? Especially since each class cost me around $6 k in travel, accommodation and registration?

    2. I have two accounts prometric which I asked to reconcile, but ocpexam response (s) that they have no record of them. My transition from 1z0 - 042 was recorded under a number of "PR #", while my hands previously mentioned Records are registered under number "SR # What should I do? I take today 1z0-007 and 1z0-043 before switching to the seller.

    1 failure hands on classes of forms: form of the House of Commons that you submit is directly related to a specific path. If you have submitted several courses for a certification path - 10g OCP DBA form, for example, one would be accepted or "passed." Others would be stranded because if they were to be used for the other certification paths, they would need be submitted by using a different key code.

    2 fusion ID: looks that OCP team could not find a record of your exam 1Z0 - 042 - is - right? So, go ahead and submit your request to ocpexam and let them know that you submitted this application before and they have been unable to find the folder of 042 review. Provide as much information as possible - all Prometric ID. And ask them to move forward and get worse if they cannot locate the 042 record so that this can be settled before the passage of Prometric to VIEW.

    Kind regards
    Brandye Barrington
    Certification Forum Moderator
    Manager certification program

  • Re: Two questions on the recovery of my Satellite C850 / 09L

    Hello

    I had an unfortunate accident with a drink and my C850 / 09L while in the hospital, and while he was cleaning that I used my external hard drive on an old computer.

    Long story short, while making the usable drive I have in some way managed to make the unreadable UEFI and need a recovery disk to fix it (which I did not cause of course I was in the hospital when the laptop was given to me).

    I have two questions:

    (1) the recovery disk creator organize files in a specific way, or can I copy the whole partition on a USB flash drive and make it work?

    and

    (2) if I am able to use the recovery partition copied or obliged to buy a Toshiba drive, the recovery disk difficulty will be just the OS or it will wipe my files as well?

    1 / recovery disc Creator create a special bootable media that can be used for the installation of laptop recovery image. If you want to install the recovery image, you MUST create this bootable media.

    2 / Yes Yes please before you use it to backup all your important data.

    If you have any other questions you are welcome.

Maybe you are looking for

  • Should I the "intego personal backup" on my new drive of lace

    Should I the "intego personal backup" on my new drive of lace? I just want to copy music than I do in my logic music program. I would also like to know the best way to copy my music from my old lacie drive to my new. Thanks for your help!

  • Drive HARD SSD update of HP ENVY 15 - j009wm AMD processor

    I read on some other forums that the Intel chip was required for updates.  I was wondering if it would be possible to upgrade the HDD of 750 GB in this laptop to an SSD.

  • need a sample code

    My knowledge of java are... It's my request, I have the answer, but I need a code example http://supportforums.BlackBerry.com/T5/Web-development/it-is-posible-to-make-widget-to-run-only-on-m... can someone help me?

  • Question of VPN &amp; ACS

    Hello It's maybe a stupid question, but I need to learn more about security issues, so here's my question: If the remote end users can access their corporate network via secure VPN, then why do need ACS solution? Thank you to educate me.

  • BlackBerry Smartphones REM Extension Confusion

    Ok... I'm REALLY confused now!  I got a few videos that I saved e-mail messages and MMS messages.  After recording, looks like they have a .rem suffix after a 3pg the file name extension.  I can visualize find on the storm, but when transferred to my