1600 PMP mock questions 1400 CAPM mock questions 800 SCJP 6 mock questions 600 OCAJP 7 mock questions 590 OCPJP 7 mock questions 556 SCWCD 5 mock questions 500 OCEJWCD 6 mock questions pdfDownload (java,struts, hibernet etc)

ORACLE Tutorials

Generates the .csv file for the table along with column headings

CREATE OR REPLACE VIEW vu1
AS
SELECT 'x' aliascol
FROM DUAL;
/

CREATE OR REPLACE PROCEDURE create_csv (
tname IN VARCHAR2,
fname IN VARCHAR2,
PATH IN VARCHAR2
)
IS
fileid UTL_FILE.file_type;
concat_col VARCHAR2 (2000);
dupe_concat_col VARCHAR2 (2000);
select_stmt VARCHAR2 (2000);
cursor_id NUMBER;
exec_cur NUMBER;
BEGIN
fileid := UTL_FILE.fopen (PATH, fname || '.csv', 'W');

FOR j IN (SELECT column_name
FROM user_tab_columns
WHERE table_name = UPPER (tname)
ORDER BY column_id DESC)
LOOP
concat_col := j.column_name || '||'',''||' || concat_col;
dupe_concat_col := j.column_name || ',' || dupe_concat_col;
select_stmt :=
'select '
|| SUBSTR (concat_col, 1, LENGTH (concat_col) - 7)
|| ' aliascol from '
|| tname;
END LOOP;

DBMS_OUTPUT.put_line (select_stmt);

EXECUTE IMMEDIATE ('CREATE OR REPLACE VIEW VU1 AS ' || select_stmt);

UTL_FILE.put_line (fileid, dupe_concat_col);

FOR i IN (SELECT aliascol
FROM vu1)
LOOP
UTL_FILE.put_line (fileid, TO_CHAR (i.aliascol));
END LOOP;

UTL_FILE.fclose (fileid);
EXCEPTION
WHEN UTL_FILE.invalid_mode
THEN
DBMS_OUTPUT.put_line (SQLERRM || ' occured');
WHEN UTL_FILE.invalid_operation
THEN
DBMS_OUTPUT.put_line (SQLERRM || ' occured');
WHEN UTL_FILE.invalid_path
THEN
DBMS_OUTPUT.put_line (SQLERRM || ' occured');
WHEN UTL_FILE.invalid_maxlinesize
THEN
DBMS_OUTPUT.put_line (SQLERRM || ' occured');
END;
/

Reviews and Comments


PMP, CAPM, PMI is a registered certification mark of the Project Management Institute, Inc

Copyright © www.techfaq360.com 2016


About US | Contact US | Privacy Policy | Terms and Conditions  | Website disclaimer  | Cancellation and Refund Policy  | Shipping & Delivery Policy