Home » RDBMS Server » Server Administration » procedure creates the insert statement
procedure creates the insert statement [message #372841] Tue, 13 March 2001 07:58 Go to next message
rakesh
Messages: 25
Registered: March 2001
Junior Member
Hello Sir

How R u I am Fine With My Health and Grat Oracle DBA Job i need Help From U sir I want Script From U

That Is procedure Take value user(table name ) that is i have some tables ok tables have rows ok , i want out put from the that procedure is if the table have the 100 rows ok that should create or out put should be 100 insert statement all actual values from what table name i have submitted so i want script because our clients dont knows the sql loader and exp imp utilities they are technically not that much sound so i will spool the whatever out from this script i will send them they can run this script ok and another thing is condition is the we have to avoid bad characters like &, ' etc single code and ampersant and pls send script to me i am tryinfg here

Yours Site team Member

Rakesh
Oracle DBA
Re: procedure creates the insert statement [message #372847 is a reply to message #372841] Tue, 13 March 2001 11:30 Go to previous messageGo to next message
Andrew again...
Messages: 270
Registered: July 2000
Senior Member
Use TOAD, or see the following script...

As far as & is concerned, in SQLplus you need to "set scan off" to disable variable substitution.

PROCEDURE punloadrecord (
ppowner IN VARCHAR2,
pptablename IN VARCHAR2,
ppwhereclause IN VARCHAR2)
IS
/****************************************************************************
Author: Sean Cassidy (scassidy@ozemail.com.au) December 1999
Purpose: Unload a record to be a SQL INSERT Statement.
Primarily for one record but will handle if many.

Parameters
Name Details
---------------- ------------------------------------------------------------
ppOwner The Owner of the table.
ppTableName The Name of the Table from which the record is to be
Unloaded from
ppWhereClause A CLAUSE to identify the record. May select multiple records

NB: This Procedure is about as robust as those little sachets
of International Roast Coffee that you get in cheap hotel rooms
It will fall over for any number of reasons and does not handle LONG
****************************************************************************/
CURSOR ctablecolumns (cpowner VARCHAR2, cptablename VARCHAR2)
IS
SELECT atc.column_name, atc.data_type
FROM all_tab_columns atc, all_tables ats
WHERE
--== Join to All_Tables so we can't get views (Inserts would fail) ==--

atc.owner = UPPER (cpowner)
AND atc.owner = ats.owner
AND atc.table_name = ats.table_name
AND ats.table_name = UPPER (cptablename)
AND atc.data_type IN ('DATE', 'NUMBER', 'VARCHAR2');
rtablecolumns ctablecolumns%ROWTYPE;
--
TYPE ttctable IS TABLE OF ctablecolumns%ROWTYPE
INDEX BY BINARY_INTEGER;
TYPE tcursortable IS TABLE OF INTEGER
INDEX BY BINARY_INTEGER;
TYPE tvaltable IS TABLE OF VARCHAR2(2000)
INDEX BY BINARY_INTEGER;
lvcursortable tcursortable;
lvtctable ttctable;
lvvaluetable tvaltable;
lvselectioncursor INTEGER;
lvselectstatement VARCHAR2(2000);
lvcolumnlist VARCHAR2(2000);
i BINARY_INTEGER := 0;
lvnumcolumns NUMBER := 0;
lvcurrentrow ROWID;
lvignore NUMBER;
lvcurrentvalue VARCHAR2(2000);
BEGIN -- pUnloadRecord;
--== Fetch our columns into a pl/sql table ==--
FOR rtablecolumns IN ctablecolumns (ppowner, pptablename)
LOOP
i := i + 1;
lvtctable (i) := rtablecolumns;
END LOOP;
lvnumcolumns := i;
<<columnlist_loop>>
FOR i IN 1 .. lvnumcolumns
LOOP
-- Add each column name to a list
IF lvcolumnlist IS NULL
THEN
lvcolumnlist := lvtctable (i).column_name;
ELSE
lvcolumnlist := lvcolumnlist || ','|| lvtctable (i).column_name;
END IF; -- ColumnList is NULL
IF lvtctable (i).data_type = 'DATE'
THEN
--== All the quotes are so our strings have enough in the end ==--
lvselectstatement :=
'SELECT ''to_date(''''''||to_char('||
lvtctable (i).column_name ||
', ''yyyymmddhh24miss'')||
'''''', ''''yyyymmddhh24miss'''')'' FROM '||
pptablename ||
' WHERE rowid = :x';
ELSIF lvtctable (i).data_type = 'NUMBER'
THEN
lvselectstatement :=
'SELECT to_char('||
lvtctable (i).column_name ||
')'||
' FROM '||
pptablename ||
' WHERE rowid = :x';
ELSIF lvtctable (i).data_type = 'VARCHAR2'
THEN
lvselectstatement :=
'SELECT ''''''''||'||
lvtctable (i).column_name ||
'||'''''''' FROM '||
pptablename ||
' WHERE rowid = :x';
END IF; -- Data type
lvcursortable (i) := DBMS_SQL.open_cursor;
DBMS_SQL.parse (lvcursortable (i), lvselectstatement, DBMS_SQL.native);
END LOOP column_list_loop;
--===--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--
--== Because DBMS_SQL requires us to call define_column for each ==--
--== column, we cannot have dynamic number of columns fetched ==--
--== Instead, we need to fetch each column seperately... Bugger! ==--
--===--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--
lvselectstatement :=
'SELECT rowid'|| ' FROM '|| pptablename || ' WHERE '|| ppwhereclause;
lvselectioncursor := DBMS_SQL.open_cursor;
DBMS_SQL.parse (lvselectioncursor, lvselectstatement, DBMS_SQL.native);
DBMS_SQL.define_column_rowid (lvselectioncursor, 1, lvcurrentrow);
lvignore := DBMS_SQL.execute (lvselectioncursor);
<<fetch_rows_loop>>
LOOP
IF DBMS_SQL.fetch_rows (lvselectioncursor) > 0
THEN
DBMS_SQL.column_value (lvselectioncursor, 1, lvcurrentrow);
<<column_loop>>
FOR i IN 1 .. lvnumcolumns
LOOP
DBMS_SQL.define_column (lvcursortable (i), 1, lvcurrentvalue, 2000);
DBMS_SQL.bind_variable (lvcursortable (i), 'x', lvcurrentrow);
lvignore := DBMS_SQL.execute (lvcursortable (i));
IF DBMS_SQL.fetch_rows (lvcursortable (i)) > 0
THEN
DBMS_SQL.column_value (lvcursortable (i), 1, lvcurrentvalue);
ELSE
lvcurrentvalue := NULL;
END IF;
IF lvcurrentvalue IS NULL
THEN
lvcurrentvalue := 'NULL';
END IF;
lvvaluetable (i) := lvcurrentvalue;
END LOOP column_loop;
--== Output this row ==--
DBMS_OUTPUT.put_line (
'INSERT INTO '|| ppowner || '.'|| pptablename || '('
);
pprintcolumnlist (lvcolumnlist);
DBMS_OUTPUT.put_line (') VALUES (');
<<output_values>>
FOR i IN 1 .. lvnumcolumns
LOOP
IF i > 1
THEN
DBMS_OUTPUT.put (',');
END IF;
pprintstring (lvvaluetable (i));
END LOOP output_values;
DBMS_OUTPUT.put_line (')');
DBMS_OUTPUT.put_line ('/');
ELSE
EXIT fetch_rows_loop;
END IF; -- fetch > 0
END LOOP fetch_rows_loop;
--== Close all the cursors ==--
<<column_cursor_loop>>
FOR i IN 1 .. lvnumcolumns
LOOP
DBMS_SQL.close_cursor (lvcursortable (i));
END LOOP column_cursor_loop;
DBMS_SQL.close_cursor (lvselectioncursor);
END punloadrecord;
/
Re: procedure creates the insert statement [message #372849 is a reply to message #372841] Tue, 13 March 2001 22:50 Go to previous messageGo to next message
Balamurugan.R
Messages: 91
Registered: March 2001
Member
Hai rakesh,

Sorry I couldn't understand your question.
Could you explain in detail with example.
Re: procedure creates the insert statement [message #372864 is a reply to message #372841] Wed, 14 March 2001 15:08 Go to previous messageGo to next message
Salman Khan
Messages: 51
Registered: September 2000
Member
Rakesh ok, Abay who hired you as a DBA.
ok and ok Gadha kahi kaa.
Re: procedure creates the insert statement [message #373015 is a reply to message #372841] Thu, 22 March 2001 12:00 Go to previous messageGo to next message
aish
Messages: 44
Registered: March 2001
Member
Hey What is this .Could you explain what are you trying to do?
Re: procedure creates the insert statement [message #373017 is a reply to message #372864] Thu, 22 March 2001 13:17 Go to previous messageGo to next message
Samreen Surayya
Messages: 3
Registered: March 2001
Junior Member
Hey Salman Khan,

Please why are you using foul language
in normal conversation. Please realize the Critical importance of communicating with others.
May be he is not able to explain the things more clearly that could happen with anyone.Every one need not be in the same boat as you are.

Thanks,
Samreen .
Re: procedure creates the insert statement [message #373018 is a reply to message #372864] Thu, 22 March 2001 13:17 Go to previous messageGo to next message
Samreen Surayya
Messages: 3
Registered: March 2001
Junior Member
Hey Salman Khan,

Please why are you using foul language
in normal conversation. Please realize the Critical importance of communicating with others.
May be he is not able to explain the things more clearly that could happen with anyone.Every one need not be in the same boat as you are.

Thanks,
Samreen .
Re: procedure creates the insert statement [message #373019 is a reply to message #372864] Thu, 22 March 2001 13:17 Go to previous messageGo to next message
Samreen Surayya
Messages: 3
Registered: March 2001
Junior Member
Hey Salman Khan,

Please why are you using foul language
in normal conversation. Please realize the Critical importance of communicating with others.
May be he is not able to explain the things more clearly that could happen with anyone.Every one need not be in the same boat as you are.

Thanks,
Samreen .
Re: procedure creates the insert statement [message #373049 is a reply to message #372864] Fri, 23 March 2001 14:20 Go to previous messageGo to next message
Salman Khan
Messages: 51
Registered: September 2000
Member
Hey Samreen Surraya,

What are you talking about? I dont remeber when i used fool language.

By the way where you from?
Re: procedure creates the insert statement [message #373072 is a reply to message #372864] Mon, 26 March 2001 10:09 Go to previous messageGo to next message
samreen
Messages: 2
Registered: March 2001
Junior Member
Hi,

I am from Hyd.How about you.
Re: procedure creates the insert statement [message #373073 is a reply to message #373049] Mon, 26 March 2001 10:12 Go to previous messageGo to next message
surayya
Messages: 8
Registered: March 2001
Junior Member
come on you used Gadha word to someone you don't know

Samreen
Re: procedure creates the insert statement [message #373074 is a reply to message #373049] Mon, 26 March 2001 10:13 Go to previous messageGo to next message
surayya
Messages: 8
Registered: March 2001
Junior Member
come on you used "Gadha" word to someone you don't know

Samreen
Re: procedure creates the insert statement [message #373075 is a reply to message #372864] Mon, 26 March 2001 10:14 Go to previous messageGo to next message
surayya
Messages: 8
Registered: March 2001
Junior Member
Hi Salman ,
I am from Hyd.How about you.
Re: procedure creates the insert statement [message #373076 is a reply to message #372864] Mon, 26 March 2001 10:15 Go to previous messageGo to next message
surayya
Messages: 8
Registered: March 2001
Junior Member
Hi Salman ,
I am from Hyd.How about you.
Re: procedure creates the insert statement [message #373077 is a reply to message #373049] Mon, 26 March 2001 10:16 Go to previous messageGo to next message
surayya
Messages: 8
Registered: March 2001
Junior Member
come on Salman you used "Gadha" word to someone you don't know.

Samreen
Re: procedure creates the insert statement [message #373078 is a reply to message #372864] Mon, 26 March 2001 10:17 Go to previous messageGo to next message
surayya
Messages: 8
Registered: March 2001
Junior Member
Hi Salman ,
I am from Hyd.How about you.
Re: procedure creates the insert statement [message #373080 is a reply to message #372864] Mon, 26 March 2001 12:57 Go to previous messageGo to next message
Salman Khan
Messages: 51
Registered: September 2000
Member
Hey, Iam karachian but living in Toronto/Canada.

You are a DBA or developer?

Bye
Salman Khan
Re: procedure creates the insert statement [message #373081 is a reply to message #373049] Mon, 26 March 2001 12:59 Go to previous messageGo to next message
Salman Khan
Messages: 51
Registered: September 2000
Member
Yeah really, I dont remeber when i said this.

Bye
Salman Khan
Re: procedure creates the insert statement [message #373082 is a reply to message #373049] Mon, 26 March 2001 13:10 Go to previous messageGo to next message
surayya
Messages: 8
Registered: March 2001
Junior Member
But it was cute though.It bought smile onto my face.
Now are you really Salman?
Re: procedure creates the insert statement [message #373083 is a reply to message #372864] Mon, 26 March 2001 13:22 Go to previous messageGo to next message
surayya
Messages: 8
Registered: March 2001
Junior Member
I am suppose to be developer but I don't know what I am doing now.
Re: procedure creates the insert statement [message #373085 is a reply to message #372864] Mon, 26 March 2001 19:21 Go to previous messageGo to next message
Salman Khan
Messages: 51
Registered: September 2000
Member
What type of work are you doing now?
Re: procedure creates the insert statement [message #373093 is a reply to message #373049] Tue, 27 March 2001 06:44 Go to previous messageGo to next message
vishal gupta
Messages: 111
Registered: March 2001
Senior Member
Hey love birds won't it be good if you keep your conversation private.

--Vishal Gupta
Re: procedure creates the insert statement [message #373098 is a reply to message #373049] Tue, 27 March 2001 13:13 Go to previous messageGo to next message
Swathi
Messages: 5
Registered: March 2001
Junior Member
Stupid you don't interfere.Are you jealous
Re: procedure creates the insert statement [message #373099 is a reply to message #373049] Tue, 27 March 2001 13:14 Go to previous messageGo to next message
Swathi
Messages: 5
Registered: March 2001
Junior Member
Stupid you don't interfere.Are you jealous
Re: procedure creates the insert statement [message #373100 is a reply to message #373049] Tue, 27 March 2001 13:18 Go to previous messageGo to next message
Swathi
Messages: 5
Registered: March 2001
Junior Member
Stupid Vishal Gupta
you don't interfere.Are you jealous
Help [message #373854 is a reply to message #372841] Tue, 15 May 2001 23:44 Go to previous message
suneeldixit
Messages: 1
Registered: May 2001
Junior Member
Sir,

i have the problem,
problem is
Suppose u have 2 rows in a table,
and i want to insert the 3 row between the existing two rows..

What will be the query for it

with regards
Suneel Dixit
Previous Topic: How to query this question?
Next Topic: OCP developer. test ...please reply........
Goto Forum:
  


Current Time: Mon Jul 01 04:08:26 CDT 2024