How to put a table as parameter name in the name of the cursor and the header as a variable?

Hello

I have the code:
create or replace procedure transpose_table_row2column(table_source IN VARCHAR2 ,table_result IN VARCHAR2) is

-- set serveroutput on;

v_nazwa_kamp      varchar2(100);
v_czas_start      date;
v_czas_stop       date;
err_code          varchar2(50);
err_msg           varchar2(2000);

cmd_1_drop        varchar2(50);
cnt_1             pls_integer;
cnt_2             pls_integer;
cnt_3             pls_integer;
cnt_4             pls_integer;
v_col_name        varchar2(50);
test              varchar2(5);

-- deklaracja wyjatku dla nieistniejacej lub niedostepnej tabeli
TableDoesNotExist     EXCEPTION;
PRAGMA EXCEPTION_INIT(TableDoesNotExist, -942);

-- nazwa pierwszej kolumny tabeli zrodlowej
cursor first_column is
    SELECT column_name FROM USER_TAB_COLUMNS WHERE TABLE_NAME = upper(table_source) and column_id = 1;

-- wartosci z pierwszej kolumny tabeli zrodlowej
cursor first_col_data_header is
       select v_col_name from table_source;



begin

test := 'true';
v_nazwa_kamp := 'transpose_table_row2column';
v_czas_start := sysdate;


-- sprawdzenie czy istnieje tabela zrodlowa
BEGIN
         EXECUTE IMMEDIATE 'SELECT count(*) FROM ' || table_source INTO cnt_4;
EXCEPTION
         WHEN TableDoesNotExist
         THEN
             test := 'false';
             err_code := SQLCODE;
             err_msg := substr(SQLERRM, 1, 2000);
             INSERT INTO log_errors (time_err, object_name, campaign_name, error_number, error_message)
             VALUES (sysdate, 'transpose_table_row2column', v_nazwa_kamp, err_code, err_msg);
             COMMIT;
         
         WHEN NO_DATA_FOUND
         THEN
             test := 'false';
             err_code := SQLCODE;
             err_msg := substr(SQLERRM, 1, 2000);
             INSERT INTO log_errors (time_err, object_name, campaign_name, error_number, error_message)
             VALUES (sysdate, 'transpose_table_row2column', v_nazwa_kamp, err_code, err_msg);
             COMMIT;
             
         WHEN OTHERS
         THEN
             test := 'false';
             err_code := SQLCODE;
             err_msg := substr(SQLERRM, 1, 2000);
             INSERT INTO log_errors (time_err, object_name, campaign_name, error_number, error_message)
             VALUES (sysdate, 'transpose_table_row2column', v_nazwa_kamp, err_code, err_msg);
             COMMIT;
END;



-- jesli istnieje tabela zrodlowa to przetwarzamy
if test = 'true' then 



-- pobieram nazwe pierwszej kolumny tabeli zrodlowej
for v_first_column in first_column
loop
  v_col_name := v_first_column.column_name;
end loop;


-- sprawdzenie czy istnieje tabela docelowa, jesli tak to trzeba usunac
select count(*) into cnt_1 from user_tables t
where t.table_name = upper(table_result);

-- jesli istnieje tabela docelowa to usuwamy
if cnt_1 > 0 then
   cmd_1_drop := 'DROP TABLE ' || table_result;
   execute immediate cmd_1_drop;
end if;



-- pobranie liczby wierszy tabeli zrodlowej - nalezy stworzyc tyle samo kolumn w tabeli docelowej
-- ponizej sprawdzenie czy w pierwszej kolumnie tabeli zrodlowej sa unikalne wartosci - jesli nie to nie mozna 
-- transponowac tabeli poniewaz musi ona miec te wartosci jako naglowki nowej tabeli i musza wystepowac one tylko 1 raz
execute immediate 'select count(' || v_col_name || ') from ' || table_source into cnt_2; 
execute immediate 'select count(distinct ' || v_col_name || ') from ' || table_source into cnt_3; 


-- jesli wartosci w 1 kolumnie sa unikalne to przetwarzamy dalej
if cnt_2 = cnt_3 then



-- tutaj rozpoczynamy odczytywanie tabeli zrodlowej i tworzenie nowej przetransponowanej tabeli

for v_first_col_data_header in first_col_data_header
loop
  DBMS_OUTPUT.PUT_LINE(': ' || v_first_col_data_header.v_col_name);
end loop;








v_czas_stop:= sysdate;

insert into log_campaigns (campaign_name, time_start, time_stop, records_count, time_diff_min)
values (v_nazwa_kamp, v_czas_start, v_czas_stop, cnt_2, round((v_czas_stop - v_czas_start) * 24 * 60, 2));
commit;


end if;
end if;


EXCEPTION
       WHEN OTHERS THEN
          err_code := SQLCODE;
          err_msg := substr(SQLERRM, 1, 2000);

          INSERT INTO log_errors (time_err, object_name, campaign_name, error_number, error_message)
          VALUES (sysdate, 'transpose_table_row2column', v_nazwa_kamp, err_code, err_msg);
          COMMIT;

end transpose_table_row2column;
and I don't know how to create the slider:
cursor first_col_data_header is
       select v_col_name from table_source;
I have error this table does not exist
because table_name is the name of the parameter and v_col_name is variable which I initialize later in the code:
for v_first_column in first_column
loop
  v_col_name := v_first_column.column_name;
end loop;
Thanks for help

Here is the code you are looking for:

create or replace procedure transpose_table_row2column (table_source IN VARCHAR2, table_result IN VARCHAR2) is

-set serveroutput on;

v_nazwa_kamp varchar2 (100);
date of v_czas_start;
date of v_czas_stop;
err_code varchar2 (50);
err_msg varchar2 (2000);

cmd_1_drop varchar2 (50);
cnt_1 pls_integer;
cnt_2 pls_integer;
cnt_3 pls_integer;
cnt_4 pls_integer;
v_col_name varchar2 (50);
test varchar2 (5);

-deklaracja wyjatku dla nieistniejacej lub niedostepnej tabeli
TableDoesNotExist EXCEPTION;
PRAGMA EXCEPTION_INIT (TableDoesNotExist,-942);

-name pierwszej kolumny tabeli zrodlowej
l_first_column varchar2 (32767): = 'SELECT column_name FROM USER_TAB_COLUMNS WHERE TABLE_NAME = upper(:table_source) and column_id = 1';

-z pierwszej kolumny tabeli zrodlowej wartosci
l_first_col_data_header varchar2 (32767).
first_col_data_header sys_refcursor;
l_first_col_data varchar2 (32767).

Start

test: = "true";
v_nazwa_kamp: = 'transpose_table_row2column ';
v_czas_start: = sysdate;

-sprawdzenie czy istnieje image zrodlowa
BEGIN
EXECUTE IMMEDIATE ' SELECT count (*) FROM "| table_source INTO cnt_4;
EXCEPTION
WHEN TableDoesNotExist
THEN
test: = "false";
err_code: = SQLCODE;
err_msg: = substr (SQLERRM, 1, 2000);
INSERT INTO log_errors (campaign_name, time_err, object_name, error_message, error_number)
VALUES (sysdate, 'transpose_table_row2column', v_nazwa_kamp, err_code, err_msg);
COMMIT;

WHEN NO_DATA_FOUND
THEN
test: = "false";
err_code: = SQLCODE;
err_msg: = substr (SQLERRM, 1, 2000);
INSERT INTO log_errors (campaign_name, time_err, object_name, error_message, error_number)
VALUES (sysdate, 'transpose_table_row2column', v_nazwa_kamp, err_code, err_msg);
COMMIT;

WHILE OTHERS
THEN
test: = "false";
err_code: = SQLCODE;
err_msg: = substr (SQLERRM, 1, 2000);
INSERT INTO log_errors (campaign_name, time_err, object_name, error_message, error_number)
VALUES (sysdate, 'transpose_table_row2column', v_nazwa_kamp, err_code, err_msg);
COMMIT;

END;

-jesli istnieje image zrodlowa at przetwarzamy
If test = "true", then

-pobieram nazwe pierwszej kolumny tabeli zrodlowej
run immediately l_first_column in v_col_name using table_source;

-sprawdzenie czy istnieje image docelowa, tak jesli to trzeba usunac
Select count (*) in the user_tables cnt_1 t
where t.table_name = upper (table_result);

-jesli istnieje image docelowa at usuwamy
If cnt_1 > 0 then
cmd_1_drop: = 'DROP TABLE ' | table_result;
immediately run cmd_1_drop;
end if;

-pobranie liczby wierszy tabeli zrodlowej - nalezy stworzyc tyle samo kolumn tabeli w docelowej
-czy sprawdzenie ponizej w pierwszej kolumnie zrodlowej his unikalne wartosci tabeli - jesli nie to nie mozna
-transponowac tabeli poniewaz musi ona IMCs you wartosci tabeli nowej naglowki jako I musza wystepowac a tylko 1 raz
run immediately "select count (' |)" v_col_name | ') de ' || table_source in cnt_2;
run immediately "select count (distinct ' |)" v_col_name | ') de ' || table_source in cnt_3;

-jesli wartosci w 1 kolumnie his unikalne to przetwarzamy dalej
If cnt_2 = cnt_3 then

-tutaj rozpoczynamy tabeli zrodlowej odczytywanie I create nowej przetransponowanej tabeli
l_first_col_data_header: = 'choose ' | v_col_name | 'from ' | table_source;
Open the first_col_data_header for l_first_col_data_header;
loop
extract the first_col_data_header in l_first_col_data;
When the output first_col_data_header % notfound;
DBMS_OUTPUT. Put_line (': ' | l_first_col_data);
end loop;

v_czas_stop: = sysdate;

insert into log_campaigns (campaign_name time_start time_stop, records_count, time_diff_min)
values (v_nazwa_kamp, v_czas_start, v_czas_stop, cnt_2, round ((v_czas_stop-v_czas_start) * 24 * 60, 2));
commit;

end if;
end if;

EXCEPTION
WHILE OTHERS THEN
err_code: = SQLCODE;
err_msg: = substr (SQLERRM, 1, 2000);

INSERT INTO log_errors (campaign_name, time_err, object_name, error_message, error_number)

VALUES (sysdate, 'transpose_table_row2column', v_nazwa_kamp, err_code, err_msg);
COMMIT;

end transpose_table_row2column;

Tags: Database

Similar Questions

  • How to put two images in an image on the windows photo gallery

    I need to know how to put two images in an image on the windows photo gallery.

    I need to know how to put two images in an image on the windows photo gallery.

    =================================
    If you say you want to join two images
    edge to edge that's easy to do with the free-
    Ware IrfanView.

    (FWIW... it's always a good idea to create a system)
    Restore point before installing software or updates)

    IrfanView and IrfanView plugins
    http://www.download.HR/download-IrfanView.html

    Once you have downloaded IrfanView and
    installed... Open the program and go to...

    ... Image / create the Image of the Panorama...

    Make your choice and click on the button create an Image.

    When you see the combined images displayed
    in the display... go to... File / save as...

    Choose a location...

    Choose a format...

    Give the file a new name...

    Click on... Save...

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

  • How to create a table in a schema in the SOA database

    Hello

    can you please guide me how to create a table looks under custom schema available in the SOA database

    Thank you

    Valsaint

    Hello

    1. use JDeveloper to connect to your schema custom: view > Database > Database Navigator > new connection

    2. set the mpdel of your table column names, types of data, constraints (primary key, not null, foreign key, etc..)

    3. use this simplified tutorial to create the table according to your model of table create statement - Oracle/PLSQL: CREATE TABLE statement

    4. execute the statement in the SQL of JDeveloper journal for the custom connection (point 1 above).

    Let me know if you need help!

    HTH,

    A.

  • How to create a table with no lines to the left or to the right?

    If I create a table with say 5 columns and 15 lines, how not to do a vertical line (border) to the left and to the right of the table while keeping the boundary up and down? Is that possible or I just put a white box on the left and the right?

    IDCS3

    There are a few methods that work. Here is one.

    (1) select your table cells

    (2) open the race Panel

    3) click the blue lines of the proxy image in the Panel of stoke to deselect the lines inside and high and low lines

    (4) 0 the value of the weight of the race (or change the color of the None swatch)

    Oh and for the love of your fellow designers or the person that allows you to edit your work in the future... do NOT use a white box to hide the traits of lines and columns in the table.

    HTH

    -mt

  • What can I and how I, put firefox on a stick, then I can travel with my TI and my favorites

    What can I and how I, put firefox on a stick, then I can travel with it and my favorites

    Use the portable version of Firefox.
    See http://portableapps.com/apps/internet/browsers/portable_firefox

  • How can I stop DWCS4 insert style rules in the header?

    I would sometimes include inline style tags in my tag without DWCS4 automatically insert a rule .style1 in the header.  How can I change this in the preferences?

    There is no such preference - CS4 is now oriented toward writing validate code and put all styles, either at the head of the document or in an external style sheet.

    However, you can quickly easily create inline styles (tailored to creating electronic newsletters, for example).

    If you have a tag for a

    you want to add an inline style to:

    instead of view code the cursor just after that the '1' key, then press SPACEBAR and a small tag inspector will pop up - choose "style." and press ENTER.

    How you have a choice of style to the selection rules- like this:

    and now the code looks like this with the added inline style:

    If you want to add another style to the same element, once again, place the cursor just after the sem-colon, hit space bar the small pop-up window will reappear and you can choose another style rule to add.

    so you might end up with something like the following if repeat you the above steps a few times:

    You could even write the styles in by handcoding it in, instead of using the popup window if you are familiar with css  :-)

    Hope this helps.

    style=" "="">

  • How to redirect a page to a link in the header.

    Hi, I have a link in the Header.jsp to Contactus page. How do I access this page of header.jsp.

    Can someone help me on this please

    Tag render: pageUrl user
    http://download.Oracle.com/docs/CD/E13155_01/WLP/docs103/javadocjsp/framework/render/PageUrl.html
    I assume you mean you want to goto the page and not a "redirect".

  • Works with table as parameter name

    How to fix this feature

    Create or replace function f1 ( tab_name in varchar2 )
    return number
    as 
    num_of_row number;
    begin
    num_of_row := 'select count(*) from' || 'tab_name'';
    return num_of_row;
    end;
    
    
    create or replace function f1 ( tab_name in varchar2 )
    return number
    as
    num_of_row number;
    sqlstr varchar2(900);
    begin
    sqlstr :=  ' SELECT count(*) FROM '||  tab_name;
    execute Immediate sqlstr Into num_of_row;
    return num_of_row;
    end;
    

    I have it

  • Child panel - how to put it to a specific location in the Parent Panel

    Hello I have a program with main panel what other signs in the form of tabs.

    I need to put the child Panel on the tab panels.

    How can I do this and get a good view of the child Panel only

    on the right panel?

    I'm attaching an image to describe.

    Thank you for your comments

    Meir

    Hey Meir,

    It seems to me you're missinig a very basic concept on the tab control: each tab IS actually a child Panel! In other words, all of the controls that you have on your test panel can be simply loaded on the desired tab, leaving the other unchanged pages.

    You may be missing the scroll bar on the right, which actually isn't is not present on the controls tab, but as far as I can see your interface might be reduced to a single table control placed on a page of tabs with appropriate row headers and colunm.

    In all cases, if you do not strongly want to change your existing code you can use the command (InsertPanelAsTabPage) to add a panel you have previously loaded to the tab control: in this case a current scroll bar is maintained. Keep in mind that this statement actually makes a copy of the original Panel, you need to retrieve the handle of the appropriate tab of address on the page adding control. The original panel can be thrown immediately after it is added to the tab control.

  • How to make a table of contents to display the chapter number and chapter text together

    I'm working on 11 of FrameMaker. How can I get my Table of contents (TOC) to display the chapter number and chapter title on one line. My chapter titles have the chapter number and chapter title on two lines, two centered at the top of a new page. I wish that my OCD to pick the chapter number and chapter name on one line not two. Thank you.

    If you'v created the table of contents with activation of hyperlinks (default) setting, and then simply hold the CTRL + alt keys and click on empty entries in your TOC file. FM will open the file containing the entrry and jump to the correct section.

  • How to put 2 different forms of wave with the timestamp on a chart

    Hello

    I'm putting the 2 waveforms with different stamps on the same chart.

    I'm able to do that if I post my data in my chart once.

    When I write to my chart several times, the new data replaces old data, instead of concatenation to the old data.

    See the vi attached for what I'm trying to do.

    Can anyone suggest how to do this correctly?

    Thank you.

    -Matt

    It works.  It's your data.  Put a longer wait statement in the loop and watch.

    You create 1/10 seconds of data in each simulated waveform.  You have a millisecond 33 wait between your 2 simulations.  The loop For will run super fast with only this 33 msec waiting that is less than 1/10th of a second.  Then of course some data will overwrite old data.

    Change your Simulations for "Simulate Acquisition Timing" rather than "Run as fast as Possible" which will slow down the loop and make it more realistic timetable.

  • How to put clips in order by number in the list? Open the Prime Minister and they were reversed!

    I imported a large number of clips in numerical order from lowest to highest.  Today when I opened the first the order was reversed in the list view of the highest to the lowest number. I do not know why. I didn't change anything. He did this to all my other tanks too!

    When I Watch clips in the icon view that they are in good condition!

    So now when I try to put on the timeline it up my latest music video first. Is there an easy way to reverse the order in the list view to the way in which I initially imported? I don't want to have to import all the clips.

    Thank you!!

    Have you tried clicking on the column header?

    (Open a folder and go under the headings at the top of the trash... click on the file name column header)

  • How access an item by using its name or id if this isn't a class variable?

    I'm recovering the item that I added to my user interface in a different function. I use actionscript 3. I know that I can put the variable in a class variable, so it can be access anywhere in the class, but I have too many items. Is there anyway that I could access it without putting them in the class variable?

    Thank you.

    public class Test extends SkinnableContainer{
    
    // private var image:Image; <-- I try not to do this, too messy
    
    private function func1() {
        var image:Image = new Image();
        addElement(image);
    }
    
    
    private function func2() {
        var image:Image = /* how to get the element from my UI without putting into class variable */
    }
    

    Of course, because you don't want to create in the first place of the variables

    But you could add one to a dictionary of class and get your references from there.

    Something like this:

    private var objArray:Dictionary = new Dictionary();
    private function init (): void
    {
    var image: Image = new Image();
    ObjArr ['image'] = addElement (image);
    trace (gridArray ['image']);
    }

  • How to put a WIFI-connect button directly on the home screen?

    Hi all

    I know there is a wifi - connect button in the notification Panel, but I have to turn on my screen, open the Control Panel, then click on the "quick settings" button, then click on the WiFi connect button... " 4 actions connect within my own wifi network!

    (Note that I don't want the automatic connection setting because I don't want to be connected to each time)

    I wish I had just a "wifi - connect ' on my screen which allow me to connect just by clicking this button."
    I can't find a widget or application in my phone to do this.

    Do you know how?

    Thank you very much
    Guy

    Hello

    The best thing would be to follow the advice of dandy63of s, by downloading a third-party application that can handle it. The closest you can get this as standard (without having to download any third-party application), would be to add a shortcut to settings > Wi - Fi. This can be if you long press on an empty space on your home screen > select Apps > shortcuts > settings > Wi - Fi.

  • How to put a file jpg or png as the background of a page

    I tried to use ImagePaintDefinition to set the background of a container and added that the container on the page. But does not work. It must also have dimension photo as a power of 2. Is there some way I can put guess 768 X 1280 image dimensions as my background? Thank you.

    It seems that there is nothing in the container and because you have not set a width and a height, the size of the container is equal to zero.

Maybe you are looking for