Create table as in procedure vs SQL*Plus between 2 utf8-db's
I have a 9.2.05 db with charset UTF8 and Polish characters in it. When I extract a table to another 9.2.05 db with UTF8 charset using create table x as selcect * ...
When I run it in SQL*Plus everything works just fine but when I do the create table as from inside a procedure the national characters are converted to western characters and the length of the record are shorter. Why? How do I get the procedure to work as SQL*Plus does. /Göran
This sounds strange. Could you show the code of the procedure? Could you double-check that your db link points to the right database? Could you add:
SELECT VALUE INTO <variable1>
FROM NLS_DATABASE_PARAMETERS
WHERE PARAMETER='NLS_CHARACTERSET'
SELECT VALUE INTO <variable2>
FROM NLS_DATABASE_PARAMETERS@<dblink>
WHERE PARAMETER='NLS_CHARACTERSET'
to your procedure and output the contents of the PL/SQL <variable1> and <variable2>, e.g. using DBMS_OUTPUT, to verify the character sets of the databases?
-- Sergiusz
Similar Messages
-
How to compile a procedure from Sql*Plus?
Dear friends,
I couldnt find the way how to compile my invalid procedure through sql*Plus.
I know this is very awkward,but I m in need of that command only.
Thanks
Ritesh SharmaPls check it --
SQL>
SQL>
SQL> @C:\RND\Oracle\Function\a.sql;
11 /
Function created.
SQL>
SQL>
SQL> start C:\RND\Oracle\Function\a.sql;
11 /
Function created.
SQL> Regards.
Satyaki De. -
How to execute the parametered stored procedure in sql *plus ?
how to execute the parametered stored procedure in sql *plus ?
my storedprocedure format
CREATE OR REPLACE PROCEDURE SMS_SELECTMPLOYEE
(empDOB out date, empEmpName out varchar2)
thanks & regards
mk_murOh, sorry... making many reading-too-fast mistakes today...
You can't declare date variables in SQL*Plus (seel help var), but you can cast to varchar2:
TEST> CREATE OR REPLACE PROCEDURE SMS_SELECTMPLOYEE (empDOB out date, empEmpName out varchar2) IS
2 d date := sysdate;
3 e varchar2(10) := 'bob';
4 begin
5 empdob := d;
6 empempname := e;
7 end;
8 /
Procedure created.
TEST> var d varchar2(30)
TEST> var n varchar2(30)
TEST> call SMS_SELECTMPLOYEE(:d,:n);
Call completed.
TEST> print d n
D
11/07/06
N
bobYoann. -
How to copy procedure to sql plus window.
I am trying to copy my procedure from note pad to sql plus window and some of the texts are being cut off. How can I copy the entire procedure to sql plus window.
thanksThank you guys this is what is happning.
1 CREATE OR REPLACE PROCEDURE ITEMCUSTOMPAGING(
2 p_desc in itemlist.idescr%type,
3 p_letting in bidlet.datelet%type,
4 p_letting1 in bidlet.datelet%type,
5 p_sort in NUMBER ,
6 p_order in VARCHAR ,
7 i_results out sys_refcursor
8 )
9 AS
10 BEGIN
11 OPEN i_results FOR
12 SELECT g.csecnum , e.iplineno , substr(e.eiitem ,1,4)||'.'||substr(e.eiitem ,5,9) ItemNum,
13 INITCAP(i.idescr ||' '|| e.isupdes) Descrip,INITCAP(i.idescrl ||' '|| e.isupdes) Descrip
14 DECODE (TRIM (p.prroute), NULL, 'N/A',p.prroute) Route,b.datelet ,trim(to_char(b.datelet ,'
15 FROM itemlist i, estitem e, estcatg g, propproj x, proposal p, bidlet b, letprop l
16 WHERE p.contid = x.contid AND x.pcn = g.pcn AND e.pcn = g.pcn AND e.cn = g.cn AND i.item =
17 AND i.ispecyr = p.cspecyr AND e.iplineno <> ' ' AND e.eiitem <> '2550601/01000'
18 AND e.eiitem <> '2565601/00031' AND e.eiitem <> '2565601/00032' AND e.eiitem <> '2565601/0003
19 AND e.eiitem <> '2402601/01000'
20 AND (i.idescr like TRIM(UPPER(p_desc))||'%' or i.idescrl like TRIM( UPPER(p_desc))||'%'
21 AND b.datelet between p_letting and p_letting1
22 AND p.contid = l.lcontid
23 AND l.letting = b.letting
24 AND SUBSTR (l.lcontid, 4, 4) <= '5'
25 GROUP BY g.csecnum,i.idescr,b.datelet,i.iunits,p.clocat1,p.clocat2,p.contid,p.cdescr, p.cproj
26 ORDER BY p_sort p_order;
27* End;
QL> /
arning: Procedure created with compilation errors.
QL> SHOW ERR
rrors for PROCEDURE ITEMCUSTOMPAGING:
INE/COL ERROR
2/8 PL/SQL: SQL Statement ignored
6/25 PL/SQL: ORA-00933: SQL command not properly ended
QL> -
Testing stored procedure using sql plus
I'm attempt to create and test a stored procedure in sql plus.
I enter:
create procedure sp_getconfiguration(mygroup in char, myparameter in char, myvalue in out char) as begin select configvalue into myvalue from tblconfiguration where configgroup = mygroup and configparameter = myparameter; end;/
I get a procedure created. response by when I type:
variable myval char
call sp_getconfiguration('Language','Enabled', myval);
I get the following error:
error at line 1:
ora-06576: not a valid function or procedure name
I can go into DBA studio and see the procedure listed and can compile it and it says "valid". I have tried granting execute permission to public and trying it again under sql plus and nothing seems to help.
I'm also attempting to run this same procedure from VB and get an invalid column name error from there.
Thanks for any help in advance.
LeeThanks for all your help. What I actually called product support and they helped me solve it. But what I found out is that if using oracle 8.1.# you have to invoke the stored procedure without the "call " in front of the procedure name. For instance.
sp_getconfiguation()
In version 9.# it appears that you use the call in front of the procedure. Dah! So if anyone else is having this problem. That is the solution. Thanks anyway. -
Create Table in a Procedure?
Hey everybody!
got a question... I would like to create a table within a procedure with a dynamic number of rows. The Input of the Procedure should be a number, and this number should determine the number of rows. Thought about something like this:
create_table(3)
-> rows: Seq_nb, Z1_Air, Z1_Gas, Z1_Time, Z2_Air, Z2_Gas, Z2_Time, Z3_Air, Z4_Gas, Z3_Time
is this possible to do? All Tries to make a CREATE TABLE within the Procedure didn't work. Also, it seems to be difficult to name a row like 'Zx_Gas', x := Number
I don't mean a temporary table, it should be a REAL table ;)
Anybody who could help me please? Thanks in advance!!Is this the one you are trying to get?
create or replace procedure create_table(num_of_cols in number) is
num number;
stmt varchar2(400);
begin
num:=num_of_cols;
execute immediate 'drop table test_tab';
stmt:='create table test_tab(constant_cols varchar2(30)';
for i in 1.. num
loop
stmt:=stmt||', Z'||i||'_Air varchar2(30)';
stmt:=stmt||', Z'||i||'_Gas varchar2(30)';
stmt:=stmt||', Z'||i||'_Time varchar2(30)';
end loop;
stmt:=stmt||')';
execute immediate stmt;
end; -
How to view a stored procedure from sql plus
Can anyone please tell what is the command for viewing the content of the stored procedure from sql plus ?
ThanksHi,
I use this simple script to retrieve.......
EDTRAD@T_E_S_9-->l
1 select text from all_source where name = 'GET_MAN' -- proc name here
2* order by line asc
EDTRAD@T_E_S_9-->/
TEXT
FUNCTION get_man (in_man SSBOSS.CLNTWORK.manager%type)
RETURN varchar2 IS
CURSOR get_man(in_man SSBOSS.CLNTWORK.manager%type) IS
SELECT name
FROM ssboss.clntwork
WHERE agency = 'TM'
AND manager = in_man
AND manager is not null
AND manager != '**OB**';
v_man SSBOSS.CLNTWORK.name%type := null;
BEGIN
OPEN get_man(in_man);
FETCH get_man INTO v_man;
IF get_man%notfound THEN
v_man := 'Manager Not Found !';
RETURN (v_man);
CLOSE get_man;
END IF;
RETURN (v_man);
CLOSE get_man;
END;
21 rows selected.
EDTRAD@T_E_S_9--> -
How to pass Unix environment variable to a SQL procedure or SQL * Plus
Can any body suggest me how to ,
How to pass Unix environment variable to a SQL procedure or SQL * Plus file..
I am trying to invoke a SQL Procedure from Unix
by passing the value of a Unix environment variable.
Is it possible..?
Thanks in advance.
Regards,
Srinivas JaltaruWithin your shell script you can use what is known as a "here document" which is basically a way of wrapping a call to Oracle. The following call to Oracle loops and writes rows to files with numerically increasing file names. Two unix shell variables are used, one in a select statement and one in a spool command :
<pre>
#!/bin/bash
export ORACLE_SID=DEV05
FILENO=1007351
while [ ${FILENO} -le 1008400 ]
do
FILENAME=farm_${FILENO}.txt
DUMMY=`sqlplus -s user20/user20 <<SQLSTOP
set lines 73
set pages 0
set head off
set termout off
set echo off
set feedback off
select rpad(searchx, 8)
from blastx@PRODUCTION
where searchx = ${FILENO} ### here's a shell variable
spool /export/home/user20/sql/psiblast/BACKUP2_D/${FILENAME} ### here's a shell variable
spool off
SQLSTOP`
FILENO=`expr ${FILENO} + 1`
done
exit 0
</pre> -
Create table statement in a pl/sql procedure
Hi all.
I have a problem in Oracle 10g.
First of all I must say that I'm new in oracle 10.
I have a stored procedure in which I have the instruction "create table name_table as
select col1,col2,col3,..ecc
from table1, table2
where table1.col1 = table2.col2"
When I compile this procedure it gives me an error.
Is it changed the sintax????
Is there anyone that can help me???
Thanks all for the collaboration,
FabrizioA little mistake -- see it --
SQL> ed
Wrote file afiedt.buf
1 Create or replace procedure My_procedure as
2 begin
3 EXECUTE IMMEDIATE 'create table my_table(fld number(5));'
4* end;
SQL> /
Warning: Procedure created with compilation errors.
SQL>
SQL>
SQL> ed
Wrote file afiedt.buf
1 Create or replace procedure My_procedure as
2 str varchar2(200);
3 begin
4 str := 'create table my_table(fld number(5))';
5 EXECUTE IMMEDIATE(str);
6* end;
SQL> /
Procedure created.
SQL>
SQL>
SQL> Create or replace procedure My_procedure as
2 begin
3 EXECUTE IMMEDIATE 'create table my_table(fld number(5));'
4 end;
5 /
Warning: Procedure created with compilation errors.
SQL> ed
Wrote file afiedt.buf
1 Create or replace procedure My_procedure as
2 begin
3 EXECUTE IMMEDIATE 'create table my_table(fld number(5))';
4* end;
SQL> /
Procedure created.Regards.
Satyaki De.
N.B.: Please check the bolded line. You didn't write the ; outside the quotation. Otherwise, it will compile successfully. -
PLS-00201 error occurs when batching a stored procedure in SQL*Plus
I have a batch file to run a stored procedure and spool the results to file. When I enter the commands manually in sql*plus the output works fine and my results are spooled to the output file. But when I run the same commands in the batched script I get an error.
Any ideas?
Stored Procedure:
create or replace procedure MMP( p_cursor in out SYS_REFCURSOR)
as
begin
open p_cursorfor select name, id from table;
end;
batch file 1:
sqlplus -S user/pw@REPORTDV @sp_output_spooled.sql
script file sp_output_spooled.sql
Pasting these commands directly to the SQL*Plus command prompt spools the result set to file as expected.
set colsep '|'
set echo off
set feedback off
set termout off
set heading off
set linesize 9000
set pagesize 0
set trimspool on
set headsep off
spool output.TXT
var rc refcursor
execute MMP(:rc)
print rc
spool off
exit
The errors printed to output.TXT file after the batch is run and error occurs:
BEGIN MMP(:rc); END;
ERROR at line 1:
ORA-06550: line 1, column 8:
PLS-00201: identifier 'MMP' must be declared
ORA-06550: line 1, column 8:
PL/SQL: Statement ignored
ERROR:
ORA-24338: statement handle not executed
SP2-0625: Error printing variable "rc"Hi,
Your code worked fine for me.
Is MMP procedure owned by the same user that is running the batch file or does it have proper privileges and synonym?
vr,
Sudhakar -
How execute this stored procedure from SQL PLUS???
Hello folks....
Help me please...
I have this procedure....
CREATE OR REPLACE PROCEDURE TEST(COD OUT VARCHAR2, NUM OUT
VARCHAR2, ID OUT VARCHAR2)
AS
BEGIN
END;
SO, I4D LIKE TO EXECUTE IT FROM SQL PLUS::
BUT, I DONT KNOW HOW TO DO..PLEASE SEND ME A SAMPLE..
THANK UThank u man!!!
look, my error before was :
SQL> set serveroutput on
SQL> declare
SQL> cod varchar2(100);
SQL> num varchar2(100);
SQL> id varchar2(100);
SQL> begin
SQL> TEST( cod, num, id );
SQL> EXEC DBMS_OUTPUT.put_line( cod || ' ' || num || ' ' ||
id );
SQL> end;
SQL> /
i put the EXEC....
thank u!!! -
Create Table or MV in PL/SQL
Hey everyone,
This is probably a really simple question, but I can't seem to create a table in a PL/SQL procedure. I have something like this:
PROCEDURE TEST_PROC IS
BEGIN
EXECUTE IMMEDIATE 'CREATE TABLE TEST_TBL AS SELECT * FROM DUAL';
END TEST_PROC;
I get a privs error when I try to execute the proc. I also tried first to create a materialized view in a very similar manner, but it also didn't work.
I did some looking and on someone's blog, they created a table using the full create table statement i.e. CREATE TABLE NAME ( COLUMN1 TYPE1, etc..);
But I want to create the table using the "AS" clause and defining a query.
Is there a specific privilege I need to be able to do this? It seems simple enough.
Thanks!
-JoeHere's what I run:
I ran the query you provided above and here are the results:
UNLIMITED TABLESPACE
CREATE TABLE
Here are the commands I run:
CREATE TABLE TEST_TABLE AS SELECT * FROM DUAL;CREATE TABLE succeeded.
DROP TABLE TEST_TABLE;DROP TABLE TEST_TABLE succeeded.
CREATE PROCEDURE TEST_PROC IS
BEGIN
EXECUTE IMMEDIATE 'CREATE TABLE TEST_TABLE AS SELECT * FROM DUAL';
END TEST_PROC;PROCEDURE TEST_PROC Compiled.
EXEC TEST_PROC; Error starting at line 1 in command:
EXEC TEST_PROC;
Error report:
ORA-01031: insufficient privileges
ORA-06512: at , line 4
ORA-06512: at line 1
01031. 00000 - "insufficient privileges"
*Cause: An attempt was made to change the current username or password
without the appropriate privilege. This error also occurs if
attempting to install a database without the necessary operating
system privileges.
When Trusted Oracle is configure in DBMS MAC, this error may occur
if the user was granted the necessary privilege at a higher label
than the current login.
*Action: Ask the database administrator to perform the operation or grant
the required privileges.
For Trusted Oracle users getting this error although granted the
the appropriate privilege at a higher label, ask the database
administrator to regrant the privilege at the appropriate label.
Does this mean I need the CREATE ANY TABLE priv?
Thanks again everyone!
-Joe
Edited by: Joe Bertram on Dec 2, 2009 12:07 PM -
How to create table in a procedure
Dear All,
I am new to this PLSQL.
I want to create a table in a plsql procedure. I wrote proc but it is not working
CREATE OR REPLACE PROCEDURE loyalty_extraction(bc VARCHAR,r VARCHAR)
IS
v_count NUMBER ;
BEGIN
EXECUTE IMMEDIATE 'CREATE TABLE' || 'R'|| r || '_bc' ||bc||'loy_batch_test' ||'AS SELECT * FROM R5_BC5_LOY_BATCH WHERE 1=2';
EXECUTE IMMEDIATE 'SELECT COUNT(*) INTO v_count FROM R'|| r || '_bc' ||bc||'loy_batch_test';
END;
For Ex: If we run the proc as exec loyalty_extraction (2,2)
output should be: a table should be created as R2_BC2_LOY_BATCH_test
Thanks in advance.user9073870 wrote:
Dear All,
I am new to this PLSQL.
Then add these links to your favorites to find examples and explanation regarding Oracle Database:
http://asktom.oracle.com
http://www.oracle.com/pls/db112/homepage
http://www.oracle.com/pls/db102/homepage
http://tahiti.oracle.com (all Oracle documentation)
Creating tables on the fly (doing DDL through dynamic SQL) is usually a very bad thing to do.
But if you insist, you could try:
untested
create or replace procedure loyalty_extraction(bc varchar2,r varchar2)
is
v_count number ;
begin
execute immediate 'create table '||'r'||r||'_bc'||bc||'loy_batch_test'||' as select * from r5_bc5_loy_batch where 1=2';
execute immediate 'select count(*) from r'||r||'_bc'||bc||'loy_batch_test' into v_count ;
dbms_output.put_line(v_count);
end;
/Also, when posting code, and you want it formatted, remember to use the {noformat}{noformat} tag for that.
Put it before and after your example.
So, when you type or paste your formatted code like this:
{noformat}select *
from dual;{noformat}
it will appear as:select *
from dual;on this forum -
Issue with new line when manually executing a procedure in SQL*Plus
The below procedure works fine in SQL*Plus when the entire EXEC <procedure_name> (parameter1, parameter2, ..); is put in a single line
SQL > exec cust_admin_util.create_schema (P_SCHEMA_NAME => 'SCOTT_01', P_SCHEMA_PWD => 'scott123', P_TBS_NAME => 'TRAG_TBS', p_temptbs_name => 'TEMP' );
PL/SQL procedure successfully completed.I wanted to execute the same procedure with more readability. So, I put each parameters on a separate line and try to execute. But it is erroring out.
SQL > exec cust_admin_util.create_schema
P_SCHEMA_NAME => 'TESTUSR_01',
P_SCHEMA_PWD => 'scott123',
P_TBS_NAME => 'TRAG_TBS',
p_temptbs_name => 'TEMP'
);BEGIN cust_admin_util.create_schema; END;
ERROR at line 1:
ORA-06550: line 1, column 7:
PLS-00306: wrong number or types of arguments in call to 'CREATE_SCHEMA'
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored
SQL > 2 3 4 5 6 7
P_SCHEMA_NAME => 'TESTUSR_01',
ERROR at line 2:
ORA-00928: missing SELECT keywordAny workaround for this ?Hi Tom,
At SQL Plus,
You have to use the -(Hyphen) as the concatenation Operator.
For Instance,
SQL> exec host_command( -
p_command => 'dir');
PL/SQL procedure successfully completed.
Thanks,
Shankar -
Using Create table command in a Pl/Sql Anonymous Block
Hi,
I need to create a table dynamically based on the table_name and column_names that a user wants. When I use a Pl/sql Anonymous block to do this, it complains. Any suggestions ?
Thanks,
MarisaPersonally this sounds like a bad design to me. I would say under most "normal" circumstances, you should not be creating tables on the fly. Especially one where a user has control over what columns,datatypes to use. Let a developer or dba take care of that.
Maybe you are looking for
-
Some appointments are not shown sometimes
I access a Webaccess server that is in GMT+1 timezone from GMT-5 timezone and have GW set to either GMT-5 explicitly or use workstation's timezone. I did this test on Sunday Feb 26 and couple hours into Monday Feb 27 (GMT-5) - I created an appointmen
-
Hi there, i bought an Ipad air and trying to upload the pictures that i have taken in raw files via itunnes. however pictures are quite blurry which is disappointing. Appreciate any suggestions on how to make it right via itunes? Thanks
-
Hi I have uploaded some pdf files using HTMLDB upload download tutorial. When downloading it always pops up the option of "Open"/"Save"/"Cancel" I dont want to see the options. Instead I should be able to view the pdf file in the web browser. Any sug
-
Regarding delete entreis from infotype
hi experts, i need to delete multiple records from the custmized infotype one at a time plz suggest me how to do that plz dnt suggest loop at itab,hr_infotype_opertaion as i already used but it is taking so much of time for deleting 4000 to 5000 entr
-
Error code -36. Two MACs: One mac can copy DVD data, one can't.
On the G5 that appears in the profile below, I cannot copy VOB files without getting error code -36 in which the copy operation times out. Another older 1.6G G5 can copy. The problem computer has a Pioneer 115D burner. Older computer has a Sony U10A.