Table name input. and output i need all rows and columns using procedures
hi,
question: table name input. and output i need all rows and columns by using procedures.
thanks,
To All
An example of using DBMS_SQL package to execute dynamic SQL (in this case to generate CSV data in a file)...
As sys user:
CREATE OR REPLACE DIRECTORY TEST_DIR AS '\tmp\myfiles'
GRANT READ, WRITE ON DIRECTORY TEST_DIR TO myuser
/As myuser:
CREATE OR REPLACE PROCEDURE run_query(p_sql IN VARCHAR2
,p_dir IN VARCHAR2
,p_header_file IN VARCHAR2
,p_data_file IN VARCHAR2 := NULL) IS
v_finaltxt VARCHAR2(4000);
v_v_val VARCHAR2(4000);
v_n_val NUMBER;
v_d_val DATE;
v_ret NUMBER;
c NUMBER;
d NUMBER;
col_cnt INTEGER;
f BOOLEAN;
rec_tab DBMS_SQL.DESC_TAB;
col_num NUMBER;
v_fh UTL_FILE.FILE_TYPE;
v_samefile BOOLEAN := (NVL(p_data_file,p_header_file) = p_header_file);
BEGIN
c := DBMS_SQL.OPEN_CURSOR;
DBMS_SQL.PARSE(c, p_sql, DBMS_SQL.NATIVE);
d := DBMS_SQL.EXECUTE(c);
DBMS_SQL.DESCRIBE_COLUMNS(c, col_cnt, rec_tab);
FOR j in 1..col_cnt
LOOP
CASE rec_tab(j).col_type
WHEN 1 THEN DBMS_SQL.DEFINE_COLUMN(c,j,v_v_val,2000);
WHEN 2 THEN DBMS_SQL.DEFINE_COLUMN(c,j,v_n_val);
WHEN 12 THEN DBMS_SQL.DEFINE_COLUMN(c,j,v_d_val);
ELSE
DBMS_SQL.DEFINE_COLUMN(c,j,v_v_val,2000);
END CASE;
END LOOP;
-- This part outputs the HEADER
v_fh := UTL_FILE.FOPEN(upper(p_dir),p_header_file,'w',32767);
FOR j in 1..col_cnt
LOOP
v_finaltxt := ltrim(v_finaltxt||','||lower(rec_tab(j).col_name),',');
END LOOP;
-- DBMS_OUTPUT.PUT_LINE(v_finaltxt);
UTL_FILE.PUT_LINE(v_fh, v_finaltxt);
IF NOT v_samefile THEN
UTL_FILE.FCLOSE(v_fh);
END IF;
-- This part outputs the DATA
IF NOT v_samefile THEN
v_fh := UTL_FILE.FOPEN(upper(p_dir),p_data_file,'w',32767);
END IF;
LOOP
v_ret := DBMS_SQL.FETCH_ROWS(c);
EXIT WHEN v_ret = 0;
v_finaltxt := NULL;
FOR j in 1..col_cnt
LOOP
CASE rec_tab(j).col_type
WHEN 1 THEN DBMS_SQL.COLUMN_VALUE(c,j,v_v_val);
v_finaltxt := ltrim(v_finaltxt||',"'||v_v_val||'"',',');
WHEN 2 THEN DBMS_SQL.COLUMN_VALUE(c,j,v_n_val);
v_finaltxt := ltrim(v_finaltxt||','||v_n_val,',');
WHEN 12 THEN DBMS_SQL.COLUMN_VALUE(c,j,v_d_val);
v_finaltxt := ltrim(v_finaltxt||','||to_char(v_d_val,'DD/MM/YYYY HH24:MI:SS'),',');
ELSE
v_finaltxt := ltrim(v_finaltxt||',"'||v_v_val||'"',',');
END CASE;
END LOOP;
-- DBMS_OUTPUT.PUT_LINE(v_finaltxt);
UTL_FILE.PUT_LINE(v_fh, v_finaltxt);
END LOOP;
UTL_FILE.FCLOSE(v_fh);
DBMS_SQL.CLOSE_CURSOR(c);
END;This allows for the header row and the data to be written to seperate files if required.
e.g.
SQL> exec run_query('select * from emp','TEST_DIR','output.txt');
PL/SQL procedure successfully completed.Output.txt file contains:
empno,ename,job,mgr,hiredate,sal,comm,deptno
7369,"SMITH","CLERK",7902,17/12/1980 00:00:00,800,,20
7499,"ALLEN","SALESMAN",7698,20/02/1981 00:00:00,1600,300,30
7521,"WARD","SALESMAN",7698,22/02/1981 00:00:00,1250,500,30
7566,"JONES","MANAGER",7839,02/04/1981 00:00:00,2975,,20
7654,"MARTIN","SALESMAN",7698,28/09/1981 00:00:00,1250,1400,30
7698,"BLAKE","MANAGER",7839,01/05/1981 00:00:00,2850,,30
7782,"CLARK","MANAGER",7839,09/06/1981 00:00:00,2450,,10
7788,"SCOTT","ANALYST",7566,19/04/1987 00:00:00,3000,,20
7839,"KING","PRESIDENT",,17/11/1981 00:00:00,5000,,10
7844,"TURNER","SALESMAN",7698,08/09/1981 00:00:00,1500,0,30
7876,"ADAMS","CLERK",7788,23/05/1987 00:00:00,1100,,20
7900,"JAMES","CLERK",7698,03/12/1981 00:00:00,950,,30
7902,"FORD","ANALYST",7566,03/12/1981 00:00:00,3000,,20
7934,"MILLER","CLERK",7782,23/01/1982 00:00:00,1300,,10The procedure allows for the header and data to go to seperate files if required. Just specifying the "header" filename will put the header and data in the one file.
Adapt to output different datatypes and styles are required.
Similar Messages
-
I had to get a new i phone and I backed up all contacts and photos to i cloud and now I can't get them back onto my new iphone. Any advice?
EVerything you need to know is here http://support.apple.com/kb/HT4859
-
I have been attempting to wipe/erase the iphone 4S I recently purchased...for the past 20 hours....I went to Reset in Settings and clicked on "Erase All Content and Settings"....At that point the phone the screen went dark except for a white circular symbol revolving - indicating something should be happening....
The instructions indicated that, depending on what needed to be erased, the process could take several hours. Even though the device had a Tom Tom application with all the maps of Europe etc (about 2GB) and there were several other apps on the device, it does not seem to me normal that the device would be still clearing into the next day - today!
Can you please help!?
Richard W.Something has gone wrong. Turn your phone off, then force it into recovery mode & restore it:
Press the Sleep/Wake button & Home button at the same time, keep pressing until your phone turns off, then release.
Leave the USB cable connected to your computer, but NOT your phone, iTunes running, press & hold the home button while connecting the USB cable to your dock connector, continue holding the home button until you see “Connect to iTunes” on the screen. You may now release the home button. iTunes should now display that it has detected your phone in recovery mode, if not quit and reopen iTunes. If you still don’t see the recovery message repeat these steps again. iTunes will give you the option to restore from a backup or set up as new.
Make sure you have no anti-virus software running or any firewalls...turn all of that stuff off. -
If my iphone, ipad, MAC and macbook pro are all linked, and then I upgrade only my ipone to IOS 7.0, does that have an effect on the linking to my other MAC products. It seems my calendar has lost a lot of information since the upgrade.
If you purchased Lion for your iMac, just log into the Mac App Store from your MacBook using the Apple ID under which you purchased Lion and go to the Purchases page. You will be able to download and install Lion there.
searching the internet i found a link to upgrtade to 10.7
The only place you get get Lion is from the Mac App Store. If you found some other site, that was an illegal copy and almost certainly tied to someone else's Apple ID and hence unusable by you. If the link was just to the Mac App Store, see above.
As to the problem with synchronization to iCloud, that's not a 10.6 question, so I'd suggest you take up that specific issue in either the Lion or iCloud forums, providing full details, and someone there can probably help you sort things out.
Regards. -
I am new to apple, i have an itunes account and want to start collecting music ect. i also have an ipod and i have erased all content and i have a picture of a power lead entering a itunes logo?
Connect the iPod to your computer and restore via iTunes
iTunes: Restoring iOS software -
I am using iPhone 5 and tried to Erase All Contents and Settings but it is just showing an apple sign on the screen and nothing is happening now for about 3 days now. All it does is eat up my battery and still show apple sign after charging! Help!!!!
Hi DaVince Vince,
I'm sorry to hear that you are having issues with your iPhone. I also apologize, I'm a bit unclear what issues you were having that led up to the attempted Erase All, and/or exactly what behavior you are seeing now (restarting, not responding at all, etc). If you are seeing an Apple Logo screen and your iPhone does not appear to be starting correctly, you may find the following articles helpful:
If your iOS device restarts, displays the Apple logo, or powers off while you're using it - Apple Support
If your iPhone, iPad, or iPod touch doesn't respond or doesn't turn on - Apple Support
Regards,
- Brenden -
i have a iphone 3gs and recently I Erase All Contents and Settings, now my phone is asking me to update to itunes but when I do it comes up with the message...error 10.15, can someone please help?
Your headline says iPhone 3GS, but your text says 3G.
iPhone 3G is not compatible with iOS5. 3GS is. -
My iphone4 has been stuck on the connect to itunes logo for a few hours. I connected it to itunes and it says that the iphone is on recovery mode and that I need to restore it to use it with itunes. I'm afraid that if I restore it I will loose everything help please!!
AT this point whatever data you have on yoru phone is already gone since it is in recovery mode.
However you can restore from your backup, when your phone reboots from recovery.
YOu do have a backup right? -
My iCloud on my phone is under another persons account I however am no longer with them and want to cut all ties and is there any way for me to change my iCloud account or will it affect my phone? And it's photos, apps, music?
You have to delete the iCloud account but you can keep all your data such as Contacts, Calendars etc. when you delete the account you will prompted to "Keep on my iPhone".
All your purchased content (like apps and music from iTunes Store) belongs to the original ID and you have to re-Purchase them under your Apple ID.
Photos in Camera Roll remains in Camera Roll.
Photos in photo stream that are not in Camera Roll must be saved in Camera Roll.
Photo that previously synced from iTunes remains in photo library until you synced with another iTunes library (another computer).
Also sign out from iMessages, FaceTime and Home sharing (Settings>Music) -
How can we connect mac air and iPad to share all documents and downloads
How can we connect mac air and iPad to share all documents and downloads?
If you are referring to the "Documents" and "Downloads" folder in OSX, I suggest using https://www.dropbox.com
-
Can we produce a newsletter in one CS4 application and output it to both print and the web?
Can we produce a newsletter in one CS4 application and output it to both print and the web?
If so what do you suggest that we use?
Message was edited by: [email protected]A very cautious "yes". It mainly depends on what you expect.
It has always been possible to just export to PDF and post that on your site. You can also export your ID file as one comprehensive SWF file and immediately put that onto the site -- it comes with a few handy browse functions, snazzy page flipping (when required); and it looks exactly like your ID document.
Hard-core techies can use the Export To XHTML/DreamWeaver function, but that will only export the very bare bones -- plain text, with just the commands for text formatting in place. You have to re-do layout and styling in HTML code. Bear in mind ID is designed, top to bottom, as a document layout program, and this export is "extra", not really a basic feature. -
Updated to ios 5 and itunes 10.5 for my iphone and now i lost all apps and songs that i had downloaded in the past. how do i get everything back?
in order to restore your songs and apps, you should just reconnect to itunes and sync your data. your phone ran a backup before it upgraded, and you can also do a restore. but the key is still to go to your itunes and sync back to your phone what you wanted there in the first place.
-
My grandson played with my 4th generation iPod touch and the phone icon and contacts icon are gone. I have gone to settings and done the "reset all settings" and "reset home screen layout" with no success. I also did a hard reset. No luck. I can get to my apps through the search screen but no icons.Help?
Try doing a Spotlight search for the Contacts app.
Read this for doing a search:
https://sites.google.com/site/appleclubfhs/support/advice-and-articles/spotlight -search/
(Skip to the section for Spotlight on iOS)
(Note that my links to other pages may promote my organization, and this should not be taken as an endorsement by Apple) -
HT4858 my iphone 4 is lost and i wanna earse all msgs and everything on it what should i do?
my iphone 4 is lost and i wanna earse all msgs and everything on it what
If you enabled Find My iPhone you may be able to erase it as explained here: http://help.apple.com/icloud/#/mmfc0ef36f. Be sure you want to do this because it can't be cancelled once you do, and you will no longer be able to locate it.
-
i am trying to download normal applications on my iphone 2g and i really need to update and it is frustrating please i need help
Help with what?
You did not ask a question.
The original iphone can go to 3.1.3
Maybe you are looking for
-
hi, i am trying to find out if i can stream music from my iphone4 via bluetooth to my car stereo or car speakers. the phone pairs up and works ok for calls
-
Calculated column in a pivot in obiee 10g
Hello all , Please share your thoughts on the below requirement : I have 3 measure columns in a pivot table (in measures)- A,B,C . against region dimension (in rows) and one month dimension (in measure lable ). the data's are populating as below : ..
-
How can I view music video that I purchased on my Music App on my iPad?? I can view video in question on my iPhone!! On my iPad it simply plays the song when selected.
-
[Solved] Latest GTK2 [2.20.1-1] package breaks gtk apps
Hey guys, I just did a pacman -Syu for the latest set of updates, and discovered immediately that both firefox and chromium (not sure of other apps though I suspect so) crash. After rolling back to 2.20.0-2 my system began to work again without furth
-
Parsing Log file with PowerShell
Hey Guys, I have the following line in a txt file (log file) 2012-08-14 18:00:00 [ERROR] . Exception SQL error 1 2012-08-14 18:10:00 [ERROR] . Exception SQL error 22012-08-15 18:00:00 [INFO] . Started - Check the most recent entry(s) the last 24 ho