Create or replace Stored procedure

Hi all

11.2.0.1

I have the HR schema/user, who is the owner of all tables in the app.

Then, all his paintings are also granted to BATCH - HR user with corresponding synonyms.

This batch user will be used by computer operators to run reports of generations.

For security reasons, they are not allowed to CONNECT to HR, but only to the BATCH - RH.

My question is, can I create a stored procedure to the BATCH - RH which has only synonymous all tables?

Or is it a good design to install it on human resources?

Stored procedures recommend to operate only on base tables?

Thank you

Petra k.

You can use everywhere in PL/SQL or external programs, because synonym is nothing more than a name new/more existing object; i.e. scott.emp table can have synonym1, synonym2, synonym3, etc.

For more information: CREATE SYNONYM

Concerning

Girish Sharma

Tags: Database

Similar Questions

  • Tables created in a stored procedure cannot be used with dynamic SQL? The impact?

    There is a thread on the forum which explains how to create tables within a stored procedure (How to create a table in a stored procedure , however, it does create a table as such, but not how to use it (insert, select, update, etc.) the table in the stored procedure.) Looking around and in the light of the tests, it seems that you need to use dynamic SQL statements to execute ddl in a stored procedure in Oracle DB. In addition, it also seems that you cannot use dynamic SQL statements for reuse (insert, select, update, etc.) the table that was created in the stored procedure? Is this really the case?

    If this is the case, I am afraid that if tables cannot be 'created and used"in a stored procedure using the dynamic SQL, as is the case with most of the servers of DB dynamic SQL is not a part of the implementation plan and, therefore, is quite expensive (slow). This is the case with Oracle, and if yes what is the performance impact? (Apparently, with Informix, yield loss is about 3 - 4 times, MS SQL - 4 - 5 times and so on).

    In summary, tables created within a stored procedure cannot be 'used' with dynamic SQL, and if so, what is the impact of performance as such?

    Thank you and best regards,
    Amedeo.

    Published by: AGF on March 17, 2009 10:51

    AGF says:
    Hi, Frank.

    Thank you for your response. I understand that the dynamic SQL is required in this context.

    Unfortunately, I am yet to discover "that seeks to" using temporary tables inside stored procedures. I'm helping a migration from MySQL to Oracle DB, and this was one of the dilemmas encountered. I'll post what is the attempt, when more.

    In Oracle, we use [global temporary Tables | http://www.psoug.org/reference/OLD/gtt.html?PHPSESSID=67b3adaeaf970906c5e037b23ed380c2] aka TWG these tables need only be created once everything like a normal table, but they act differently when they are used. The data inserted in TWG will be visible at the session that inserted data, allowing you to use the table for their own temporary needs while not collide with them of all sessions. The data of the TWG will be automatically deleted (if not deleted programmatically) when a) a commit is issued or b) the session ends according to the parameter that is used during the creation of the TWG. There is no real need in Oracle to create tables dynamically in code.

    I noticed that many people say that the "Creation of the tables within a stored procedure" is not a good idea, but nobody seems necessarily explain why? Think you could elaborate a little bit? Would be appreciated.

    The main reason is that when you come to compile PL/SQL code on the database, all explicit references to tables in the code must correspond to an existing table, otherwise a djab error will occur. This is necessary so that Oracle can validate the columns that are referenced, the data types of those columns etc.. These compilation controls are an important element to ensure that the compiled code is as error free as possible (there is no accounting for the logic of programmers though ;)).

    If you start to create tables dynamically in your PL/SQL code, so any time you want to reference this table you must ensure that you write your SQL queries dynamically too. Once you start doing this, then Oracle will not be able to validate your SQL syntax, check the types of data or SQL logic. This makes your code more difficult to write and harder to debug, because inevitably it contains errors. It also means that for example if you want to write a simple query to get that one out in a variable value (which would take a single line of SQL with static tables), you end up writing a dynamic slider all for her. Very heavy and very messy. You also get the situation in which, if you create tables dynamically in the code, you are also likely to drop tables dynamically in code. If it is a fixed table name, then in an environment multi-user, you get in a mess well when different user sessions are trying to determine if the table exists already or is the last one to use so they can drop etc. What headache! If you create tables with table names, then variable Dynamics not only make you a lot end up creating (and falling) of objects on the database, which can cause an overload on the update of the data dictionary, but how can ensure you that you clean the tables, if your code has an exception any. Indeed, you'll find yourself with redundant tables lying around on your database, may contain sensitive data that should be removed.

    With the TWG, you have none of these issues.

    Also, what is the impact on the performance of the dynamic SQL statements in Oracle? I read some contrasting opinions, some indicating that it is not a lot of difference between static SQL and SQL dynamic in more recent versions of Oracle DB (Re: why dynamic sql is slower than static sql is this true?)

    When the query runs on the database, there will be no difference in performance because it is just a request for enforcement in the SQL engine. Performance problems may occur if your dynamic query is not binding variable in the query correctly (because this would cause difficult analysis of the query rather than sweet), and also the extra time, to dynamically write the query running.

    Another risk of dynamic query is SQL injection which may result in a security risk on the database.

    Good programming will have little need for the tables of dynamically created dynamically or SQL.

  • Link to database not be created using a stored procedure

    Hello

    I am creating a link of database using a stored procedure.

    Here is the code for it

    CREATE OR REPLACE PROCEDURE create_db_link (ca_db_name IN VARCHAR2,

    ca_service_name IN VARCHAR2)

    AUTHID CURRENT_USER IS

    BEGIN

    EXECUTE IMMEDIATE ' create public database link test_db_link connect to ca_db_name identified by ca_db_name using "ca_service_name" ';

    END create_db_link;

    During execution of the code is created the db_link. But, when I ask all_db_links I get the following result.

    OWNER

    ------------------------------

    DB_LINK

    --------------------------------------------------------------------------------

    USERNAME

    ------------------------------

    HOST

    --------------------------------------------------------------------------------

    CREATED

    ---------

    PUBLIC

    TEST_DB_LINK. WORLD

    CA_DB_NAME

    ca_service_name

    20 Aug 13

    Could you please help me understand why it shows the parameter names in the name column of the USER and the HOST instead of the name of the database and the name of the service?

    This is to show exactly what you said to do.

    Did you expect that Oracle would read as if by magic through your string you passed to run immediately and magically know to replace all occurrences of the string that correspond to local (or even global) parameter/variable names with the values of these variables?  It does not work like that.  You could concatenate the values into the string.

    for example

    EXECUTE IMMEDIATE ' create public database link test_db_link connect to ' | ca_db_name |' identified by ' | ca_db_name: ' using the "' | ca_service_name | " ' ;

    But why are create you database links running?  Shouldn't this be part of the design of your application and the initial fact before the application runs?

  • Extraction of the DDL (Code) of the stored procedures only

    DB Version: 11 g

    I have a list of stored procedures (about 250) whose code IE. Statements to CREATE or REPLACE STORED PROCEDURE I want to extract a file.
    Is there an option in imp or impdp where I can extract only the code of these stored procedures?

    Apart from the imp/impdp, is there another way to do this?

    Is there an option in imp or impdp where I can extract only the code of these stored procedures?

    Impdp, Yes. Write the contents of a file, the option SQLFILE.

    DUMPFILE = exp.dmp
    LOGFILE = exp.log
    SCHEMAS = TEST
    INCLUDE = PROCEDURE: 'IN ("SP") '.
    SQLFILE = sp... SQL

    Or use dbms_metadata.get_ddl

    set long 99999
    set pagesize 0
    SELECT DBMS_METADATA.GET_DDL(object_type, object_name, owner) FROM DBA_OBJECTS WHERE OBJECT_TYPE = 'PROCEDURE' and OWNER='OWNER';
    

    HTH
    -André

  • Create a stored procedure in the settings view

    I want to be able to create a view with the parameters of a stored procedure.

    Oracle 11g.

    don't know how to use the variable in immediate execution.

    CREATE OR REPLACE

    PROCEDURE TEST_GENERIC (TBL IN VARCHAR2, VWNAME IN VARCHAR2)

    AS

    BEGIN

    RUN IMMEDIATELY "CREATE OR REPLACE VIEW VWNAME AS SELECT SYSDATE FROM TBL";

    COMMIT;

    END;

    exec ('BIRD', 'DUAL') TEST_GENERIC

    Thanks for any help

    Hello

    Single quotes enclose a literal string; in other words, the text between the quotes literally means what it says, without reference to any variables.

    So, when you say:

    RUN IMMEDIATELY "CREATE OR REPLACE VIEW VWNAME AS SELECT SYSDATE FROM TBL";

    CREATE the word literally means to CREATE.  You may or may not have also a variable called CREATE, but that is irrelevant.

    The word OR means OR literally.  You may or may not have also a variable called operation GOLD, but that is irrelevant.

    REPLACE the word literally means REPLACE.  You may or may not have also a variable called to REPLACE, but that is irrelevant.

    ...

    The TBL Word literally means TBL.  You may or may not have also a variable called TBL, but that is irrelevant.

    If you want to reference a variable called TBL, then use TBL outside single quotes, like this:

    ...

    sql_text: = "CREATE or REPLACE VIEW VWNAME AS SELECT SYSDATE FROM '

    ||  TBL;

    dbms_output.put_line (sql_text |) "= sql_text before EXECUTE IMMEDIATE');   -For debugging

    EXECUTE IMMEDIATE sql_text.

    ...

    On the rare occasions when you use dynamic SQL statements, always put the dynamic SQL statement in a string variable (for example, sql_text, above) so that you can easily display for debugging purposes and to ensure that the command you are viewing is the same exact command that you should run.

    I guess the code you posted is a first test version of something that will be much, much different when it is finished.  Creating objects from database (such as views) in PL/SQL is almost always a terrible idea, and it seems that opinion that this code is attempting to produce would be very useful, anyway.

  • Create stored procedure

    Hi, I create my first stored procedure and really need help... I managed to set up the following:

    CREATE or REPLACE PROCEDURE DRL_PROCEDURE (var_SOURCE_OBJECTID IN varchar2, var_NEW_OBJECTID OUT varchar2)
    IS
    var_temp_newobjectid varchar2 (20);
    BEGIN
    SELECT MAX (NEW_OBJECTID)
    IN var_temp_newobjectid
    OF DRL_CONVERSION
    WHERE SOURCE_OBJECTID = var_SOURCE_OBJECTID;

    var_NEW_OBJECTID: = var_temp_newobjectid;
    return;
    END;

    I don't know if this is correct, however, I tried running with the following text, but when it does not perform any results show... it just says: procedure completed successfully:

    RETVAL VARIABLE VARCHAR2 (20)
    EXEC DRL_PROCEDURE('ab',:RETVAL);

    Do I need to change somehow to show the result?
    Also if you know how I can call the procedure in c# and show the result in this way which would be useful... Thank you

    Hi and welcome to the forums!

    The last step, you forgot to PRINT your result. See the example below:

    SQL> CREATE OR REPLACE PROCEDURE TEST_PROC
      2  (
      3          pOwner  IN VARCHAR2
      4  ,       pCnt    OUT VARCHAR2
      5  )
      6  AS
      7  BEGIN
      8          SELECT  COUNT(*) INTO pCnt
      9          FROM    ALL_OBJECTS
     10          WHERE   OWNER = pOwner;
     11  END;
     12  /
    
    SP2-0804: Procedure created with compilation warnings
    
    SQL> VAR result NUMBER;
    SQL> EXECUTE TEST_PROC(USER,:result);
    
    PL/SQL procedure successfully completed.
    
    SQL> PRINT result
    
        RESULT
    ----------
          7090
    

    In addition, you don't need the VAR_TEMP_NEWOBJECTID variable. You can SELECT... IN VAR_NEW_OBJECTID instead.

    HTH!

  • Create the user of the stored procedure.

    Hi, look at this and tell me where is the error:

    Oracle 10g R2 datbase.

    Conn SYS AS SYSDBA

    ****************************
    create user HR22 identified by HR22;

    create or replace
    change_password procedure)
    p_password varchar2)
    as

    Start
    run immediately 'edit user' | the user: ' identified by ' | p_password;
    end;
    /
    ****************************

    GRANT CONNECT, CHANGE USER TO HR22;

    GRANT EXECUTE ON change_password to HR22;

    Disc;

    CONN HR22/HR22

    execute SYS.change_password ('DATA');

    Error: Privileges insuficients.

    Roberto.

    Hello..

    When performing a procedure, the procedure works as the owner of the procedure. In this case, Don t you must assign the 'ALTER USER' privilege to the user HR22; You must assign the user owner of the procedure in your sys case username.

    You example...

    SYSTEM@> create user HR22 identified by HR22;
    
    User created.
    
    SYSTEM@> create or replace
      2  procedure change_password(
      3  p_password varchar2)
      4  as
      5
      6  begin
      7  execute immediate 'alter user '||user||' identified by ' ||p_password;
      8  end;
      9  /
    
    Procedure created.
    
    SYSTEM@> GRANT CONNECT TO HR22;
    
    Grant succeeded.
    
    SYSTEM@>
    SYSTEM@>  grant alter  user to system;
    
    Grant succeeded.
    
    SYSTEM@>
    SYSTEM@> GRANT EXECUTE ON change_password TO HR22;
    
    Grant succeeded.
    
    SYSTEM@> conn HR22@db
    Enter password: ****
    Connected.
    
    HR22@>  exec system.change_password('new');
    
    PL/SQL procedure successfully completed.
    

    Published by: dask99 on December 23, 2008 16:31
    Additional test cases

  • Why these stored procedures his does not work

    Hi I'm new and I need help following SQL works correctly, but when I walked into a stored procedure me displays error

    SELECT Por.PortalID,

    Name,

    Lower (LTrim (RTrim (SEOName))) SEOName,

    IsParent,

    Por.Parentid,

    (Select Seoname

    Portal port

    Where Por.Parentid = Port.Portalid) Parentportalname;

    SettingValue.SettingValue DefaultPage

    Por PORTAL

    JOIN SettingValue

    ON Por.PortalID = SettingValue.settingtypeid

    Where Settingtype = 'SiteAdmin '.

    And Settingkey = 'PortalDefaultPage. '

    his return:

    Portald Name SEONAME ISPARENT ParentId parentportalname DefaultPage
    1by defaultby default10nullHomepage

    It's my stored procedure

    create or replace

    Procedure Sp_Portalgetlist as

    Start

    SELECT Por.PortalID,

    Name,

    Lower (LTrim (RTrim (SEOName))) SEOName,

    IsParent,

    Por.Parentid,

    (Select Seoname

    Portal port

    Where Por.Parentid = Port.Portalid) Parentportalname;

    SettingValue.SettingValue DefaultPage

    Por PORTAL

    JOIN SettingValue

    ON Por.PortalID = SettingValue.settingtypeid

    Where Settingtype = 'SiteAdmin '.

    And Settingkey = 'PortalDefaultPage ';

    END SP_PORTALGETLIST;

    When I compile with oracle sqldeveloper show this error:

    • Error (4.1): PLS-00428: an INTO clause in this SELECT statement

    I appreciate all the help

    What about the compile error in a PL/SQL block a select statement has an additional part:

    Select attr1, attr2...

    in var1, var2,...

    Of...

    but you can also use your selection (without the) in a cursor:

    procedure is...

    cursor my_select is

    Select...;

    my_variable my_cursor % rowtype;

    Start

    Open my_cursor;

    extract my_cursor in my_variable; -fails at the record and then one more found!

    close my_cursor;

    ...

    Good bye

    DPT

  • How to do this consult of a hierarchical recursion on a stored procedure? Help!

    Please help me, im using oracle 11g

    I have 2 tables

    Department table (number of I_Depto (1), number of E_Depto (30));

    i_depto e_dept

    1 Finance

    2 shopping

    3 sistemas

    4               rh

    Empleado table (I_Emp number (5), N_Emp varchar (20), Q_salary (8.2) number, number of I_boss (5), the number of I_Depto (1));

    i_emp n_emp q_salary i_boss i_dept

    Juan 100 300 null 1

    200 100 100 1 Pedro

    300 Angélique 150 100 1

    400 70 300 2 alberto

    500 60 300 2 Miriam

    600 3 500 80 moises

    And yet, I have 3 conditions:

    If the boss has 3 employees or more, he has increased his salary by 20%

    If the boss have 2 employees, there was an increase in his salary of 10%

    And if 0 or 1 employee, there is an increase of 5%

    herarchical diagram is like that

    -> Pedro Juan

    Juan-> Angelica-> Alberto

    Juan-Angelica-Miriam-Moses > > >

    I have to present the name of the Department (e_depto) in the console and the result should be like this;



    SQL > exec p_example ('finance');

    Employees of BOSS of the boss pay increase employees (name) boss of the salary increase employee employees employees

    juan             6                                              60                             pedro                                   0                                      5

    juan             6                                              60                             angelica                               3                                    45

    pedro           0                                                5                              NULL                                  0                                     0

    Angelica       3                                              45                              alberto                                0                                     5

    Anglica         3                                               45                              miriam                               1                                     3

    SQL > exec p_example ('shopping');

    Employees of BOSS of the boss pay increase employees (name) boss of the salary increase employee employees employees

    alberto             0                                              3.5                             -                                   0                                      0

    miriam             1                                                3                         moises                            0                                    4

    SQL > exec p_example('sistemas);

    Employees of BOSS of the boss pay increase employees (name) boss of the salary increase employee employees employees

    moises             0                                            4                              -                                  0                                      0

    His need to create a recurrence, stored procedure

    The query I have is this, but it only shows me that the boss and the boss employees.

    createor replace procedure deptos (depto varchar) as

    t_boss varchar (49);

    t_employ varchar (50);

    cursor c_depto (t_depto varchar) is

    Select a.n_emp boss, employee of b.n_emp

    of empleado a, b empleado, departamento d

    where a.i_emp = b.i_boss (+) and d.i_dept = a.i_dept

    and a.i_emp in (select i_EMP from empleado where i_dept = t_dept);

    Start

    Open c_depto (depto);

    loop

    extract the c_depto in t_boss t_employ;

    When the output c_depto % notfound;

    dbms_output.put_line (t_boss |) Chr (9) | Chr (9) | t_employ);

    end loop;

    end;

    /

    Hello

    I know it's a pain to post CREATE TABLE and INSERT statements for the sample data.  Think about why it is necessary: that people who want to help you can recreate the problem and test their ideas.  If you post statements that do not work, which does not recreate the problem or to test their ideas.  Test (and, if necessary, correct) your statements before committing.  Make sure all quotes are balanced.

    I don't understand the desired output.  For example, when n_emp = 'Juan', why is-employees_ofthe_boss = 6, 5 no?  When n_emp is 'Angelic', why is-salary_increase = 45, not 30?  When n_emp = 'Alberto', why is-salary_increase = 5, not 3.5?

    You may want something like this:

    WITH universe_dup AS

    (

    SELECT i_emp, n_emp, q_sueldo, i_jefe

    SYS_CONNECT_BY_PATH (i_emp, ","). ',' AS line

    ,       LEVEL                                    AS lvl

    Of empleado

    START WITH (IN) i_depto

    SELECT i_depto

    OF Department

    WHERE e_depto = 'Finance' - or what you want

    )

    CONNECT BY i_jefe = PRIOR i_emp

    )

    universe

    (

    SELECT i_emp, n_emp, q_sueldo, i_jefe

    MAX (lineage) DUNGEON (DENSE_RANK LAST ORDER BY lvl) AS lineage

    MIN AS min_level (lvl)

    Of universe_dup

    GROUP of i_emp, n_emp, q_sueldo, i_jefe

    )

    got_salary_increase AS

    (

    SELECT a.i_emp, a.n_emp, a.i_jefe, a.min_level

    EARL of (d.i_emp) AS employee_cnt

    , a.q_sueldo * CASE

    WHEN COUNT (d.i_emp) > = 3 PUIS.2

    WHEN COUNT (d.i_emp) = 2 PUIS.1

    OF AUTRE.05

    END AS salary_increase

    OF the universe a

    LEFT OUTER JOIN universe d ON d.lineage LIKE '%', | a.i_emp | ',%'

    AND d.i_emp <> a.i_emp

    GROUP OF a.i_emp, a.n_emp, a.i_jefe, a.min_level, a.q_sueldo

    )

    SELECT p.n_emp AS boss

    p.employee_cnt AS employees_ofthe_boss

    p.salary_increase AS salary_increase_boss

    c.n_emp AS employees_name

    , NVL (c.employee_cnt, 0) AS employees_ofthe_employee

    , NVL (c.salary_increase, 0) AS salary_increase_employee

    OF got_salary_increase P

    LEFT OUTER JOIN got_salary_increase c ON c.i_jefe = p.i_emp

    WHERE p.min_level = 1

    ;

    Depending on your data and your needs, it may be more effective to do "START WITH i_jefe IS NULL", as one of the above.  I guess "START WITH i_depto (...)" in the largest tables, when efficiency is more important.

  • Adding apostrophe in dymanic, stored procedure

    Hello world

    I use a stored procedure that prints the triggers which is called as a script to dynamic triggers.

    Here I store the values required in M_ALL_DYNAMIC_DRIVER_TEMP table name

    for ex: M_ALL_DYNAMIC_DRIVER_TEMP:

    TABLE-NAME DATA_UID_ALT1_PREFIX IU_TRG_FLAG

    --------------         --------------------------                  -------------

    BA_ORG                ALT                                     Y

    stored procedure is:

    create or replace

    PROCEDURE SP_TRIGGER_SCRIPT_temp

    AS

    SQLSTR VARCHAR (4000);

    SQLSTR_ETL VARCHAR (4000);

    SQLSTR1 varchar (40);

    SQLSTR2 varchar (40);

    SQLSTR3 varchar (40);

    SQLSTR4 varchar (40);

    Table-name varchar (40);

    PK_TABLE varchar (40);

    Start

    for c in (select TABLE_NAME, DATA_UID_ALT1_PREFIX from M_ALL_DYNAMIC_DRIVER_TEMP where IU_TRG_FLAG = 'Y' and DATA_UID_ALT1_PREFIX is not null)

    loop

    SQLSTR1: = c.TABLE_NAME;

    SQLSTR2: = TRIM (SQLSTR1) | ' _ID'.

    DBMS_OUTPUT. PUT_LINE ('-TABLE_NAME START :'||) SQLSTR1 |', DATA_UID_GEN_METHOD:ALT1, SHORT_TRG_BASENAME:-");"

    SQLSTR: = ' create or replace

    TRIGGER ' ' |. ' TRIM (SQLSTR1) | "' _IU_TRG ' INSERT BEFORE THE '. SQLSTR1 | "FOR EACH LINE

    BEGIN

    If the insertion

    If: new. ROW_CHANGED_BY is NULL then

    : new. ROW_CHANGED_BY: =: new. ROW_CREATED_BY;

    end if;

    If: new. DATA_UID is NULL then

    SELECT GENERATE_DATA_UID('||) SQLSTR1 |',: new.'. SQLSTR2 |') IN: new. DATA_UID FROM DUAL;

    end if;

    end if;

    If the update can

    If it isn't updating ("ROW_CHANGED_BY") then

    : new. ROW_CHANGED_BY: = USER;

    end if;

    end if;

    END ';

    DBMS_OUTPUT. PUT_LINE (SQLSTR);

    DBMS_OUTPUT. PUT_LINE (SQLSTR_ETL);

    DBMS_OUTPUT. PUT_LINE ('-END OF ' |) SQLSTR1 | » -------------------------------------------------------------');

    end loop;

    end;

    When I run the stored procedure out put:

    -LAUNCH TABLE_NAME:BA_ORG, DATA_UID_GEN_METHOD:ALT1, SHORT_TRG_BASENAME:-

    create or replace

    "BA_ORG_IU_TRG" TRIGGER BEFORE INSERT ON BA_ORG FOR EACH LINE

    BEGIN

    If the insertion

    If: new. ROW_CHANGED_BY is NULL then

    : new. ROW_CHANGED_BY: =: new. ROW_CREATED_BY;

    end if;

    If: new. DATA_UID is NULL then

    SELECT GENERATE_DATA_UID (BA_ORG,: new.BA_ORG_ID) INTO: new. DATA_UID FROM DUAL;

    end if;

    end if;

    end if;

    END

    --------------------------------------END OF BA_ORG-------------------------------------------------------------

    I want to:

    statement: SELECT GENERATE_DATA_UID (BA_ORG,:new.BA_ORG_ID) IN: new. DATA_UID FROM DUAL;

    be: SELECT GENERATE_DATA_UID ('BA_ORG',: new.BA_ORG_ID) INTO: new. DATA_UID FROM DUAL;

    That is to say, function GENERATE_DATA_UID ('BA_ORG',: new.BA_ORG_ID) first parameter I want apostrophe

    Please help on this

    SELECT GENERATE_DATA_UID ("' |) SQLSTR1 | ''',:new.' ||

    ----

    Ramin Hashimzade

  • A simple stored procedure - select with an if statement returning a cursor

    Hello

    I am creating a simple stored procedure, but having never worked with them, before that I'm not sure what I'm doing wrong.

    Here is my code:

    create or replace
    procedure contact_return(
        v_contact_id IN varchar2,
        p_cursor OUT SYS_REFCURSOR)
    AS
    begin
    
      set sql_statement varchar2(4000) := '
        SELECT URN,
          FIRSTNAME,
          LASTNAME,
          TITLE,
          CREATED_DT,
          AREA_URN,
          MOBILE,
          WORK,
          EMAIL,
          ORG_NAME,
          ADDRESS,
          POSTCODE,
          IN_USE
        FROM CONTACT';
        
      if v_contact_id is not null then
        sql_statement := sql_statement || ' where urn = ' || v_contact_id;
      end if;
      
      open p_cursor for sql_statement;
    end;
    

    It is actually 2 errors:

    • Error (7.3): PL/SQL: statement ignored
    • Error (7.7): PL/SQL: ORA-00922: missing or invalid option

    That seems to be a problem with my line fixed sql_statement, but it looks good for me?

    Thank you

    Do not know what language you are trying to use there for your variable declarations, but it is not PL/SQL.  Looks like you're mixing SQL * more syntax with PL/SQL UltraLite or something.

    Something more in this sense is perhaps what you are looking for...

    create or replace procedure contact_return (v_contact_id IN varchar2

    p_cursor ON SYS_REFCURSOR

    ) AS

    sql_statement varchar2 (4000): = '

    SELECT THE URN,

    FIRST NAME,

    LASTNAME,

    TITLE,

    CREATED_DT,

    AREA_URN,

    MOBILE,

    WORK,

    E-mail

    NOM_ORG,

    ADDRESS,

    Zip code

    IN_USE

    CONTACT

    where urn = nvl(:1,urn)';

    Start

    Open the p_cursor for sql_statement using v_contact_id;

    end;

  • Command SQLPLUS to execute stored procedure

    Hello

    I'm trying to run the command SQLPLUS (CONNECT) to the stored procedure.

    It is throwing the error message below.


    Stored procedure:

    SQL > select use double
    2;

    USER
    ------------------------------
    SYS

    SQL > create or replace
    2 PROCEDURE PROCEDURE1 AS
    3 BEGIN
    4 sqlplus sys/sys@D as sysdba;
    5 - immediate execution "create user 'kkk' identified by 'kkk';
    6 END PROCEDURE1;
    5 m

    CAUTION: Procedure created with compilation errors.

    SQL > show err
    PROCEDURE1 PROCEDURAL errors:

    LINE/COL ERROR
    -------- -----------------------------------------------------------------
    3/9 PLS-00103: encountered the symbol "SYS" when awaits an of the
    Next:
    := . ( @ % ;
    The symbol ': = ' was replaced by 'SYS' continue.

    3/22 PLS-00103: encountered the symbol "UNDER" when awaits an of the
    Next:
    . (* @ & = - +; <>/ at mod is still not rem)
    < an exponent (*) > <>or! = or ~ = > = < = <>and or LIKE2_
    LIKE4_ LIKEC_ between | Member SUBMULTISET_
    The symbol "." has been inserted before "AS" to continue.


    Please let me know if it is possible to do or not.
    If it is possible how is this possible?

    Published by: NGK246 on August 28, 2012 02:21

    NGK246 wrote:
    Now I tried to implement even taking arguments when running in the command prompt, but the OraCallTest.log file is not created.
    Please let me know why is it happening as such.

    Please show it does not work. It works well for me...

    c:\Temp>notepad testing.bat
    
    c:\Temp>more testing.bat
    @echo off
    SET DBUser=%1
    SET DBPass=%2
    SET DBTNS=TEST
    SET LOG=C:\temp\
    
    ECHO spool OraCallTest.log > %LOG%OraCallT.sql
    ECHO set linesize 132 >> %LOG%OraCallT.sql
    ECHO select * from dual; >>%LOG%OraCallT.sql
    ECHO spool off >> %LOG%OraCallT.sql
    ECHO exit >> %LOG%OraCallT.sql
    sqlplus -s "%DBUser%/%DBPass%@%DBTNS%" @%LOG%OraCallT.sql > %LOG%PLTT.log
    
    c:\Temp>testing scott tiger
    
    c:\Temp>more pltt.log
    
    Session altered.
    
    D
    -
    X
    
    c:\Temp>more oracallt.sql
    spool OraCallTest.log
    set linesize 132
    select * from dual;
    spool off
    exit
    
    c:\Temp>more oracalltest.log
    
    D
    -
    X
    
  • helps the stored procedure

    Hi all
    I am creating a simple stored procedure that updates a table which has initially been removed

    CREATE PROCEDURE CLASSTEST_01 IS
    BEGIN

    delete from temp_test_01;

    Select * from TEMP_CLASS_SCORE in temp_test_01;
    END CLASSTEST_01;

    However, it will not create.
    Pls can someone check if there is something wrong with the statement
    Thank you

    There is no need of stored procedure. All you need is:

    delete from temp_test_01;
    insert into temp_test_01 select * from TEMP_CLASS_SCORE;
    

    Or:

    truncate table temp_test_01;
    insert into temp_test_01 select * from TEMP_CLASS_SCORE;
    

    But if you decide to create one:

    CREATE OR REPLACE
      PROCEDURE CLASSTEST_01
        IS
        BEGIN
            delete from temp_test_01;
            insert into temp_test_01 select * from TEMP_CLASS_SCORE;
    END CLASSTEST_01;
    /
    

    SY.

  • Select problem with a statement in the stored procedure oracle

    Hi guys,.

    I am new to oracle. I have a simple sql stored procedure that needs to be converted to oracle. The procedure is,

    CREATE PROCEDURE my_procedure
    Char (4) @my_var = null
    AS

    Select * from my_table where my_variable = @my_var

    I converted this SP as oracle and the convert SP is,

    create or replace
    My_procedure PROCEDURE
    (
    v_my_var in CHAR DEFAULT NULL
    )
    AS

    BEGIN

    SELECT * FROM my_table WHERE my_variable = v_my_var;

    END;

    But the SP above returns an error (Error (13.3): PLS-00428: an INTO clause in the following SELECT statement) when compiling.

    So I used the slider to get the results and send back them. Updated the SP is,

    create or replace
    My_procedure PROCEDURE
    (
    v_my_var in CHAR NULL by DEFAULT,
    cv_1 ON SYS_REFCURSOR
    )
    AS

    BEGIN

    OPEN cv_1 to SELECT * FROM my_table WHERE my_variable = v_my_var;

    END;

    Now, the SP is compiled successfully and return the result set correctly. My doubt is,
    What is the right way to solve the problem that I mentioned above? Is there another way to get the select query result without using a cursor?

    Please advice. Thank you for your help in advance.

    RAM

    Depends on where you are calling from SP.
    I assume you are using a windows client, as you referred to SQL Server.
    The .NET Oracle provider, allowing return of pl/sql types and as you return only all columns in a single line, you could change your procedure to something like this:

    create or replace procedure my_procedure(v_my_var in  char default null
                                            ,cv_1     OUT my_Table%rowtype) as
    
      rt my_table%rowtype;
    begin
    
      SELECT *
      into   rt
      FROM my_table
      WHERE my_var = v_my_var;
    
      cv_1 := rt;
    
    END my_Procedure;
    /
    
  • PL/SQL - Call Out Ref Cursor returned by a stored procedure

    Hello

    I am creating a procedure where a Ref Cursor is defined as an OUT parameter, my question is how to shout that the Ref Cursor when I run for example here is how I want to call my EXEC sql command:

    EXEC film_not_in_stock (2,2,vcur);

    Here is the procedure:

    CREATE OR REPLACE PROCEDURE film_not_in_stock (p_film_id in NUMBER, p_store_id number, vcur ON SYS_REFCURSOR)

    IS

    News sys_refcursor;

    v_cur inventory.inventory_id%TYPE--ou is the same type of column inventory_id

    v_cur sys_refcursor;

    BEGIN

    Heart OPEN to SELECT inventory_id

    INVENTORY

    WHERE film_id = p_film_id

    AND store_id = p_store_id

    AND inventory_id NOT IN (SELECT inventory_in_stock (inventory_id) FROM dual);

    News of FETCH in v_cur;

    OUTPUT WHEN heart % NOTFOUND;

    END;

    /

    I know there are typos in the procedure, you will appreciate if you can help me to put it right.

    Thank you very much!

    Tonya.

    In fact, based on your previous post, function inventory_in_stock returns 0 or 1. If so, there are:

    CREATE OR REPLACE

    PROCEDURE film_not_in_stock)

    p_film_id in NUMBERS

    p_store_id in NUMBERS

    p_cur ON SYS_REFCURSOR

    )

    IS

    News sys_refcursor;

    v_cur inventory.inventory_id%TYPE--ou is the same type of column inventory_id

    v_cur sys_refcursor;

    BEGIN

    OPEN p_cur

    FOR

    SELECT inventory_id

    INVENTORY

    WHERE film_id = p_film_id

    AND store_id = p_store_id

    AND inventory_in_stock (inventory_id) = 0;

    News of FETCH in v_cur;

    OUTPUT WHEN heart % NOTFOUND;

    END;

    /

    SY.

Maybe you are looking for

  • iPod Touch (5th generation) need password after reset

    Hello I bought an iPod for my son's birthday last month and it had a password on it, but then later removed. Last night, the iPod randomly asked a password and then locked my son on his iPod. The old password does not work. I tried to connect the iPo

  • How can I reconfigure media buttons?

    Hello On the left side, I have a few buttons for Internet and sound.How is it possible to configure that if I start the Itunes of its start-up and not Windows Media Player? Thanks for your commentsSincerelyVincent

  • ENVY 4500: cut top printing

    When I print my Crusaders off the coast of the enternet cuts the top line. What is new, its happening recently. I tried running the allignment and scanned this page, but that did not help. I tried printing via a different browser, but the same thing

  • Password for KB888111 patch does not work.

    Original title: 888111 KB Password for the KB 888111 fix does not work Any suggestions?

  • Invalid selected ringtone blackBerry Smartphones?

    Just upgraded my phone for the latest OS and now none of my ringtones or alerts work.  They all say "Invalid ringtone selected, you must perform another selection."  Any ideas on how to fix it? Thanks for any help! Oh, I'm on Sprint, and it is a 3G c