Try to make a loop on a select statement in a procedure

Ok
I'm writing a procedure that will make an operation on every table in a select statement.
Example: I want to add a column in each table that starts with "XX_" (XX_01, XX_BD, etc.)
I have new procedures.
I guess I have to use a cursor that is defined as:
cursor xbtable is select * from user_tables where table_name like 'XX_%';
begin
open xbtables;
loop
Then what?
How to make this work.
Also, I have to use substr() on xbtable to extract parts of the name of the table...

Can anyone help?

THX

I'm sorry, I made a mistake

cursor xbtable is select * from user_tables where table_name like 'XX_ % ';
String VARCHAR2 (200);
Start
for everything in the loop of xbtable
string: = 'ALTER TABLE ' | Everything.table_name | "ADD column_name column-definition."

immediately run a string;

end loop;

end;

Tags: Database

Similar Questions

  • a loop on a select statement

    Hello
    I'm doing a loop on a select statement, I give as input to select a string with a list of numbers, separated by "," (I call it projectIdList)
    but in the loop it iterates only on the first element
    for example, if I give a string 1,2,3,4,5
    just 1 iteration happen

    Here's the head

    I'm in (select substr (the_string, decode (level, 1, 1, instr(the_string,',',1,level-1) + 1), decode (instr(the_string,',',1,level), 0, length (the_string), instr(the_string,',',1,level) - decode (level, 1, 0, instr(the_string,',',1,level-1))-1)) (select projectIdList from double the_string) ProjectID connect by level < length (replace (translate (the_string,'01234567890 ', ' 00000000000') '0')) + 2) loop



    does anyone have an ideal?

    Concerning
    Sallemel

    I don't have a version 9i database to test on (as he has not supported), but I think it works on 9i if you wrap the link by select in another selection...

    SQL> ed
    Wrote file afiedt.buf
    
      1  declare
      2    v_projectlist varchar2(100) := '2,8,5,4'; -- This is my "parameter"
      3    cursor cur_v is
      4      select projectID
      5      from (
      6        select substr(the_string, decode(level, 1, 1, instr(the_string,',',1,level-1)+1),
      7                                  decode( instr(the_string,',',1,level), 0, length(the_string), instr(the_string,',',1,level)
      8                                - decode( level, 1, 0, instr(the_string,',',1,level-1))-1) ) ProjectID
      9        from (select v_projectlist the_string from dual )
     10        connect by level < length(replace(translate(the_string,'01234567890','00000000000'),'0')) + 2
     11        );
     12  begin
     13    for i in cur_v
     14    loop
     15      dbms_output.put_line('Row: '||cur_v%ROWCOUNT||' - Value: '||i.ProjectID);
     16    end loop;
     17* end;
    SQL> /
    Row: 1 - Value: 2
    Row: 2 - Value: 8
    Row: 3 - Value: 5
    Row: 4 - Value: 4
    
    PL/SQL procedure successfully completed.
    
    SQL>
    

    Just give it a go.

  • How to store select statements in a procedure and use it as a parameter

    I need to enter below the select statements in a stored procedure with an input parameter, business_dt_num. This parameter must be the result under the statement select and placed inside the procedure...
    select max(business_dt_num)
    from invent.dp_ca 
    If a select statement fails he must get out of the execution of the procedure and is not engaged in the next select statement. How can I cancel the execution of the procedure, if a select statement fails?
    select max(business_dt_num)
    from invent.dp_ca 
    /
    Select count (1)
    of invent.dp_ca
    where BUSINESS_DT_NUM = YYYYMMDD
    and product_id! = 0 ;
    -above and below sql account must match
    Select count (1)
    invent.dp_ca d, e invent.dp_ca_proof
    where d.BUSINESS_DT_NUM = YYYYMMDD
    and d.KEY_ID = e.KEY_ID;
    /
    exec pk_proof.pr_PopulateTaggingWorkTable_CA (yyyymmdd);
    /
    SELECT count (distinct univ_key_id) of invent.dp_ca_proof
    where business_dt_num = YYYYMMDD and proof_status! = « A » ;
    -above and below sql account must match
    Select count (0) in the invent.dp_ca_work where business_dt_num = YYYYMMDD.
    Thanks,
    Steve
    
    Edited by: steve2312 on Dec 22, 2011 12:32 PM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
    declare
       dp_ca_count1 number;
       dp_ca_count2 number;
    begin
       select count(1) into dp_ca_count1
       from invent.dp_ca
       where BUSINESS_DT_NUM = trunc(sysdate)
       and product_id != 0;
    
       select count(1) into dp_ca_count2
       from invent.dp_ca d, invent.dp_ca_proof e
       where d.BUSINESS_DT_NUM = trunc(sysdate)
       and d.KEY_ID = e.KEY_ID;
    
       if dp_ca_count1 != dp_ca_count2 then
               raise_application_error (-20001, 'Counts do not match.');
       end if;
    end;
    /
    
  • passing multiple values from the query in the select statement of the procedure

    I am collecting IDS to select education agreement from the date of rental values and then I would pass the result of the query in the statement select to get the result.
    data type for the contract id is of type varchar and date of rental there is more than one id to contract for most of the time. Help, please. Thank you

    CREATE OR REPLACE PROCEDURE abstract_menu (p_letting   IN     VARCHAR2,
                                               p_results      OUT SYS_REFCURSOR)
    IS
       v_contractId   VARCHAR2 (40);
    
    SELECT lcontid
      INTO v_contractId
      FROM letprop
     WHERE datestat IS NOT NULL AND letting = p_letting AND letstat <> 'R';
    
    
    BEGIN
       OPEN p_results FOR
            SELECT DISTINCT
                      SUBSTR (l.letting, 3, 2)
                   || '-'
                   || SUBSTR (l.letting, 5, 2)
                   || '-'
                   || SUBSTR (l.letting, 1, 2)
                      lettingdate,
                   l.lcontid contractid,
                   SUBSTR (q.cprojnum, 1, 10) projectnumber,
                   DECODE (TRIM (MIN (j.route)), NULL, 'N/A', TRIM (MIN (j.route)))
                      routenumber,
                   L.DATESTAT statusdate,
                   L.LETSTAT lettingstatus,
                   (q.cdescr) jobdescription,
                   INITCAP (q.clocat1 || q.clocat2) LOCATION
              FROM vendor v,
                   vendaddr r,
                   letprop l,
                   planhold p,
                   proposal q,
                   project j,
                   propproj k,
                   bidlet bd
             WHERE     v.vendor = r.vendor
                   AND k.contid = q.contid
                   AND k.pcn = j.pcn
                   AND l.lcontid = k.contid
                   AND p.vendor = v.vendor
                   AND l.letting = p.letting
                   AND l.lcontid IN v_contactid  "**************This is where I would like to pass the contract id from the above select statement***********'"
                   AND l.CALL = p.CALL
                   AND r.addrnum = p.billto
                   AND bd.letting = l.letting
          GROUP BY q.cdescr,
                   q.clocat1,
                   q.clocat2,
                   bd.letting,
                   l.letting,
                   l.lcontid,
                   q.cprojnum,
                   L.LETSTAT,
                   L.DATESTAT
          ORDER BY lettingdate;
    
    end;

    user9196150 wrote:
    AND l.lcontid IN v_contactid ' * this is where I would like to pass the id of the select statement above contract * ""»

    CREATE OR REPLACE PROCEDURE abstract_menu (p_letting   IN     VARCHAR2,
                                               p_results      OUT SYS_REFCURSOR)
    IS
    BEGIN
       OPEN p_results FOR
            SELECT DISTINCT
                      SUBSTR (l.letting, 3, 2)
                   || '-'
                   || SUBSTR (l.letting, 5, 2)
                   || '-'
                   || SUBSTR (l.letting, 1, 2)
                      lettingdate,
                   l.lcontid contractid,
                   SUBSTR (q.cprojnum, 1, 10) projectnumber,
                   DECODE (TRIM (MIN (j.route)), NULL, 'N/A', TRIM (MIN (j.route)))
                      routenumber,
                   L.DATESTAT statusdate,
                   L.LETSTAT lettingstatus,
                   (q.cdescr) jobdescription,
                   INITCAP (q.clocat1 || q.clocat2) LOCATION
              FROM vendor v,
                   vendaddr r,
                   letprop l,
                   planhold p,
                   proposal q,
                   project j,
                   propproj k,
                   bidlet bd
             WHERE     v.vendor = r.vendor
                   AND k.contid = q.contid
                   AND k.pcn = j.pcn
                   AND l.lcontid = k.contid
                   AND p.vendor = v.vendor
                   AND l.letting = p.letting
                   AND l.lcontid IN (
                                     SELECT  ll.lcontid
                                       FROM  letprop ll
                                       WHERE ll.datestat IS NOT NULL AND ll.letting = p_letting AND ll.letstat  'R'
                                    )
                   AND l.CALL = p.CALL
                   AND r.addrnum = p.billto
                   AND bd.letting = l.letting
          GROUP BY q.cdescr,
                   q.clocat1,
                   q.clocat2,
                   bd.letting,
                   l.letting,
                   l.lcontid,
                   q.cprojnum,
                   L.LETSTAT,
                   L.DATESTAT
          ORDER BY lettingdate;
    
    end;
    /
    

    SY.

  • function() nested in the select statement

    Oracle 11g. Try to nest a function within the select statement.  Goal: get the average customer rating for each of the qualified user.

    Select user_name, f_get_avg_cust_rating() "Notation.

    of u, OTHER_TABLES o TAB_USER

    where u.id = o.id and another condition matched;

    How Oracle would deal with the sql.  Is it

    (1) first of all display records based on the where clause, then call the f_get_avg_cust_rating() for each of the selected records OR

    (2) for the analysis in tables, the f_get_avg_cust_rating() will be called for each record met?

    Thank you

    Scott

    Words of Frank, I created two functions with dbms_output and used a function in where clause in select another function. See the bottom of the unit tests. Everyone says, where first clause then select...

    -Where function clause

    SQL > CREATE or REPLACE FUNCTION ret_empno

    2 RETURN NUMBER

    3 AS

    4 BEGIN

    5 DBMS_OUTPUT. Put_line (' where Clause Function');

    6 RETURN 7839;

    7 END;

    8.

    The function is created.

    -Select the function

    SQL > CREATE or REPLACE FUNCTION ret_1

    2 RETURN NUMBER

    3 AS

    4 BEGIN

    5 DBMS_OUTPUT. Put_line ('Select function');

    6 RETURN 1;

    7 END;

    8.

    The function is created.

    SQL > SELECT empno, ename,ret_1

    2 FROM emp

    3. WHERE empno = ret_empno;

    EMPNO, ENAME RET_1

    ---------- ---------- ----------

    7839 KING 1

    Where the function Clause

    Select the function

  • SELECT query in a procedure

    How to create a procedure to SELECT similar to the following query? When I create a procedure; I get an error.

    • "Error (80.1): PLS-00428: an INTO clause in the following SELECT statement.

    PROCEDURE MyProc

    IS

    BEGIN

    Select 'Dakota' as an ALIAS

    A.StartDate

    B.EndDate

    customer A

    , Customers b

    where a.cType = b.cType

    and b.Active = 0

    ORDER BY StartDate, EndDate

    MyProc END;

    remove the; at the end of your query

  • whenever I try to make my computer in Hibernate, or sleep, he starts running instead of doing what I select

    Original title: why isn't my Vista system down correctly?

    Last month, I noticed that whenever I try to make my computer in Hibernate, or sleep, it will restart instead of doing what I select.  Several times, it will reboot, sometimes in Mode without failure.  This never used before, and it's really disturbing.  What is happening, and how can I fix this problem so that my computer will sleep or Hibernate when I choose these options?  Thank you.

    Hi Ako1979,

    (1) remember you to make changes prior to this problem?

    (2) you get an error message?

    (3) using a laptop or a desktop computer?  Please provide the serial number and model


    Method 1:
    change the power plan and then check if the problem persists. To do this, follow the steps mentioned in the link below

    Change, create, or delete a power plan (scheme)
    http://Windows.Microsoft.com/en-us/Windows-Vista/change-create-or-delete-a-power-plan-scheme


    Method 2:
    to turn off the power on the USB (Universal Serial Bus) hub and then check if it makes a difference

    (a) right click on my computer, click Properties and click the Hardware tab, then click Device Manager.

    (b) double-click to expand, USB Bus controllers right click on USB root hub, and then click Properties.

    (c) click the power management tab.

    (d) clear the allow the computer to turn off this device to save power check box, and then click OK.

    Method 3: Download and install all the available Windows updates

    Install Windows updates
    http://Windows.Microsoft.com/en-us/Windows-Vista/install-Windows-updates

    For more information, please visit the links below

    Change what happens when you close your mobile PC
    http://Windows.Microsoft.com/en-us/Windows-Vista/change-what-happens-when-you-close-your-mobile-PC-lid

    Change the function of the power button on your laptop
    http://Windows.Microsoft.com/en-us/Windows-Vista/change-the-function-of-the-power-button-on-a-mobile-PC

  • Error when you try to modify or to open a video (WLMP) using Windows Live Movie Maker: Movie maker does not support the selected file

    WLMP does not open on windows live movie maker?

    Well I made a video Windows live Director and saved it but when I try to open it to change some more it is said "Movie maker does not support the selected file" but he should not let me because I did in windows live Director please help!

    I'm having the same problem, but if I double click on the Window media player file appears help!

    ================================================
    Right-click the. WLMP file and try... Open with / Windows Live Movie Maker...

    See the following article

    Windows 7 - changing the programs that Windows uses by default
    http://Windows.Microsoft.com/en-us/Windows7/change-which-programs-Windows-uses-by-default

    Volunteer - MS - MVP - Digital Media Experience J - Notice_This is not tech support_I'm volunteer - Solutions that work for me may not work for you - * proceed at your own risk *.

  • Very new to photoshop, I try to make changes to a photo and set up as a dynamic object, but after the selection of dynamic object, the grid appears and my photo dissppears

    Very new to photoshop, I try to make changes to a photo and set up as a dynamic object, but after the selection of dynamic object, the grid appears and my photo dissppears

    Well, something's wrong with Photoshop. Try to close Photoshop, and then press Command + Option + shift as you restart Photoshop. You will be asked to clear the Photoshop preferences. ATTENTION: you will lose all current preferences.

  • My destop all icons are colored and when I try to make crystal or visible, I can't change

    My destop all icons are colored and when I try to make it transparent or visible, I can't change

    Click the Start button, select Control Panel

    Check points: -.
    1. in the performance and Maintenance/adjust Visual effects or if you use the classic theme - settings/system/advanced/performance
    'Use the shadows of the desktop icon labels -' must be checked
    2. right click on the desktop, point to arrange icons by and ensure that items Web Lock on Desktop is unchecked;
    3. If you have content web on your desktop, transparency does not do a right click on the desktop. Select properties, then go to the Desktop tab.
    Click on the button customize the desktop, and then open the Web tab.
    Uncheck everything in the box of Web Pages
    Press OK, then apply and OK again.
    4. you can't have a file html as wallpaper, it must be an image file.
    It is sometimes necessary to restart to take effect, sign out and then sign back in.

  • Whenever I try to make my project with the media encoder, it crashes. Can anyone help?

    Exactly what the title says.

    If I try to make in Adobe Premiere or send it to the Media Encoder, the project blocks everything to halfway through the rendering process. He always seems to crash at the same point in the process. Similarly, the program crashed a few times while I was working on the project, but I've always been able to recover and pick up from where I had left. Everybody knows such a question and know how to fix?

    Hi Matt,

    Ann has a valid point. If it crashes at the same place every time, she can be the media on the timeline at this particular point, or may be the effects. (if requested) Give it a shot and let us know.

    In addition, this could help:

    Go to file > project settings > General and change the "Video Renderer" to "only Mercury playback engine software. Click 'OK' and select "Remove the Previews". Then export them again.

    Thank you

    Regalo

  • Skype crashing when I try to make a call 7.9.0.103

    Hello.

    I never had this problem before it started today. When I try to make a Skype call it always crashes. It works perfectly until I make a call. I tried to rename the Skype folder in %APPDATA%\microsoft\windows\sendto and deleted the db folder, but none of them seem to work because I still have the same question. I added my hope to report dxdiag that you guys can help me. Thanks in advance

    The Windows event log:

    Log name:      Application
    Source: Application error
    Date: 5.9.2015 01:22:44
    Event ID: 1000
    Task category: (100)
    Level: error
    Key words: Classic
    User: n/a
    Computer: Skynet
    Description:
    Name of the failing application: Skype.exe, version: 7.9.0.103, time stamp: 0x55ddec34
    Name of the failed module: KERNELBASE.dll, version: 6.2.9200.16384, time stamp: 0x5010ac2f
    Exception code: 0xe0fafac1
    Offset: 0x00014b32
    Process ID vulnerabilities: 0x15dc
    Start time of application vulnerabilities: 0x01d0e7602bd05ad6
    The failing application path: C:\Program Files (x86)\Skype\Phone\Skype.exe
    Path of the failing module: C:\Windows\SYSTEM32\KERNELBASE.dll
    Report ID: 7640be1c-5353-11e5-bfb7-54a05052abbd
    Faulting full name of the package:
    ID of the failed package-parent application:
    The event XML:



    1000
    2
    100
    0 x 80000000000000

    1594832
    Application
    Skynet



    Skype.exe
    7.9.0.103
    55ddec34
    KERNELBASE.dll
    6.2.9200.16384
    5010ac2f
    e0fafac1
    00014b 32
    15dc
    01d0e7602bd05ad6
    C:\Program Files (x86)\Skype\Phone\Skype.exe
    C:\Windows\SYSTEM32\KERNELBASE.dll
    7640be1c-5353-11e5-bfb7-54a05052abbd





    Edit: added Windows event log

    Try to uninstall the currently installed version of 7.9 and install the older version of Skype 7.8.0.102 using this Setup program:

    http://download.Skype.com/MSI/SkypeSetup_7.8.0.102.msi

  • Error "classic asp not installed" when I try to make the purchase on a Web site.

    Original title: I am asp error whenever I try to make the purchase on the website, any help on this

    classic ASP not installed

    Communicate with those who are responsible for the Web site.  There is nothing wrong with your machine, it's their server which has problems and is perhaps misconfigured.

    You can't solve their website of your machine.

    Steve

  • Skype continues to ask valid directx when I also try to make a video call, what can I do?

    Skype is asking for valid directx when I also try to make a video call, I can do

    Hello

    • What is the version of DirectX installed?

    You can check the link below: how to determine the Version of DirectX using the DirectX Diagnostic tool: http://support.microsoft.com/kb/157730

    Follow the steps mentioned below and check to see if they help.

    Step 1:

    Download and install DirectX

    http://www.Microsoft.com/downloads/en/details.aspx?FamilyId=2da43d38-DB71-4C1B-bc6a-9b6652cd92a3

    Step 2:

    I suggest you follow the steps mentioned in the link given below.

    http://Forum.Skype.com/index.php?showtopic=594951

  • When I try to make my windows update I get error 641. I think it has something to do with my windows service install. I just want a simple solution to get my windows install to work.

    When I try to make my windows update I get error 641.  I think it has something to do with my windows service install.  I just want a simple solution to get my windows install to work.  When I try to update itunes it also fails.

    Yes, mechanic system is installed.  but I think that I have fixed last night.  IHAVE has since been able to get my installed updtaes and my itunes updated.

Maybe you are looking for

  • Satellite Pro L650 - network driver Pb after re - install Win7

    Good afternoon. A laptop computer was infected with a virus, so I re - install Win 7.My problem is that all network devices don't have 'no driver for this device.I install the drivers I download, but the problem is the same.When I view the list of de

  • Personalization of media (6 button series) - Satellite A200 keys

    I have a Satellite A200 - 1 M 8 (PSAE6E). It comes with 6 buttons of media (then on on / off button). Now, I managed to affect the inet and media buttons of player for Windows media player (WMP) and apps that I normally use instead of Internet explor

  • Error 62 TCP

    I try to write 4 info after a tcp connection is in place. 1. "registration". 2. "subscribe." 3. "HeartBeat". 4. "cancel registration". 1, 2 and 4 to send to the server to client without problem, but 3 cannot cross and give a message of error code 62.

  • The taskbar icon remains highlighted even when the mouse is moved.

    In windows 7, (and this is just a recent problem, so probably linked to an update of windows or something) normally when you move the mouse over an icon that is pinned to the taskbar (or icon of a window that is open) he puts out, then when you move

  • Browser and Outlook 10 are not open.

    My browsers (IE and Firefox and Chrome), but also the 10 Outlook does not connect to the internet.  I know that I have an internet connection because Skype works.   I tried a lot of solutions, but none works.  What remains?  (I'm this component on an