procedure makes mysql script and return it as CLOB [message #160818] |
Tue, 28 February 2006 08:29 |
fabi
Messages: 26 Registered: February 2006
|
Junior Member |
|
|
Hi my name is lukas im from poland. i dont speak english very well so
sorry if you dont understand me. i dont find anything about my problem in
polish disciussion groups.
i must create procedure. this procedure has 1 parameter and return CLOB with mysql script(text script who create the same table as parameter in procedure with the same field and data but in mysql command). this parameter is table name.
for example create procedure aaa(table_name varchar2). then this
procedure must receive name of fields,type of fields and data from this fields and create mysql commands with this information.(create tables
and a lot of inserts) to CLOB and return this clob.
i dont have any idea to solve this problem. ( thanks for any information.
i try explain problem so clearly as i can .
[Updated on: Tue, 28 February 2006 08:46] Report message to a moderator
|
|
|
|
|
Re: procedure makes mysql script and return it as CLOB [message #160865 is a reply to message #160849] |
Tue, 28 February 2006 18:00 |
Todd Barry
Messages: 4819 Registered: August 2001
|
Senior Member |
|
|
I don't know what needs to change in order to get Oracle DDL to execute in mySQL, but here is a procedure example that use the DBMS_METADATA package to pull in the DDL automatically. Alternatively, you could loop through the user_tab_cols view to pull out just column names and datatypes.
sql>create or replace procedure getDDL
2 (p_table_name in user_tables.table_name%type,
3 p_ddl out clob)
4 is
5 begin
6 p_ddl := dbms_metadata.get_ddl('TABLE', p_table_name);
7 end;
8 /
Procedure created.
sql>var ddl clob
sql>set long 200
sql>exec getDDL('EMP', :ddl)
PL/SQL procedure successfully completed.
sql>print ddl
DDL
------------------------------------------------------------------------------
CREATE TABLE "BARRYT"."EMP"
( "EMPNO" NUMBER(4,0) NOT NULL ENABLE,
"E
NAME" VARCHAR2(10),
"JOB" VARCHAR2(9),
"MGR" NUMBER(4,0),
"HIREDATE" DAT
E,
"SAL" NUMBER(7,2),
"COMM" NUMBER(7,2)
I'm only showing the first 200 characters of the DDL here but you could see the whole thing by bumping up the value in the SET LONG SQL*Plus command.
|
|
|
Re: procedure makes mysql script and return it as CLOB [message #160952 is a reply to message #160865] |
Wed, 01 March 2006 02:24 |
fabi
Messages: 26 Registered: February 2006
|
Junior Member |
|
|
Todd Barry wrote on Tue, 28 February 2006 18:00 | Alternatively, you could loop through the user_tab_cols view to pull out just column names and datatypes.
|
thank you. could you give me a short example how i can through the user_tab_cols view to pull out just column names and datatypes????
|
|
|
|
Re: procedure makes mysql script and return it as CLOB [message #160967 is a reply to message #160957] |
Wed, 01 March 2006 03:39 |
fabi
Messages: 26 Registered: February 2006
|
Junior Member |
|
|
thank you
i have also another problem.
create or replace procedure proc(table_name varchar2)
is
cursor kur is
select * from table_name;
...
...
and system return me mistake in line //select * from table_name;
table or view does not exist something like that.
table_name from procedure must be the same in cursor.
how can i use parameter from procedure (table_name) in cursor???
thanks
|
|
|
|
|
Re: procedure makes mysql script and return it as CLOB [message #161034 is a reply to message #160997] |
Wed, 01 March 2006 08:47 |
fabi
Messages: 26 Registered: February 2006
|
Junior Member |
|
|
Maaher wrote on Wed, 01 March 2006 05:53 |
[code]SQL> CREATE PROCEDURE foo(p_tab_name IN VARCHAR2)
2 IS
3 CURSOR c_cols(c_tname VARCHAR2)
4 IS
5 SELECT column_name
6 , data_type
7 , data_length
8 , data_precision
9 , data_scale
10 FROM user_tab_columns
11 WHERE table_name = c_tname;
12 BEGIN
13 FOR the_column IN c_cols(p_tab_name)
14 LOOP
15 -- do your processing here
16 dbms_output.put_line(the_column.column_name||' is a '
17 ||the_column.data_type||' COLUMN.');
18 END LOOP;
19 END;
20 /
/code]
|
ok i used your code but i want second cursor next to cursor c_cols so i write
cursor kur(c_tname varchar2)
is select * from c_tname;
and there is a mistake : table or view does not exist
|
|
|
|
|