Create user through procedure on another database via database link - oracle

I have created user on another database using database link and stored procedure but facing problem while grant permission to the new created users.
Check below code:
CREATE OR replace PROCEDURE Hostname10 (user_name IN VARCHAR2,
pass_word IN VARCHAR2,
table_space IN VARCHAR2,
pro_file IN VARCHAR2)
AS
BEGIN
dbms_utility.Exec_ddl_statement#rahul2('CREATE USER '
||user_name
||' IDENTIFIED BY '
||pass_word
||' DEFAULT TABLESPACE '
||table_space
|| ' PROFILE '
|| pro_file
|| ' ACCOUNT UNLOCK');
dbms_utility.Exec_ddl_statement#rahul2('grant create table,create session,create view,create sequence,create procedure,create job,create synonym to'
||user_name
||'');
END;
/
I am getting error while executing it:
Error:
Error report -
ORA-06550: line 1, column 7:
PLS-00201: identifier 'HOSTANAME10' must be declared
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
*Action:

Your error message says:
PLS-00201: identifier 'HOSTANAME10' must be declared
^
But your procedure is created as Hostname10. So this is just a typo, you have an extra a in the name when you try to call the procedure.
You also seem to have a mistake in the grant call, though you're not currently getting that far; that ends with:
... create synonym to'
||user_name
||'');
so in the generated command there will be no space between to and the username; that needs to be:
... create synonym to '
||user_name);
Concatenating the null/empty string after the username isn't doing anything so I've taken the liberty of removing that too.

Related

Cannot execute a stored procedure in Oracle

Here is a simple example using Toad for Data Analysts 3.0.1.1734. I have full permissions on the schema JSWEENEY.
Create the table
CREATE TABLE JSWEENEY.TEMP_SQL
(
SQL VARCHAR2(3000)
);
Create the procedure
CREATE OR REPLACE PROCEDURE JSWEENEY.SP_INSERT_SQL
IS
BEGIN
INSERT INTO JSWEENEY.TEMP_SQL(SQL) VALUES('SELECT * FROM TEMP_SQL');
COMMIT;
END JSWEENEY.SP_INSERT_SQL;
/
Execute the procedure:
BEGIN
JSWEENEY.SP_INSERT_SQL;
END;
The first error:
ORA-06550: line 2, column 11:
PLS-00905: object JSWEENEY.SP_INSERT_SQL is invalid
ORA-06550: line 2, column 2: PL/SQL: Statement ignored
Execute the procedure:
BEGIN
EXECUTE JSWEENEY.SP_INSERT_SQL;
END;
The second error:
ORA-06550: line 2, column 10:
PLS-00103: Encountered the symbol "JSWEENEY" when expecting one of the following: := . ( # % ; immediate The symbol ":=" was substituted for "JSWEENEY" to continue.
Any suggestions would be greatly appreciated.
When you compile the procedure you will get an error; if your client doesn't display that then you can query the user_errors view (or all_errors if you're creating it in a different schema) to see the problem. Here it will be complaining that:
LINE/COL ERROR
-------- -----------------------------------------------------------------
6/13 PLS-00103: Encountered the symbol "." when expecting one of the following:
;
It's valid to use the schema name in the create call; but not as part of the end. So if you need to specify the schema at all - which you don't if you're creating an object in your own schema, but your reference to permissions makes it sound like you aren't - then it should be:
CREATE OR REPLACE PROCEDURE JSWEENEY.SP_INSERT_SQL
IS
BEGIN
INSERT INTO JSWEENEY.TEMP_SQL(SQL) VALUES('SELECT * FROM TEMP_SQL');
COMMIT;
END SP_INSERT_SQL;
/
Your second error is because execute on its is a client command (in SQL*Plus and relations), not a PL/SQL statement. The error refers to immediate because PL/SQL does have an execute immediate statement which is used for dynamic SQL, not for making static calls to procedures. Your first syntax to run the procedure is correct, once the procedure itself is valid:
BEGIN
JSWEENEY.SP_INSERT_SQL;
END;
/
try this edited the SQL statement.
create table TEMP_SQL ( col1 varchar2(100));
CREATE OR REPLACE PROCEDURE SP_INSERT_SQL
AS
BEGIN
INSERT INTO TEMP_SQL SELECT * FROM TEMP_SQL;
COMMIT;
END SP_INSERT_SQL;

Use string concatenation in UPDATEXML()

I want to write an update script for my oracle db. I want to replace old XML node values with new ones. But I need to do this for many values so I wanna outsource the logic in a procedure.
This is what I've come up with.
CREATE OR REPLACE PROCEDURE MY_PROCEDURE(
old_name IN NVARCHAR2,
new_name IN NVARCHAR2
)
AS
BEGIN
UPDATE
MY_TABLE
SET
ENTITY = UPDATEXML(ENTITY, '/*/Section', '<Section>' || new_name || '</Section>', 'xmlns="http://foo.bar.com/baz"')
WHERE
EXTRACTVALUE(ENTITY, '/*/Section', 'xmlns="http://foo.bar.com/baz"') = old_name;
END;
This is actually working really well - when I don't use string concatenation in UPDATEXML(). When I start using concatenation the execution of the procedure stops working / starts to throw exceptions.
I've also tried CONCAT(CONCAT('<Section>', new_name), '</Section>') instead of the ||-Operator. Didn't work out either.
The exception I get running the procedure in Oracle SQL Developer
ORA-06550: line 2, column 5:
PLS-00905: object MY_DB.MY_PROCEDURE is invalid
ORA-06550: line 2, column 5:
PL/SQL: Statement ignored
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
*Action:

PLS-00201 Error Occured for the Trigger must be declared pls-00201

CREATE OR REPLACE TRIGGER trg_test
AFTER DELETE
ON ADMİN.KULLANICILAR
for each row
DECLARE
v_username := USER;
BEGIN
DBMS_OUTPUT.PUT_LINE(v_username);
END;
Hey guys I'm getting that error always I put every privalege to my user and
it says :
after editing
CREATE OR REPLACE TRIGGER trg_test
AFTER DELETE
ON ADMİN.KULLANICILAR
for each row
DECLARE
v_username nvarchar2(20) := USER;
BEGIN
DBMS_OUTPUT.PUT_LINE(v_username);
END;
and error like that it ll runs on apex but not on oracle sql dev:
BEGIN
DBMS_OUTPUT.PUT_LINE(v_username);
END;
Error report -
ORA-06550: line 2, column 26:
PLS-00201: identifier 'V_USERNAME' must be declared
ORA-06550: line 2, column 5:
PL/SQL: Statement ignored
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
*Action:

Execute Immediate not working,need help in syntax

When I am executing the below query, it is working:
CREATE TABLE MySchema.AAA ( INFOLINKPODID NVARCHAR2(50));
But when I am trying to execute the same using execute immediate:
EXECUTE IMMEDIATE 'CREATE TABLE '|| MySchema||'.AAA ( INFOLINKPODID NVARCHAR2(50));';
Getting below compilation error:
Error report -
ORA-06550: line 1, column 17:
PLS-00103: Encountered the symbol "CREATE TABLE " when expecting one of the following:
:= . ( # % ;
The symbol ":=" was substituted for "CREATE TABLE " to continue.
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
*Action:
Thanks in advance.
as per the comments, you need a framing block, but also the semi-colon at the end of the execute immediate string needs to be removed (or you will get an ORA-00911 invalid character error), like this:
begin
execute immediate 'CREATE TABLE TEST (X NUMBER)';
end;
/
should work.

Why do I get an error as I try to call a procedure?

I created a procedure named greet as :
create procedure greet(message in char(50))
as
begin
dbms_output.put_line('Greet Message : ' || message);
end;
The procedure compiled successfully but when I try to call it as :
execute greet('Hey ! This is a self created procedure :)');
I get an error :
execute greet('Hey ! This is a self created procedure :)')
Error report:
ORA-06550: line 1, column 7:
PLS-00905: object SUHAIL.GREET is invalid
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
*Action:
What error is it ? Why do I get it ?
Note : 'suhail' is name of the current user connected to oracle server
I don't believe that your procedure compiled successfully. When I try to compile it on my system, I get syntax errors
SQL> create procedure greet(message in char(50))
2 as
3 begin
4 dbms_output.put_line('Greet Message : ' || message);
5 end;
6 /
Warning: Procedure created with compilation errors.
SQL> sho err
Errors for PROCEDURE GREET:
LINE/COL ERROR
-------- -----------------------------------------------------------------
1/32 PLS-00103: Encountered the symbol "(" when expecting one of the
following:
:= ) , default varying character large
The symbol ":=" was substituted for "(" to continue.
If I resolve the syntax errors (you cannot specify a length for an input parameter), it works
SQL> ed
Wrote file afiedt.buf
1 create or replace procedure greet(message in char)
2 as
3 begin
4 dbms_output.put_line('Greet Message : ' || message);
5* end;
SQL> /
Procedure created.
SQL> set serveroutput on;
SQL> execute greet('Hey ! This is a self created procedure :)');
Greet Message : Hey ! This is a self created procedure :)
PL/SQL procedure successfully completed.
I would be shocked if you really wanted the input parameter to be declared as CHAR. Almost always, you should use VARCHAR2 for character strings. It is exceptionally rare to come across a case where you really want the blank-padding semantics of a CHAR.
this is working dude;
create or replace
procedure greet(message in char)
as
begin
dbms_output.put_line('Greet Message : ' || message);
end;
see main property of char datatype is is the length of input data is less than the size you specified it'll add blank spaces.this case is not happened for varchar2.
in procedure above mentioned char property is violated so it's almost treat like varchar2. so if you remove size of input parameter it will work and also char support maximum length of input.

Resources