Manipulation of PL/SQL, an overload of functions and NULL

Hello

I am trying to write a package of assistance with the same name of function that takes a different type of settings (VARCHAR2 or NUMBER or DATE) and processing them. Please check the example below.

create or replace package is MY_PACKAGE
performOperation (var1 VARCHAR2) return feature NUMBER;
performOperation (var1 NUMBER) function return NUMBER;
performOperation (var1 DATE) function return NUMBER;
end MY_PACKAGE;

This package works well until I pass a VARCHAR2 or NUMBER or DATE values. If I pass NULL, I get error PL-00307/ORA-06550. Check for null before adoption is not an option. Is there a better way to handle the NULL value inside this package.

Thanks for your help on this.

vbforums wrote:
Thanks for the reply of Solomon.

I prefer not to determine the type of data from the start, I'm too load methods. If it manages the NULL, I could use different names for all three data type

There is no need, unless you use a PL/SQL NULL or NULL SQL function:

SQL> create or replace package body MY_PACKAGE is
  2  function performOperation(var1 VARCHAR2) return NUMBER is begin return 1; end;
  3  function performOperation(var1 NUMBER) return NUMBER is begin return 2; end;
  4  function performOperation(var1 DATE) return NUMBER is begin return 3; end;
  5  end MY_PACKAGE;
  6  /

Package body created.

SQL> set serveroutput on
SQL> declare
  2      v_num number;
  3      v_str varchar2(1);
  4      v_dt  date;
  5  begin
  6      dbms_output.put_line(my_package.performOperation(v_str));
  7      dbms_output.put_line(my_package.performOperation(v_num));
  8      dbms_output.put_line(my_package.performOperation(v_dt));
  9  end;
 10  /
1
2
3

PL/SQL procedure successfully completed.

SQL> 

However, if you use use the PL/SQL NULL or NULL SQL function, you must convert it into an appropriate type as NULL itself is without (the unknown value of an unknown type) type. When NULL is assigned to a variable or a column, it becomes an unknown variable value or a column of data type. This is why PL/SQL can understand an overload.

SY.

Tags: Database

Similar Questions

  • SQL loader by using functions and position

    Hi all, I need help, loading data in my table using sql loader. study the following
    CREATE TABLE er
    (                     
    a1 NUMBER,
    a2 number,
    a3 VARCHAR2(100),
    a4 VARCHAR2(100),
    a5 VARCHAR2(100),
    a6  VARCHAR2(100),
    a7  VARCHAR2(100),
    a8  VARCHAR2(100)
    );
    
    OPTIONS (BINDSIZE=20548000, READSIZE=20548000, STREAMSIZE=20548000, DATE_CACHE=25000,  SKIP=0)
    LOAD DATA
    INTO TABLE er
    APPEND     
    TRAILING NULLCOLS
    (
      a1            POSITION(0001:0021)               ,
      a2            POSITION(0022:0042)       "DECODE(SUBSTR(:a2,1,3),'***',NULL,:a2)"      ,
      a3            POSITION(0043:0053)       ,
      a4            POSITION(0054:0064)          ,
      a5            POSITION(0065:0075)           ,
      a6            POSITION(0076:0086)       ,
      a7            POSITION(0087:0093)      "DECODE(SUBSTR(:a7,1,3),'***',NULL,:a7)"   
    )
    BEGIN
                     0.00 ******************** X          X          X          *X          ****
    END;
    If you look at the data, some fields have a lot of * and some af a bit such as *. I want to load data into a table, and when a field contains all * as the value, I want to set to null. If a field contains a * and alphanumeric, so this value should be as it is.

    in the above example, * must be set to null and * should also be defined with a null value. Note that there is a field with x as this area contain alpha numeric, it must be loaded into the table, as is.  the only time in field must be set to null, it's when the value contains all .

    someone in this forum suggest using to decode, but looks like it doesn't work and I get error when it reads the second field and try to insert into the column number a2.

    is it possible to use regular expressions to find out if a field contains all *. I also want to cut each field as they may contain spaces.
    can be a help for this, use the ctl sqlloader and above?

    You can include regular expressions in you SQL * file the charger control.

    An example can be found here:
    http://www.morganslibrary.org/reference/sqlloader.html
    Demos of 7 and 8 by using the UPPER and DECODE functions to illustrate how do.

  • What is the best way to optimize a SQL query: call a function or doing a join?

    Hi, I want to know what is the best way to optimize a SQL query, call a function inside the SELECT statement, or make a simple join?

    It depends on.  Could be a.  Could be the other.  Could be no difference.  You would need to compare with your tables in your environment with your settings.

    If you put a gun to my head, I was given no other information and required that I answered the question, I would tend to wait that the join would be more effective.  In general, if you can do something in pure SQL, it will be more effective than if you call PL/SQL.

    Justin

  • Expert SQL 1Z0-047: all functions are examined or just groups?

    Review of press of Oracle book says that all functions can be included in the review (Chapter 6 use of the box shows a row functions p.234 review)
    and reffer the manual reference

    And as I see the book and review group (Aggregate), specific einreihig, date on which the ordinary functions of Expressions and page are reviewed.
    With the help of line features unique to customize the output

    Describe the different types of functions that are available in SQL
    Describe the use of the conversion functions
    Use of character, number, date functions in SELECT statements
    -Describe the use of functions of Group
    Identify the Group functions available
    Use the group for aggregate functions
    -Use datetime functions
    -Regular expressions
    of the foregoing, I guess that the bellows are out of the review
    XML
    Data mining

    So what really are the functions examined gtoups?

    So what really are the functions examined gtoups?

    Nowhere (or at least anywhere outside the Oracle education) is a list of all of the specific functions that will be under review. Besides, "will be" more properly would be written "could be" since all takers single review never sees all possible questions. A given function may be on the test for some people and not others.

    When deciding on what features to include, what I've done (and I suppose that Steve did) was to look through the different functions of a specific type (i.e. conversion functions) and the weight of each based on how the function is common in my experience. I have included these functions which I consider to be seen more often and so that no matter what SQL expert expected to know on top of their head. That said, the review Expert SQL takes pleasure in the dark. I've seen this most often in variations of syntax, but it is possible that review manufacturers choose a function to include simply because it is rarely used. While I don't remember all these appearing on the exam that I took, I can't exclude that possibility and so my guide at the end of the functions section States it much more listed there in the SQL Reference Guide which peuvent appear in the review.

    That said, learn the ins and outs of more functions that you might really need to review is not a bad thing. Because you indicated that you are interested in the real expertise rather than the skills of paper, limit you just to the focus of the review is not intuitive. I guarantee you there are a lot of things I know about SQL for years to work in the language that are not on the subjects of examination.

  • Any difference between the separate function and aggregation in sql query cost?

    Hello
    I've run many models sql stmts - such as:
    one) using a single table
    (b) using the two tables, using simple joins or outer joins

    but I didn't notice a difference in sql stmts in cost and implementation plan...
    In any case, my colleague insists on only using the aggregate function is less expensive compared to
    separate... (something I've not confirmed, that is why I believe that they are exactly the same...)

    For the situation described above under 1 sql... We could for example use
    select distinct deptno
    from emp
    select count(*), deptno
    from emp
    group by deptno
    select distinct owner, object_type from all_objects
    select count(*), owner, object_type from all_objects
    group by owner, object_type
    Have you ever found no difference between the two...?

    Note: I use Ora DB 10g v2.

    Thank you
    SIM

    Alexandre Gelin says:
    function separate and aggregation are for different uses and can give the same result, but if you use the aggregate function to get the separate records, it will be expensive...

    really? I find them almost identical to 11g. Actually GROUP BY is almost always more fast for me in the old days.

    article about this askTom Re: any difference between the separate function and aggregation in sql query cost?
    This applies mainly to the older oracle versions http://www.oracle.com/technology/products/rdb/pdf/distinct_derivedtables_groupby_sort_tech_article.pdf

  • Problem inserting new line in a VO with SQL functions and subqueries

    Hello

    I use JDeveloper 10.1.3.4 and and stuck with insertion of a new line when the values to insert into some fields of the new line are returns of SQL functions and subqueries.

    At the sqlplus prompt, the following sql statement is tested and developed successfully:
    insert into VALIDATIONS values (
       '111223333', 'JANE', 'DOE',
       SYSDATE,
       (select to_char(sysdate, 'yymmdd') from dual)||
       (select to_char(count(TRANSACTION_DATE)+1,'fm0999') from VALIDATIONS
          where trunc(TRANSACTION_DATE) = to_char(sysdate))
    );
    Note that the values for the fields of 4th and 5th are returns of subqueries and SQL functions.

    Ideally, it would be simple to assemble a SQL and executed him as he did to the old way of servlet:
    String sql = "insert into VALIDATIONS values ('" + id + "', '" + firstName + "', '" + lastName + "', SYSDATE, (select to_char( ......)))";
    statement.executeUpdate(sql);
    I'm not sure it can be done in JDeveloper, and it was not found in the developer's guide. What I found was rather:
    // 1. Find the ServiceRequests view object instance.
    ViewObject svcReqs = am.findViewObject("ServiceRequests");
    // 2. Create a new row and insert it into the row set
    Row newSvcReq = svcReqs.createRow();
    svcReqs.insertRow(newSvcReq);
    // 3. Show effect of entity object defaulting for Status attribute
    System.out.println("Status defaults to: "+newSvcReq.getAttribute("Status"));
    // 4. Set values for some of the required attributes
    newSvcReq.setAttribute("CreatedBy",308); // Nancy Greenberg (user)
    Date now = new Date(new Timestamp(System.currentTimeMillis()));
    newSvcReq.setAttribute("RequestDate",now);
    newSvcReq.setAttribute("ProdId",119); // Ice Maker
    newSvcReq.setAttribute("ProblemDescription","Cubes melt immediately");
    // 5. Commit the transaction
    am.getTransaction().commit();
    In my case, it would be OK for the first three fields as shown below (in the code of transactionsRecords is a display object). But what about the 4th and 5th fields?
    Row newTransaction = transactionsRecords.createRow();
    transactionsRecords.insertRow(newTransaction);
    newTransaction.setAttribute("StudentId", id);
    newTransaction.setAttribute("FirstName", firstName);
    newTransaction.setAttribute("LastName", lastName);
    
    newTransaction.setAttribute("TransactionDate", <how to put "SYSDATE" here?>);
    newTransaction.setAttribute("ConfirmNumber", <how to put subqueries here?>);
    A big thank you to those who know or have experience before!


    Newman

    Newman,
    You can do this via a procedure call. This technique is described here
    I guess you can't do this directly in the EO or VO.
    You can do it the old way to create a prepared directly query and call it as you described. To get the declaration use getDBTransaction () .createPreparedStatement (...) method available in the module of your application.
    Be aware of the implications using the given solution. The framework doesn't know anything of what you are doing. So to see the changes that you used to update the tables that you change.

    Timo

  • Passage of tables through multiple functions and PL/SQL procedures

    I am now a great application of PL/SQL. There is a main procedure which is initially called who subsequently passes information to other PL/SQL functions and procedures. Ultimately an error code and the string is passed to PUT_LINE so it can be displayed. I want to be able to do is to have a table that stores an error code and a string for every error it then go through each of the procedures and functions. This would mean passing these codes and the strings of a function to a function within the pl/sql application. What would be the best way to implement this and is it possible to move heavy or folders to other PL/SQL functions? Thank you.

    Here is a simulation->

    satyaki>
    satyaki>select * from v$version;
    
    BANNER
    ----------------------------------------------------------------
    Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - Prod
    PL/SQL Release 10.2.0.3.0 - Production
    CORE    10.2.0.3.0      Production
    TNS for 32-bit Windows: Version 10.2.0.3.0 - Production
    NLSRTL Version 10.2.0.3.0 - Production
    
    Elapsed: 00:00:00.20
    satyaki>
    satyaki>
    satyaki>create or replace type n_array is table of number;
      2  /
    
    Type created.
    
    Elapsed: 00:00:07.10
    satyaki>
    satyaki>CREATE OR REPLACE PROCEDURE Get_Array(array_in IN n_array,
      2                                        array_out OUT n_array)
      3  IS
      4  BEGIN
      5    array_out := n_array();
      6    FOR i IN 1..array_in.count
      7    LOOP
      8      array_out.extend;
      9      array_out(i) := array_in(i) * 2;
     10    END LOOP;
     11  END Get_Array;
     12  /
    
    Procedure created.
    
    Elapsed: 00:00:00.89
    satyaki>
    satyaki>
    satyaki>Create or Replace Procedure Set_Array(myArray IN n_array)
      2  is
      3    i   number(10);
      4    rec emp%rowtype;
      5    w n_array:=n_array(1200,3200);
      6    bucket n_array := n_array();
      7  Begin
      8    Get_Array(w,bucket);
      9
     10    for i in 1..myArray.count
     11    loop
     12      select *
     13      into rec
     14      from emp
     15      where empno = myArray(i);
     16      dbms_output.put_line('Employee No:'||rec.empno||' Name:'||rec.ename);
     17      for j in 1..bucket.count
     18      loop
     19        dbms_output.put_line('Commission Sub Type: '||bucket(j));
     20      end loop;
     21    end loop;
     22  End Set_Array;
     23  /
    
    Procedure created.
    
    Elapsed: 00:00:01.33
    satyaki>
    satyaki>
    satyaki>select * from emp;
    
         EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM     DEPTNO
    ---------- ---------- --------- ---------- --------- ---------- ---------- ----------
          9999 SATYAKI    SLS             7698 02-NOV-08      55000       3455         10
          7777 SOURAV     SLS                  14-SEP-08      45000       3400         10
          7521 WARD       SALESMAN        7698 22-FEB-81       1250        500         30
          7566 JONES      MANAGER         7839 02-APR-81       2975                    20
          7654 MARTIN     SALESMAN        7698 28-SEP-81       1250       1400         30
          7698 BLAKE      MANAGER         7839 01-MAY-81       2850                    30
          7782 CLARK      MANAGER         7839 09-JUN-81       4450                    10
          7788 SCOTT      ANALYST         7566 19-APR-87       3000                    20
          7839 KING       PRESIDENT            17-NOV-81       7000                    10
          7844 TURNER     SALESMAN        7698 08-SEP-81       1500          0         30
          7876 ADAMS      CLERK           7788 23-MAY-87       1100                    20
    
         EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM     DEPTNO
    ---------- ---------- --------- ---------- --------- ---------- ---------- ----------
          7900 JAMES      CLERK           7698 03-DEC-81        950                    30
          7902 FORD       ANALYST         7566 03-DEC-81       3000                    20
    
    13 rows selected.
    
    Elapsed: 00:00:00.28
    satyaki>
    satyaki>declare
      2    v n_array:=n_array(9999,7777);
      3  begin
      4    Set_Array(v);
      5  end;
      6  /
    Employee No:9999 Name:SATYAKI
    Commission Sub Type: 2400
    Commission Sub Type: 6400
    Employee No:7777 Name:SOURAV
    Commission Sub Type: 2400
    Commission Sub Type: 6400
    
    PL/SQL procedure successfully completed.
    
    Elapsed: 00:00:00.15
    satyaki>
    satyaki>
    

    Kind regards.

    LOULOU.

  • How to move the functions and procedures of packages in a schema?

    Hello

    I have less than the needs for a work at home and my question is if anyone can point me in the right direction to find documentation that can help me solve below. Any information will be appreciated. Thank you.

    Write procedures and functions (included or not in packets) as .txt or .sql scripts. Once they have been launched in Developer SQL they should, in addition, the functions and procedures of packages in the current schema. If the current schema contains only 2 packages, pac1 (p11, p12 procedures and functions f11, f12, f13) and pac2 (contains the p21 following procedures, p22, p23 and f21 and functions f21 (case of overload), running the scripts produce the following effects:)

    • Procedures p11, p12, p21, p22, p23, and f11, f12 and f13 functions will be created in the current schema.
    • PAC2 will contain 2 instances of the function of overload-f21; they will be kept in the package, without be created in the current schema. If all overloaded procedures/functions will be kept in their original packaging
    • If pac1 contains variables, cursors, and public types, keep us only the details of the package (and remove the body); usually if the packages contain no overloaded functions or procedures the body will be removed and if no variable, cursors, types of public then we will remove the header.
    • If in the triggers, procedures and functions we will call procedures/functions packages (procedures and functions moved into the current schema) they reference will need to be updated (via editing the body or recompilation) for example if pa1.p12 will be replaced with p12.
    • Scripts must have numbers in the next series (01... n) and the characters that explain the content.

    My only advice would be to remember that these are public forums and if YOU can find them, therefore cannot your instructors.

    In addition, those are horrible procedure names and function

    This mission seems to be around to overload the pl/sql objects and... prioritize a research on Oracle documentation around overhead and legacy
    http://docs.Oracle.com/CD/B28359_01/AppDev.111/b28371/adobjplsql.htm#i21148

  • ORA-00904 during execution of the functions and procedures (IDE version 4.1.0.19)

    Recently, I updated my Oracle SQL Developer to the latest version (see below) and now when I try to run the function or procedure of the IDE, I had an alert with the error: "ORA-00904:"OBJECT_ID": invalid identifier." Code provider 904 ". Previous version of IDE works pretty well. What is the problem?

    Oracle SQL Developer 4.1.0.19

    Version 4.1.0.19

    Build a HAND - 19.07

    It seems that OBJECT_ID added to ALL_PROCEDURES for the 10g DB version, but after the version you have (10.2.0.1.0).  I don't have a link to the documentation specific to hand Oracle, but see the last comment by Steven Feuerstein in the next blog...

    PL/SQL challenge: ALL_PROCEDURES changes over version (5980)

    Typically when generation SQL for a particular version of the DB with SQL Developer, only major (10) and (more rarely) secondary numbers (2) gets checked, if your problem is one of those borderline cases that are easy to miss and less likely to get fixed. Whenever a customer has a specific need to use an older version, Oracle expects usually only the last set of patch (for example, 10.2.0.5) would be used.

  • function and packages

    Hi friends,

    I have a requirement where in I need decode my source table values while inserting in my target table. I usually do my task by performing functions (don't use case and decode). My first question is

    (1) is using the function to accomplish these tasks is good. I have several of these conversion requirements.
    (2) Clubbing subprogrammes togther in packages is a good habit. But what should be the number of these subprogrammes. I can club togther 100 of this togther functions (a function of the average is 50 lines)? If this is not the case, what should be the thoughts of segregation?
    (3) are the oracle integrated like sqrt, length etc. deterministic functions?

    This code represents a typical requirement of the mine where in I map my name of source country in the target
    ID of country when migrating my data from the source to the target.

    create table source 
    (
    emp_id number,
    empname varchar2(100),
    sal number,
    country varchar2(100)
    );
    
    
    insert into source values (1,'ALEX',1000,'US');
    Insert into source values (2,'RAHUL',2000,'IND');
    Insert into source values (3,'KARTIK',3000,'IND');
    Insert into source values (4,'SHADOW',5000,'US');
    insert into source values(5,'LOUI',1500,'JAP');
    
    
    Create table source_country_code
    (
    country varchar2(100),
    abbrv  varchar2(100),
    area number,
    climate varchar2(100)
    );
    
    insert into source_country_code values ('UNITED STATES','US',10000,'COLD');
    insert into source_country_code values ('INDIA','IND',100000,'HOT');
    insert into source_country_code values ('JAPAN','JAP',1000000,'MODERATE');
    
    
    
    
    Create table target_country_code
    (
    country_id number,
    descr  varchar2(100),
    density number,
    weather varchar2(100)
    );
    
    insert into target_country_code values (101,'this is descrition txt 1',1001,'COLD');
    insert into target_country_code values (102,'this is descrition txt 2',1001,'HOT');
    insert into target_country_code values (103,'this is descrition txt 3',1001,'MODERATE');
    
    
    
    create table target
    (
    emp_id number,
    empname varchar2(100),
    sal number,
    country_id number
    );
    I generally functions for this kind of mappings. I have several of these requirements as indicated above and the
    cardinality of data is high.
    create or replace function transform (in_src_country varchar2) return number deterministic
    as
    l_country_id number;
    l_climate varchar2(1000);
    begin
    
    select climate into l_climate from source_country_code
       where upper(abbrv)=upper(in_src_country);
       
    select country_id into l_country_id
    from target_country_code
    where upper(weather)=upper(l_climate);
    
    return(l_country_id);
    exception 
    when no_data_found then
    return null;
    end;
    last step,

    so, what I usually do is

    insert into target
    Select emp_id, empname, sal, transform (country) in the source;



    As always, thank you

    Rahul

    Published by: Rahul K on 5 June 2013 10:51

    No technique is universally good or bad universally. You must understand your needs, the compromise and what you're trying to optimize for.

    If you don't care anything else you are looking for the absolute fastest performance, reduce what you have to do in PL/SQL is a good idea. Most of the people and most of the systems, however, prefer to have code that is a bit slower if it makes the code easier to maintain and easier to write or minimizes the number of places that the code is duplicated. If you attempt to load a data warehouse of company with billions of new lines every night, you're as almost exclusively worry about raw performance. And, if you design correctly, there is that one way to load any particular item of data, you don't have to worry about code duplication because there will always be an INSERT statement that inserts data in a particular table. If you build an OLTP application, on the other hand, it is very likely that there will be many places where you want to do something like search for a value and you are much less concerned about raw performance you're on maintainability and ensure that you do not duplicate the code. In these cases, well-designed functions and procedures are well worth the return miners (so if you do a query of single line as most OLTP systems are generally easier to treat if you write DSS queries that return millions of processing lines billionr lines.

    Justin

  • Same algorithm in function and procedure so that one will be better?

    Why is better to pl sql function calculates a value instead of the procedure?
    If I apply the same algorithm in function and procedure while one will perform better?

    Siddharth Singh says:
    Oracle documentation

    http://docs.Oracle.com/CD/B10500_01/AppDev.920/a96624/08_subs.htm

    This:

    Generally, you use a procedure to perform an action and a function to calculate a value.

    Does not mean that the function are better to calculate a value, but you usually use functions to calculate a value.

    Usually, a function is can be more useful if you plan to use in a query.
    that is to say:

    SELECT myfunc(col1) from mytable;
    

    That you can't do with a procedure. Functions are also usually limited to the returning a single value, while procedures may have several OUTPUT parameters.

    Kind regards.
    Al

    Published by: Alberto Faenza on 21 November 2012 15:31

  • How to perform a function and return the result in a variable of liaison

    Hello

    I'm trying to calculate the sum of the salaries of all persons with a particular using a function JOB_ID TOTAL_INCOME (v_job_id).

    create or replace function total_income
    + (v_job_id in VARCHAR2) +.
    Number IS BACK
    v_total number (6);

    cursor get_sal is
    Select the pay of employees
    where job_id = v_job_id;
    BEGIN
    v_total: = 0;
    for emp in get_sal
    loop
    v_total: = v_total emp.salary; +.
    end loop;

    dbms_output.put_line (' Total salary ' | v_job_id |' is: ' | v_total);
    Return v_total;
    END;

    Now I woud like to perform this function and assign the value returned in a variable binding test_sal

    test_sal variable number (6)
    SELECT total_income ('AD_VP') in: test_sal FROM DUAL;
    dbms_output.put_line (' Sal Total :'||: test_sal);

    This returns the errors below:

    SELECT total_income ('AD_VP') in: test_sal FROM DUAL
    *+
    Error on line 0
    ORA-01036: illegal variable name/number

    dbms_output.put_line (' Sal Total :'||: test_sal);
    Error on line 3
    ORA-00900: invalid SQL statement

    Could someone help me what could be the problem? Thanks for your time...

    Hi Kiran and welcome to the forum,

    You mix SQL and PL/SQL

    It's the way in which SQL:

    SQL> SELECT total_income('AD_VP') FROM DUAL;
    
    TOTAL_INCOME('AD_VP')
    ---------------------
                      123
    1 row selected.
    

    It comes to PL/SQL in SQL * more

    SQL> variable test_sal number
    SQL> execute :test_sal := total_income('AD_VP')
    PL/SQL procedure successfully completed.
    SQL> exec dbms_output.put_line('Total Sal:'||:test_sal)
    Total Sal:123
    PL/SQL procedure successfully completed
    

    Concerning
    Peter

  • Doubts in functions and procedures

    Hello world

    Can someone tell the exact differences between function and procedure?

    My doubts are
    1. If the procedure can return and is not necessary it must return a value (in other words, if we want to come back and is not as one can write procedure) then why do we need to function?

    2. I tried to call a function that updates a table in the code, I got an error saying that the function does not use DML.

    3. I want to know the combination that
    procedure a. can call a function and vice versa?
    b. function (which uses DML instructions) can be called from sql statement?
    and if all other combinations are there let me know with reasons.

    Thanks in advance,
    Vinay

    Have you looked at in the [reference Guide and the User Guide for PL/SQL | http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14261/toc.htm] already?
    http://download.Oracle.com/docs/CD/B19306_01/AppDev.102/b14261/subprograms.htm#i4075
    http://download.Oracle.com/docs/CD/B19306_01/AppDev.102/b14261/subprograms.htm#i4074

    (1) for example: functions can be used in SQL, procedures cannot.
    (2) generally, the methods are used for DML.
    It depends on how you are performing the function:

    hoek&XE> create table t as select 1 col from dual;
    
    Tabel is aangemaakt.
    
    hoek&XE> create or replace function f
      2   return number
      3   as
      4    num number;
      5   begin
      6    update t
      7    set col = 2;
      8    num := sql%rowcount;
      9   return(num);
     10  end;
     11  /
    
    Functie is aangemaakt.
    
    hoek&XE> select f from dual;
    select f from dual
           *
    FOUT in regel 1:
    .ORA-14551: cannot perform a DML operation inside a query
    ORA-06512: at "HOEK.F", line 6
    
    hoek&XE> 
    
    hoek&XE> var num number
    hoek&XE> exec :num := f;
    
    PL/SQL-procedure is geslaagd.
    
    hoek&XE> print :num
    
           NUM
    ----------
             1
    
    hoek&XE> select * from t;
    
           COL
    ----------
             2
    

    Yes 3A)
    No. 3B), see 2.

  • SQL Analysis: Extract column expression and SQL query tags

    Hi all

    I have a requirement and posted earlier reg. this.
    An SQL statement must be parsed and column names must be extracted separately.
    I can't use dbms_sql. I need to extract the names of columns through manipulating strings in PL/SQL only.
    I don't have to validate the SQL code.

    for example.
    SELECT EMPNO, Upper (ENAME), DEPTNO Emp_Name, DECODE (Deptno, 10, 'ACCOUNTING', 20, 'HR', 'OTHER') Dept_Name OF double

    Output should be,.

    Column names
    --------------------
    (1) EMPNO
    (2) Emp_Name Upper (ENAME)
    (3) DEPTNO
    (4) Dept_Name DECODE(Deptno,10,'ACCOUNTING', 20,'HR','OTHERS')

    How can I retrieve the names of columns using PL/SQL for the above format?
    Pls help.

    Kind regards
    Sam

    If the requirement is to have them come forward...

    SQL> ed
    Wrote file afiedt.buf
    
      1  declare
      2    v_sql VARCHAR2(4000) := q'[SELECT EMPNO, Upper(ENAME) Emp_Name, DEPTNO, DECODE(Deptno,10,'ACCOUNTING', 20,'HR','OTHERS') Dept_Name FROM Dual]';
      3    v_cols VARCHAR2(4000) := regexp_replace(v_sql, 'SELECT (.*) FROM .*', '\1');
      4    PROCEDURE parse_col(p_cols IN VARCHAR2, lvl NUMBER) IS
      5      v_str VARCHAR2(4000);
      6      v_br  NUMBER := 0;
      7      v_pos NUMBER := 1;
      8    begin
      9      LOOP
     10        EXIT WHEN v_pos > length(p_cols);
     11        CASE SUBSTR(p_cols,v_pos,1)
     12          WHEN '(' THEN
     13            v_br := v_br + 1;
     14          WHEN ')' THEN
     15            v_br := v_br - 1;
     16          WHEN ',' THEN
     17            IF v_br = 0 THEN
     18              DBMS_OUTPUT.PUT_LINE(to_char(lvl,'fm99')||': '||trim(v_str));
     19              parse_col(SUBSTR(p_cols,v_pos+1),lvl+1);
     20              v_str := NULL;
     21              EXIT;
     22            END IF;
     23          ELSE NULL;
     24        END CASE;
     25        v_str := v_str || SUBSTR(p_cols,v_pos,1);
     26        v_pos := v_pos + 1;
     27      END LOOP;
     28      IF v_str IS NOT NULL THEN
     29        DBMS_OUTPUT.PUT_LINE(to_char(lvl,'fm99')||': '||trim(v_str));
     30      END IF;
     31    end;
     32  begin
     33    parse_col(v_cols,1);
     34* end;
    SQL> /
    1: EMPNO
    2: Upper(ENAME) Emp_Name
    3: DEPTNO
    4: DECODE(Deptno,10,'ACCOUNTING', 20,'HR','OTHERS') Dept_Name
    
    PL/SQL procedure successfully completed.
    
    SQL>
    
  • Resolution of delay function and the borough

    A small question about the delay () function.  The resolution is apparently 1ms according to the help file.  What happens if I pass a value with a fraction of a mlliseconds, say something like:

    Delay(0.0128);
    

    For 12.8ms.  Does round to the top and the 13th month of delay?  Or round to 12ms?  Undefined?  Something else?

    Thank you.

    Hey tstanley,

    I did some research on the function and it seems that the feature is for timer trying to get closer to the 12.8ms, but because the resolution is only 1 ms, it could still be +/-1ms to the value that you enter. So in some of our tests, it was waiting for 13.8ms, since it is in the accuracy of the clock 1ms.

    Because Windows is not a real-time operating system, there are several factors that could keep the timer delay for 13.8ms - other processes can run on the machine and anticipate the process timer, for example. If this level of accuracy is required, you can consider using the CVI RT module on a system in real-time.

Maybe you are looking for

  • How to return to the position after recording Garageband?

    After recording something in Garage band, he returned at the beginning, I have to press return on the keyboard, how can I do it automatically go to the beginning or when I want to record from?

  • D110A appears as a Scanner "Hello".

    My new d110A is connected to my network, but when I go into the preferences panel "Print and Fax" to add the device, I can see, but it appears as a Scanner "Hello". So, I can't print to the printer. What should I do to print on this unit? I use OS X

  • Computer laptop G62 won't boot disk boot

    Need to recover the computer.  I ordered a HP boot disk.  The drive arrived and my laptop G62 reserve not boot disk.  I checked the bios and it is configured to boot from the CD.  I also started in safe mode and cannot locate an autorun exe when I st

  • How to pause / stop the backup of Windows 7

    I'm 250 GB of mainly files mp3 and jpeg on a 500 G USB backup hard drive. The backup has been ongoing for 48 hours now and is (according to the progress bar) 5% full. The option to display details do not display anything. I want to cancel the backup

  • Compatibility of the versions of oracle with RHEL versions

    where can I find a document on the COMPATIBILITY of oracle 11.2.x with RHEL 5, 6 in the oracle support?