Using a subselect in a procedure

In my procedure, I want to use a subselect to get some of the values, but i want to hard code some of the others. This is what I mean
This would be part of my insert statement for example. I want to set project_associate_oid to project_associate_oid.NEXTVAL and hard code project_type_oid and project_oid. Then I want to use a select to populate the short_title, title, address, city, state, zip. How would I do that? I know how to use the subselect, put how do you use it with hard coded values?
insert into project_associate
project_associate_oid, project_type_oid, project_oid,
short_title, title, address, city, state, zip
Select title1, title2, address, city, state, zip from table
End;
Thanks

insert into project_associate (project_associate_oid, project_type_oid, project_oid, short_title, title, address, city, state, zip)
Select project_associate_oid.NEXTVA, 'hard1','hard2', title1, title2, address, city, state, zip from table

Similar Messages

  • Using Copy statement in Stored procedure

    The following statement works in sqlplus session:
    copy from comment/password@servername append amcomment_temp using
    select * from amcomment
    where commentid in(1,2,3,4)
    I want to use this in a stored procedure. There is a long datatype in this table. The
    procedure will not compile. Have tried execute immediate and compiler rejects this statement also.

    'COPY' is a SQL*Plus command, not PL/SQL. This is why the PL/SQL compiler throws it out.

  • Using DBMS LOB in a procedure

    Hi,
    Does anybody have a code example showing the use of DBMS_LOB in a procedure to UPDATE a CLOB field in table?
    Thanks in advance,
    Marc.

    An advanved example from Oracle documentation:
    http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14249/adlob_design.htm#sthref323

  • How to use bind variables in this procedure

    Hi Experts,
    How to use bind variables in this procedure for static queries.
    PROCEDURE DELETE_MER_PROC (M_id IN NUMBER)
    IS
    BEGIN
    V_date DATE;
    SELECT PD_DATE INTO v_date FROM PD_MAINTAIN;
        DELETE FROM MER_CLEAR
        WHERE MER_DT < v_date
        AND ID = M_ID;
    COMMIT;
    END;   
    How to use  v_date and m_id as bind variables in this procedure to avoid hard parsing.
    Please help me.
    Thanks.

    976208 wrote:
    How to use  v_date and m_id as bind variables in this procedure to avoid hard parsing.
    You cannot avoid hard parsing - as the 1st time a SQL statement (like the SELECT or DELETE statements in your code) is encountered, it does not reside in the server's Shared Pool, and needs to be added into the pool via a hard parse.
    Bind variables does not prevent hard parsing. Hard parsing happens when the SQL statement (with or without bind variables) is a brand new statement encountered by the server.
    Bind variables enables the same SQL cursor to be reused, by simply changing the bind variable value.
    Not using bind variables means that each SQL statement is unique and not shareable - as the value is hardcoded into the statement and cannot be changed via a bind value. This typically means LOTS of different SQL statements (where the only difference is the changed value in the statement) are created - with each statement being a new statement not seen before in the Shared Pool and needing to be hard parsed.
    One does not design one's code not to be hard parsed. There ALWAYS will be a hard parse in order to get a SQL statement into the Shared Pool. One designs one's code to REUSE cursors in the Shared Pool.

  • How to use order by in stored procedure base block?

    How to use order by in stored procedure base block? I need to change order by dynamically

    Use SET_BLOCK_PROPERTY('BLOCK_NAME',ORDER_BY,'COLUMN_NAME1, COLUMN_NAME2');

  • Two related questions: using htmldb_Get to call stored procedure and passing in an array of items

    I have the need to save dynamically generated ApEx items via AJAX.  I am using APEX_ITEM API to generate the items.  At run-time, I have no idea how many of items will be generated on the page, but I know that they will all have discreet and distinct "name" attributes, i.e. f01, f02, f03, etc.  As a basic example, if I have to generate a select list, I know that the "p_idx" parameter of the APEX_ITEM call is say "3", so all select lists that get generated will have a "name" attribute in the DOM of "f03", all text items will be "f01", etc.
    I want to save this data to the database via AJAX.  It is typical to call the standard htmldb_Get javascript function for use of an on-demand process, but I am interested in using the rarely-called-upon "procedure" and queryString" options of that javascript function so that I can build the queryString on the fly based on what is on the DOM when the tries to save the data they entered into these APEX_ITEM-generated items.  Does anyone have any good examples of how to use the "procedure" and "queryString" parameters of the htmldb_Get javascript function?
    I have found a smattering of some blogs, posts, etc. online related to this, but mostly just people regurgitating the documentation.  I found this post (https://forums.oracle.com/thread/2549237) which had a glimpse of hope to be able to pass an array (which is something I will need) as a parameter, but would like someone to sanity check this before I go down that road.
    Shane.
    ApEx 4.2.1

    Shane
    Since you mention you are on APEX 4.2  I would recommend using apex.server.process which is the documented replacement of the officially undocumented htmldb_Get.
    In the documentation it is set that the first parameter is the ajaxidentifier but it actually is the process name.
    The data object would be something like
    var lData ={f01 : get_value_array('f01')}
    Where get_value_array is
    function get_value_array(pColumnName) {
      var l_values =[];
      apex.jQuery('[name="'+pColumnName+'"]').each(
       function(){
        var l_value;
        l_value = apex.item(this.id).getValue();
        l_values.push(l_value);
      return l_values
    For a working example see this demo.
    Nicolette

  • Using VIEW inside a stored procedure

    Hi,
    So I have a View designed in one file that validates someone who is authorized.
    Then I have a stored procedure to display authorized stationeries created before a given date. Its takes a parameter @CreatedOn.
    How can I use VIEW in my stored procedure so I can display all the authorized which are set 1 before a given date?
    My VIEW:
    ALTER VIEW vw_AuthorizedStationeries AS
    SELECT Authorized
    FROM dbo.Stationeries
    WHERE Authorized = 1
    And my stored procedure:
    CREATE PROCEDURE usp_stationeries (@CreatedOn datetime)ASBEGINSELECTFROMENDGO
    Thanks!

    Try something like below, You need to replace CreatedDate column with appropriate date column in your table.
    1. Alter the view to get the required date:
    ALTER VIEW vw_AuthorizedStationeries AS
    SELECT Authorized, CreatedDate
    FROM dbo.Stationeries
    WHERE Authorized = 1
    2. Alter SP:
    CREATE PROCEDURE usp_stationeries (@CreatedOn datetime)
    AS
    BEGIN
    SELECT Authorized
    FROM vw_AuthorizedStationeries
    WHERE CreatedDate <= @CreatedOn
    END
    GO
    OR
    You can pull required information directly from your table:
    CREATE PROCEDURE usp_stationeries (@CreatedOn datetime)
    AS
    BEGIN
    SELECT Authorized
    FROM dbo.Stationeries
    WHERE CreatedDate <= @CreatedOn and Authorized = 1
    END
    GO
    If this post answers your query, please click "Mark As Answer" or "Vote as Helpful".

  • Using temporary tables in stored procedures

    Suppose that I have created a temporary table in a stored procedure using an "EXECUTE IMMEDIATE" statement. When I compile the procedure, that table is not created yet, so the compiler says that the table does not exist.
    What is the way of using temporary tables in stored procedures?

    It's a good practice to avoid using DDL statements being executed from stored procedures. "Truncate Table" via dynamic SQL from stored procedure is a different story and is useful in DSS environments.
    But if you insist on "creating" tables using Dynamic SQL from Stored Procedures then you must also embed your DML statements in Dynamic SQL to avoid compilation errors.
    Example:
    Create or Replace Procedure Proc_TestDynamicSQL is
    Begin
    Execute Immediate 'Create table myTable as select * from user_tables' ;
    Execute Immediate 'Update myTable set table_name = ''Test'' ' ; --two single quotes before and after the string "Test"
    End;
    In this case, Oracle wouldn't care about the table references during compilation.

  • How to know a table is using in any packeges or procedures

    Dear All
    How can I know that a table is using in any packege or procedure or function ?
    I mean , let say I have 10 Packages , 10 Procedures and 5 Functions .
    I need to know in which Packages , Procedures or Functions are using the table EMP .
    How can I search ? Is there any command or I need to open all the procedures and then search one by one ?

    Hi everyone,
    Did anyone interest in the topic search for dependencies between objects in the database?
    I want to see the PL/SQL code which is an appeal to a particular procedure or function or package and where and how does an object use in any PL/SQL code.
    Often do you have a need to get answers to these questions?
    I say about an object usage presentation, not about its relations only.
    Do you want to know, how opbject used?
    If it's a table - what's DML?(insert/select/...)
    If it used in a package - which procedure of package uses in?
    The object usage in an external objects - Oracle*Forms/Reports,Flat/Word files, Informatica.
    I'll want to know, if everybody interested to one.

  • In SQLScript, how to use EXEC to call another procedure with parameters in procedure?

    Hi experts,
    In SQLScript, How to use EXEC to call another procedure with input and output parameters in procedure?thanks very much

    Hi Sagar,
    thank you! I generate another procedure with an input parameter and an output parameter in a procedure. Then i need to call the generated procedure using EXEC. Here is my code:
    create procedure ftest1(out sum_num bigint)
    as
    begin
    declare fa_output bigint;
    declare v_sql_drop varchar(200);
    declare v_sql varchar(500);
    declare cursor c_cursor1 for select num from TABLE1;
    --v_sql_drop := 'drop procedure fe';
    --exec v_sql_drop;
    v_sql := 'create procedure fe(in i_num bigint,out o_num bigint) as begin';
    v_sql := :v_sql || ' o_num := :i_num * 2 + :i_num * :i_num;';
    v_sql := :v_sql || ' end';
    exec v_sql;
    open c_cursor1;
    for c_item as c_cursor1 do
    exec 'call fe(c_item.num,o_num=>fa_output)';
    if sum_num is null then
    sum_num := fa_output;
    else
    sum_num := :sum_num + fa_output;
    end if;
    end for;
    close c_cursor1;
    end;
    The underline code is using exec to call the generated procedure. But this method cannot work. Any suggestion? thanks again!

  • Can rs.last() be used after calling the stored procedure?

    Can rs.last() be used after calling the stored procedure? If yes what should be the CURSOR types?

    Can rs.last() be used after calling the stored
    procedure? If yes what should be the CURSOR types?That would depend on the driver/database.
    And as I said in your other post it is far more efficient to count records by just returning a count rather than a complete collection regardless of how you get to the end.

  • When we use SQLScript/CE Functions or procedures in real time scenario

    Hi,
    Can anyone explain me, when we use Scripted Calculation view or procedure using SQL/CE functions in real time project implementations.
    Let me know some business requirement why we choose these instead of graphical view.

    Hi Kumar,
    <i>So in real time if you want to develop some interface whether we use existing components or we will create own user defined products and components ??</i>
    We can do both.
    If the pre-delivered content actually solves ur purpose by providing the exact format of data, then u should go for the <b>existing components</b>
    If there is any change from the content provided, then u should change it and<b> create own user defined products and components</b>
    <i> What is the criteria behind choosing either of them ??</i>
    Thus the criteria is purely based upon the type of data formats u have to use. Existing component always saves lot of development time
    Regards,
    Prateek

  • Use database inside a stored procedure

    Hi guys, a stupid question: I'm working with several database and sometimes I'm afraid to run an alter or a create something in the wrong database, bear in mind that several database have the same tables. Sometime happens to run a query oin the db A
    instead in the db B. So, the question: If I create a procedure like this,
    create procedure creatingPillar as
    use USA
    begin
    IF EXISTS (SELECT * FROM sys.objects WHERE object_id =
    OBJECT_ID(N'pillarretail') AND type in (N'U'))
    DROP TABLE PillarRetail
    create table PillarRetail (anid int , ancore varchar(20), period dec(18,6), settlem datetime2,
    settlementper int, asf dec(18,6),astlf dec (18,6), tot dec (18,6) )
    insert into PillarRetail select anid, ancore, Period, settlem, settlementper,
    asf, astlf, tot from createsemipillar2011
    insert into PillarRetail select select anid, ancore, Period, settlem, settlementper,
    asf, astlf, tot createsemipillar
    end
    but I'm wondering if is useless to put the use USA in the stored procedure by the moment that I'm creating the procedure in USA. I mean, having the SP in the USA db even if I run the procedure from another db it should run in USA. Just a stupid question
    I know but I got this doubt...
    Thanks 

    You may try as below:
    create proc as below: (This will create the proc in USA database.
    use USA
    Go
    create procedure dbo.creatingPillar as
    begin
    IF EXISTS (SELECT * FROM sys.objects WHERE object_id =
    OBJECT_ID(N'pillarretail') AND type in (N'U'))
    DROP TABLE PillarRetail
    create table PillarRetail (anid int , ancore varchar(20), period dec(18,6), settlem datetime2,
    settlementper int, asf dec(18,6),astlf dec (18,6), tot dec (18,6) )
    insert into PillarRetail select anid, ancore, Period, settlem, settlementper,
    asf, astlf, tot from createsemipillar2011
    insert into PillarRetail select select anid, ancore, Period, settlem, settlementper,
    asf, astlf, tot createsemipillar
    end
    Then you can call as below:
    Exec USA.dbo.creatingPillar

  • Using AIR as source for procedure generators??

    We currently have procedure generators for support people to choose the documentation they want to see and download it. Problem is the output (and input) is all Word based and the choice is not to go back from Frame to Word.
    Could AIR be used as sources for a procedure generator, to output in XML format?
    Thanks!

    It is my understanding you need at least 10.1.3.3.2 (upgrade/patch).
    I'm currently on 10.1.3.3.0 and will be using ESSBASE shortly - so we actually have purchased 10.1.3.3.3 (OBIEE Plus).

  • Re-use SELECT statement in several procedures (other than copy-and-paste)

    Our site uses a procedure of the following procedure construct to generate Excel spreadsheets:
    TYPE retCur is REF CURSOR;
    PROCEDURE get_data_for_excel (
      p_filter1 VARCHAR2
      ,p_filter2 VARCHAR2
      ,c_OutCursor out retCur
    IS
      retCursor retcur
    BEGIN
      BEGIN
      OPEN c_OutCursor FOR
        SELECT XMLELEMENT("TR", XMLFOREST(
           "col1" AS "TD"
           ,"col2" AS "TD"
           ,"col3" AS "TD"
          )).getstringval()DATA FROM (SELECT * FROM
       SELECT col1, col2, col3
       FROM sometable
       WHERE somecolumn = p_filter1
        AND someothercolumn = p_filter2
       ) x);
      END;
    END get_data_for_excel
    My question is, the subselect:
    SELECT col1, col2, col3
    FROM sometable
    is used in another procedure. Is there a way to reuse the select from the other procedure into this procedure so we don't copy-and-paste each time the other procedure is changed?
    Thanks a lot.

    This is a design decision you need to make BEFORE it goes into production.
    Right now you have
    procedure get_data_for_excel (
       p_filter1 VARCHAR2
      ,p_filter2 VARCHAR2
      ,c_OutCursor out retCur );
    What, I think jihuyao is trying to say is:  convert it to a pipelined function.
    I agree with jihuyao as I have ran into to this problem before.
    create type d4e_t as object ( DATA xmltype);
    create type d4e_table is table of d4e_t;
    create or replace function get_data_for_excel (
       p_filter1 VARCHAR2
      ,p_filter2 VARCHAR2 )
      return d4e_table pipelined;
    as
    begin
      for curr in ( --start of SELECT statement
    SELECT XMLELEMENT("TR", XMLFOREST(
           "col1" AS "TD"
           ,"col2" AS "TD"
           ,"col3" AS "TD"
          )).getstringval()DATA FROM (SELECT * FROM
       SELECT col1, col2, col3
       FROM sometable
       WHERE somecolumn = p_filter1
        AND someothercolumn = p_filter2
       ) x) )
    LOOP
      pipe row( d4e_t( curr.data ) );
    end loop;
    return;
    end;
    From there, you use it elsewhere as if it were a table.
    insert into t
    select X.data from table( get_data_for_excel( l_var1, l_var2 ) ) X;
    MK

Maybe you are looking for