Can some selection conditions as PL/SQL procedure input parameters

Dear All,
I need to write a PL/SQL procedure so as to compute the different query only by changing the input parameters. But those input parameters need to be like a PL/SQL table selection conditions. Like:
one of the query I need two conditions:
customers.zip = 60606
customers.zip = employees.zipMy procedure can compute the query like:
select customers.cno, cname, employees.eno, ename
from customers, orders, employees
where customers.cno = orders.cno and
      employees.eno = orders.eno and
      C; 
where C is the conjunction of the conditions in the input parameter.
Please help and thanks in advance!

Well, it's easy enough to do what you want....
SQL> conn scott/tiger
Connected.
SQL> CREATE OR REPLACE FUNCTION flexi_q (pn_deptno IN NUMBER, pv_string IN VARCHAR2 := NULL)
  2  RETURN sys_refcursor AS
  3    return_value sys_refcursor;
  4  BEGIN
  5    IF pv_string IS NULL THEN
  6          OPEN return_value FOR SELECT * FROM emp WHERE deptno = pn_deptno;
  7    ELSE
  8          OPEN return_value FOR 'SELECT * FROM emp WHERE deptno = :1 AND '
  9          ||pv_string USING pn_deptno; 
10    END IF;
11    RETURN return_value;
12  END;
13  /
Function created.
SQL> var rc refcursor
SQL> exec :rc := flexi_q(30)
PL/SQL procedure successfully completed.
SQL> print rc
     EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM
    DEPTNO
      7499 ALLEN      SALESMAN        7698 20-FEB-81       1600        300
        30
      7698 BLAKE      MANAGER         7839 01-MAY-81       2850
        30
      7900 JAMES      CLERK           7698 03-DEC-81        950
        30
      7654 MARTIN     SALESMAN        7698 28-SEP-81       1250       1400
        30
      7844 TURNER     SALESMAN        7698 08-SEP-81       1500          0
        30
      7521 WARD       SALESMAN        7698 22-FEB-81       1250        500
        30
6 rows selected.
SQL> exec :rc := flexi_q(30, 'SAL > 1400')
PL/SQL procedure successfully completed.
SQL> print rc
     EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM
    DEPTNO
      7499 ALLEN      SALESMAN        7698 20-FEB-81       1600        300
        30
      7698 BLAKE      MANAGER         7839 01-MAY-81       2850
        30
      7844 TURNER     SALESMAN        7698 08-SEP-81       1500          0
        30
SQL> The real question is: do you really want to do this? Fundamentally you are handing over control of your app to any nimrod who thinks they know how to write SQL. It's just about allowable for them to add simple restrictions but they could add in anything - correlated sub-queries, extravagant sorts, etc. Even if they don't deliberately exploit this hole you still have a fundamentally untunable part of your app.
It would be much better to have some additional parameters that allows the users to choose from several off-the-peg queries. If you have a user demanding the ability to write "any report I need" I recommend talking to them. The chances are they simply have a pet query, probably embodied in an Excel spreadsheet, they run once every month. Give them a view to meet that need and they'll be happy.
Cheers, APC

Similar Messages

  • Running Multiple SQL in a Single Worksheet: Can I Selectively Run a Single SQL and Append Output?

    In any release of SD, if I have a single worksheet containing 10 sqls. Is it possible to place the cursor on any of the sql and run only that sql, yet, append its output to existing output window. I can then select another sql and execute it and keep appending output. In other words, do not clear existing output or start a new output tab.
    As it exists today (in any release), I can either 'run script' which does append, but it executes all the sql (non-selective). Alternately, I can 'run statement' to selectively run a single sql, but it will clear the output window (or if pinned), start a new one. None of this is what I want.
    Thank you.

    Select the query you want to run. Execute it via F5. Then highlight the next query and repeat.
    The output will append to the Script Output panel.
    There's no way to get 2 queries to share a grid, unless you were to run them as a single query a la UNION.

  • How to pass values to select clause in PL/SQL procedure

    Am relatively new to PL/SQL programming and ran into the following issue...
    Table
    EMP_MASTER
    ID VARCHAR2(10);
    FIRSTNAME VARCHAR2(20);
    DATA FOR EMP_MASTER
    '1','SCOTT'
    '2','TIGER'
    I ran the following SQL Query
    SELECT COUNT(*) FROM EMP_MASTER WHERE FIRSTNAME IN ('SCOTT','TIGER');
    This select Query is working fine and we get the count = 2 as
    expected. Now I want a procedure for the same fn()
    CREATE OR REPLACE PROCEDURE TEST_EMP_MASTER(NAMELIST IN VARCHAR2)
    IS
    CNT NUMBER := 0;
    BEGIN
    SELECT COUNT(*) INTO CNT FROM EMP_MASTER WHERE FIRSTNAME IN (NAMELIST);
    DBMS_OUTPUT.PUT_LINE('Output-->NAMELIST:'||NAMELIST||':cnt:'||cnt);
    END;
    Now when I test the procedure by passing just one value its working
    fine. But when I want to pass multiple values, it doesnt work!
    set serveroutput on;
    i.e exec TEST_EMP_MASTER('SCOTT'); Works and the output is
    Output--->NAMELIST:SCOTT:cnt:1
    but don't get the expected output for exec TEST_EMP_MASTER('SCOTT,TIGER');
    I understand that the IN modifier in the WHERE clause expects the
    values as 'Value1','value2'....I tried different combination by the
    passing the values with quotes '''value1'',''value2'''.....but no
    success

    Select  e.*
    From EMP_MASTER e;
            ID     FIRSTNAME
    1     1     SCOTT
    2     2     TIGER
    3     3     CAT
    4     4     MOUSE
    SQL> create or replace procedure count_emp_master (p_namelist VARCHAR2)
      2  AS
      3     v_namelist   VARCHAR2 (1000) := p_namelist;
      4     v_name Varchar2(100);
      5     v_count Number := 0;
      6     p_count_emp  Number := 0;
      7  BEGIN
      8     v_namelist := ',' || v_namelist || ',';
      9 
    10     FOR cur IN 1 .. LENGTH (v_namelist) - LENGTH (REPLACE (v_namelist, ',', '')) - 1
    11     LOOP
    12        v_name := (SUBSTR (v_namelist,
    13                          INSTR (v_namelist, ',', 1, cur) + 1,
    14                          INSTR (v_namelist, ',', 1, cur + 1)
    15                          - INSTR (v_namelist, ',', 1, cur) - 1
    16                         ));
    17     Select Count(1)
    18     Into v_count
    19     From emp_master
    20     Where FIRSTNAME =  v_name;
    21 
    22     p_count_emp := p_count_emp + v_count;;
    23 
    24     END LOOP;
    25 
    26     dbms_output.put_line ('namelist --> '||p_namelist ||'p_count_emp -->'||p_count_emp);
    27  END count_emp_master;
    28  /
    Procedure created
    SQL> exec count_EMP_MASTER('SCOTT');
    namelist --> SCOTTp_count_emp -->1
    PL/SQL procedure successfully completed
    SQL> exec count_EMP_MASTER('SCOTT,TIGER');
    namelist --> SCOTT,TIGERp_count_emp -->2
    PL/SQL procedure successfully completed
    SQL> exec count_EMP_MASTER('SCOTT,TIGER,CAT');
    namelist --> SCOTT,TIGER,CATp_count_emp -->3
    PL/SQL procedure successfully completed
    SQL> exec count_EMP_MASTER('SCOTT,TIGER,CAT,MOUSE');
    namelist --> SCOTT,TIGER,CAT,MOUSEp_count_emp -->4
    PL/SQL procedure successfully completed
    SQL> Message was edited by:
    Nicloei W

  • FND_REQUEST PL/SQL procedure with parameters

    Hi guys
    I have created a concurrent program, using PL/SQL procedure which has 2 in parameters. I am trying to call the concurrent program using
    v_req_id :=FND_REQUEST.SUBMIT_REQUEST('INV','OMS_POP_INVVALUES_P',
    NULL,SYSDATE,FALSE,l_on_date, l_org_id,
    NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
    NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
    NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
    NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
    NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
    NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
    NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
    NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
    NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
    NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL
    COMMIT;
    However, the concurrent program always failing with
    **Starts**26-AUG-2013 14:02:31 ORACLE error 6550 in FDPSTP Cause: FDPSTP failed due to ORA-06550: line 1, column 7: PLS-00306: wrong number or types of arguments in call to 'OMS_POP_INVVALUES_P' ORA-06550: line 1, column 7: PL/SQL: Statement ignored
    and I doubt it is because the database procedure call is not proper.
    I have set four parameters with the concurrent program, as they were with the procedure itself, which are
    p_on_date IN DATE, p_org_id IN NUMBER, errbuff   OUT VARCHAR2,retcode   OUT VARCHAR2
    Please help
    regards,
    raj

    Okay I fixed the problem by
    1. Changing the order of parameters with Procedure like following
    CREATE OR REPLACE PROCEDURE OMS_POP_INVVALUES_P (
    errbuff   OUT VARCHAR2,retcode   OUT NUMBER, p_on_date IN DATE, p_org_id IN NUMBER)
    IS
    and then changing the concurrent program call like following
    l_req_id :=
          fnd_request.submit_request('INV','OMS_POP_INVVALUES_P',
                                                                        NULL,SYSDATE,FALSE,l_in_date, l_org_id,CHR(0));
       :SYSTEM.Message_Level := '25';
       COMMIT;
    after removing all the parameters from the program parameter list. No need to pass any value for errbuff and retcode, just pass other parameters and end the parameter list with CHR(0). Hope this is useful for somebody else out there.
    Regards,
    raj

  • Unable to use two SQL choices Input parameters in Production Reporting 9.0

    Hi Experts, <BR>I am unable to use two parameters as SQL Choices in Production Reporting. When i use only 1 SQL Choice parameter, it works fine but when i use more than one SQL Choice parameter, it gives error. It works fine in Production Reporting Server but when i publish it on System9 workspace, it doesn't work.<BR><BR>any help would be appriciated.<BR><BR>Thanks & Regards<BR>Arpit Shanker

    Azeroth wrote:
    @Twinkle.. it doesnt work
    SQL> create table ignore_columns
      2  (a varchar2(90),
      3  b varchar2(90));
    Table created.
    SQL> CREATE OR REPLACE PROCEDURE
      2   input_columns
      3   (
      4   table_name IN user_tab_columns.table_name%TYPE,
      5   column_list IN VARCHAR2
      6   ) IS
      7   stmt VARCHAR2(3000);
      8   BEGIN
      9   stmt := 'INSERT INTO ignore_columns VALUES (:1,:2)';
    10 
    11   EXECUTE IMMEDIATE stmt using table_name,column_list;
    12 
    13   END;
    14   /
    Procedure created.
    SQL> execute input_columns('HELL', 'HELLO');
    PL/SQL procedure successfully completed.
    SQL> select * from ignore_columns;
    A
    B
    HELL
    HELLOTwinkle

  • Can't select the new Azure sql service tiers when creating a new database or upgrading an existing one

    Hi all,
    I have set up the preview for the new Azure SQL tiers on both of the subscriptions we have for Azure. The one under my MSDN subscription to and a pay as you go subscription
    The pay as you go subscription works fine but when I try to upgrade an existing Azure sql database or create a new one on my MSDN subscription it doesn't give me the option of the new tiers.
    Using the new portal it says I need to sign up to the preview, but I already have and when I go to try to add a new subscription to the preview for Azure SQL it says all my active subscriptions are on the preview.
    Any idea what the issue could be?
    Cheers
    Ash

    Hi,
    Apologies for the inconvenience.
    I suggest you open a Billing Support Ticket. They will be able to check this for you.
    http://azure.microsoft.com/en-us/support/options/
    Regards,
    Mekh.

  • Count a procedures input parameters

    Hello,
    does anyone know how to count the number of parameters being passed into a procedure in a package. That is, if a package was called from an application how could a Procedure B count the parameters passed to Procedure A on the initial call to the package.
    Thanks in advance.

    Have a look at ALL_ARGUMENTS.

  • Send Datetime2 value to a SQL Procedure from Java using Hibernate

    Hi All,
    I Have a Procedure which takes a parameter of type datetime2.
    The procedure is called from Java Hibernate.
    How can I Pass datetime2 value to SQL procedure from Java?
    Thanks in advance,
    Shraddha Gore

    You may define a global empty array in some package. Then you can do:
    SQL> CREATE OR REPLACE PACKAGE pkg
    AS
       g_empty   DBMS_SQL.varchar2_table;
    END pkg;
    Package created.
    SQL> CREATE OR REPLACE PROCEDURE p (
       p_tuids   IN   DBMS_SQL.varchar2_table "DEFAULT pkg.g_empty"
    AS
    BEGIN
       NULL;
    END p;
    Procedure created.
    SQL> BEGIN
       p ();
    END;
    PL/SQL procedure successfully completed.

  • Need PL SQL Procedure

    Hello All,
    I like to write a PL SQL Procedure for the below sql statements. I like to pass all values from first sql stmnt to update columns in second sql stmnt based on dund_cc that is selecting from first sql stmnt. Please help me out how can I put together in pl sql procedure.
    SELECT Y.DUND_CC, Y.DPPROP, Y.APPNMENT, Y.ALLOTMENT, Y.ALLOCATION, Y.BDGCT FROM ABCDX_TBL Y;
    UPDATE POSDGET b SET B.DPPROP = Y.DPPROP, b.APPNMENT = Y.APPNMENT, b.ALLOTMENT = Y.ALLOTMENT,
    b.Y.ALLOCATION = Y.ALLOCATION WHERE b.DUND_CC = Y.DUND_CC;
    Thanks in Advance!!!

    Hi,
    You don't need a stored procedure or PL/SQL to do that. You can use a single UPDATE or MERGE statement, like this:
    MERGE INTO       posdget     dst
    USING   (
               SELECT  dund_cc
            ,        dpprop
            ,        appnment
            ,        allotment
            ,        allocation
            ,        bdgct
            FROM        abcdx_tbl
            )               src
    ON     (src.dund_cc     - dst.dund_cc)
    WHEN MATCHED THEN UPDATE
    SET     dst.dpprop     = src.dpprop
    ,     dst.appnment     = src.appnment
    ,     dst.allotment     = src.allotment
    ,     dst.allocation     = src.allocation
    ;The statement above will also work in PL/SQL, if you have a reason for doing it that way.

  • Link to PL/SQL procedure using a Template Manager template.

    Hi,
    I need to link a portal application report (report from SQL query) to a SQL procedure that uses a template manager template. The PL/SQL procedure requires parameters. I'm not be able to create a link based on a PL/SQL procedure. The only solution I found is to setup a link to a Form based on that procedure. But the form is only used to call the PL/SQL procedure by clicking the submit button and redirect to the template.
    Another question:
    Is it planed to support dynamic links based on column conditions?
    I'm using Portal release 3.0.7.6.2.
    thanks in advance
    Jens

    Jens,
    You may want to search the Oracle9iAS Portal Applications forum. It may have the answer you are looking for. This forum is for questions related to the Portal Development Kit.
    Thanks,
    Sue
    Sue

  • Execute a Grant in PL/SQL Procedure DBMS_SQL

    Trying to find a way to do a Grant in a PL/SQL procedure. We have done it in forms before using FORMS_DDL() to execute the command. I tried DBMS_SQL but the samples show cursors for queries and inserts. Can't seem to get it to work.
    Need to grant roles to users and also create users accounts.

    So it should work I just have to get it setup correctly. I am coding as the
    APPUSER. The APPUSER is a DBA, created the procedure and the roles. I am
    coding, compiling and running as APPUSER and getting errors. I did go ahead
    and try running it as someone else and granting that user explicit Grant Any Role
    with Admin option and it still does not do the grant. I do not want to grant the
    actual role to the user since the role give him specific Menu privileges and such
    that he does not need.
    We already have users granting the roles through FORMS_DDL because they
    have Grant Any Role permissions for this purpose.
    I guess if I know that you CAN Grant Roles in a PL/SQL Procedure with
    Execute Immediate then I just need to figure out whats missing.
    Thanks.

  • Blob datatype as arguement to PL/SQL procedure

    Hi,
    Iam trying to pass Blob data from application program to PL/SQL as one of its arguement. The PL/SQL procedure will inturn insert the given Blob data into appropriate table in its corresponding Blob column.
    Ex:-
    PL/SQL Procedure:
    CREATE OR REPLACE PACKAGE TestPkg as
    PROCEDURE logData
    data IN Blob
    END TestPkg;
    Application Program:
    1. string sqlStmt="BEGIN TestPkg.logData(:1); END;";
    2. Connection * pConnection = getConnection();
    3. Statement * pStatement = pConnection->createStatement(sqlStmt);
    4. Blob blob(pConnection);
    5. blob.setEmpty();
    6. blob.write(100, pBuffer, 100, 1); <=== This results in (ORA-22275: invalid LOB locator specified)
    7. pStatement->setBlob(blob);
    8. pStatement->executeUpdate();
    9. pConnection->terminateStatement(pStatement);
    10. releaseConnection(pConnection);
    I used to get similar error while directly inserting from application program to a table with Blob column.
    We fixed it by using the "FOR UPDATE" clause in a select statement and obtaining the locator
    for LOB. Iam looking for a similar syntax for PL/SQL procedure inputs.

    Gaurav,
    Just a guess, but try the following:
    ArrayDescriptor descriptor = ArrayDescriptor.createDescriptor( "SCOTT.HEADER_UPLOAD_TAB", oracleconnection );In other words, prefix the data-type name, HEADER_UPLOAD_TAB, with its schema owner name.
    Good Luck,
    Avi.

  • DTP Selection condition

    Hi Experts,
    I wanted to know if we can read selection conditions maintained in DTP in the start routine using any custom code or using any standard function module.
    Any help will be appreciated.
    Thanks,

    Hi,
    You can do that by writing code to select data from this table RSBKDATAPAKSEL
    Hope this helps
    TRUC

  • Sending message from PL/SQL procedure to form

    Hello Friends,
    How can I send messages from PL/SQL procedure to Form ?
    Ultimate target is catching progress of PL/SQL procedure from
    form. I heard about DBMS_PIPe but not sure,.
    Adi

    Hello,
    Yeah , I got the solution using DBMS_PIPE function,I
    followed following steps.
    1. Pipe is created. see below procedure.
    create or replace procedure proc_testpipe as
         v_pipe_integer          integer;
         v_pipe_message          integer;
    begin
         v_pipe_integer := DBMS_PIPE.Create_Pipe('adipipe');
         dbms_pipe.pack_message('Hello Adinath Kamode,Message
         from Pipe');
         v_pipe_message := dbms_Pipe.Send_message('adipipe');
         end;
    end;
    2. then I created one Function which will obtain message from
    Pipe and
    will return value to form.
    create or replace function proc_callpipe return varchar2 as
    v_msg          integer;
    v_rem          integer;
    v_message          varchar2(500);
    begin
    v_msg:=dbms_pipe.receive_message('adipipe');
    dbms_pipe.unpack_message(v_message);
    dbms_pipe.purge('adipipe');
    v_rem := dbms_pipe.remove_pipe('adipipe');
    return(v_message);
    end;
    3. Last I called this function from form.
    Cheers .. !
    Adi

  • Use file as sql*plus input

    Can I use a file as sql*plus input?
    I have a query like below:
    select * from employees
    where deptno = &1
    and job = &2
    It will prompt me for the values of course.
    I can execute it at the command line like below:
    sql>@script.sql 10 salesrep
    Is is possible to put the values in a file and call the script like below:
    sql>@script.sql <filename>
    Then this file could be in a directory in the OS and I can add any values to it.
    thanks.

    Hi,
    The following script reads a 1-line file and puts its contents into the substitution variable &file_contents:
    COLUMN     file_contents_col   NEW_VALUE  file_contents
    SELECT     TRANSLATE ( '
    @&1
                , 'A' || CHR (10) || CHR (13)
                , 'A'
                )     AS file_contents_col
    FROM    dual;So, if my_params.txt contains
    10    salesrepthen you can say:
    @read_file  my_params.txt
    @script.sql   &file_contentsYou can generalize this by putting the two lines above into a file called caswf.sql:
    @read_file  &2
    @&1  &file_contentsand call it like this
    @caswf  script.sql  my_params.txt"Caswf" is a Welsh word that means "call any script with file".

Maybe you are looking for