Parameter Binding by Alias

Try removing the [string] declaration, that way PowerShell will just accept whatever you give it.  

So I am working on a function that accepts pipeline input from Get-Aduser or Get-Mailbox. The goal is to bind the userprincipalname of and AD user to the -Identity parameter:Powershellfunction Test-AliasBinding { [CmdletBinding()] param ( [Parameter(Mandatory=$true, ValueFromPipelineByPropertyName=$true)] [Alias('UserPrincipalName')] [string] $Identity ) $Identity}I can pipe Get-Mailbox to this just fine since it's output already includes an Identity property. However, binding does not work if I use Get-ADUser and pipe it to the function:
PowershellPS c:\> get-aduser matt | Test-AliasBindingTest-AliasBinding : Cannot bind argument to parameter 'Identity' because it is an empty string.At line:1 char:22+ get-aduser matt | Test-AliasBinding+ ~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidData: (CN=Matthew McNa...C=domain,DC=com:PSObject) [...
This topic first appeared in the Spiceworks Community

Similar Messages

  • Parameter Binding Issue

    I have an advanced function that that looks something like this:
    function Audit-System
    [CmdletBinding()]
    param(
    [Parameter(Position=0,Mandatory=$True,ValueFromPipeline=$True,ValueFromPipelinebyPropertyName=$True)]
    [Alias("Name")]
    [string[]]$ComputerName
    Process
    foreach($computer in $ComputerName)
    ## Do stuff for every computer
    Write-Verbose $computer
    The followimg work ok:
    "computer1","computer2" | Audit-System
    Audit-System "computer1","computer2"
    Audit-System "computer1"
    The following doesn't work:
    Get-ADComputer -Filter * SearchBase "CN=Computers,DC=contoso,DC=com" | Audit-System -Verbose
    I would have thought that because the [Microsoft.ActiveDirectory.Management.ADComputer] has a 'Name' property parameter binding would have matched it up with my $ComputerName parameter. Why doesn't this work?

    What version of PowerShell are you running? I have this working running PowerShell V4 and also having installed  KB2928680 which
    fixed a known issue with PowerShell V4 and the use of -Properties * with Get-ADUser and Get-ADComputer.
    Interesting. I still need to pipe through select on a fully patched Win8.1 and Win7 (with V4 installed).
    Don't retire TechNet! -
    (Don't give up yet - 12,700+ strong and growing)
    Disregard this. After more testing (this time using the function), I run into the same issue. Appears that this particular issue is still occurring. I know there is a connect issue submitted for this, but wasn't able to locate it (at the time of this post).
    Boe Prox
    Blog |
    Twitter
    PoshWSUS |
    PoshPAIG | PoshChat |
    PoshEventUI
    PowerShell Deep Dives Book

  • PL/SQL:- Invalid Parameter binding

    While calling a pl/sql function returning table type is shows error:
    Invalid parameter binding
    Parameter name: ""

    The problem is coming from .NET and most probably for NULL values.
    SQL> set serverout on
    SQL> create TYPE TEMP_TABLE AS OBJECT (
      2  COLUMN1 VARCHAR2(128),
      3  COLUMN2 VARCHAR2(32),
      4  COLUMN3 VARCHAR2(128));
      5  /
    Type created.
    SQL> create TYPE TEMP_TABLE_REC AS TABLE OF TEMP_TABLE;
      2  /
    Type created.
    SQL> create function SP_TEMP RETURN TEMP_TABLE_REC AS
      2 
      3  v_process_inputs TEMP_TABLE_REC :=TEMP_TABLE_REC();
      4 
      5  CURSOR CUR_EQUIP IS
      6  SELECT 'b' FROM dual
      7  UNION
      8  SELECT 'f' FROM dual;
      9 
    10  REC_EQUIP CUR_EQUIP%ROWTYPE;
    11 
    12  BEGIN
    13 
    14  OPEN CUR_EQUIP;
    15  LOOP
    16  FETCH CUR_EQUIP INTO REC_EQUIP;
    17  EXIT WHEN CUR_EQUIP%NOTFOUND;
    18  v_process_inputs.EXTEND;
    19 
    20  v_process_inputs(1):=TEMP_TABLE('a','b','c');
    21 
    22  END LOOP;
    23  CLOSE CUR_EQUIP;
    24 
    25  RETURN v_process_inputs;
    26  END SP_TEMP;
    27  /
    Function created.
    SQL> declare
      2     result temp_table_rec;
      3  begin
      4    -- Call the function
      5    result := sp_temp;
      6    FOR i in 1..RESULT.COUNT LOOP
      7     dbms_output.put_line(RESULT(i).COLUMN1||'--'||RESULT(i).COLUMN2||'--'||RESULT(i).COLUMN3);
      8    END LOOP;
      9  end;
    10  /
    a--b--c
    PL/SQL procedure successfully completed.Note the last null values ----.

  • How to pass parameter [bind variable or substitution variable] to a view?

    How can I pass a parameter [bind variable or substitution variable] to a view in Oracle?
    Some will tell me that this is not necessary, that I can only pass the parameter when I query the view, but I found some case where this cause performance issue. In long view where I use subquery factoring [WITH], it's necessary to pass the parameter many time through different subqueries and not only to the resulting view.
    In other database (SQL Server, Access), we can pass parameters through query. I can't find how to do that in Oracle. Can some one tell me what is the approach suggest by Oracle on that subject?
    Thank you in advance,
    MB
    What I can do:
    CREATE VIEW "HR"."EMP_NAME" ("FIRST_NAME", "LAST_NAME")
    AS
    SELECT FIRST_NAME, LAST_NAME FROM EMPLOYEES;
    What I want to do:
    CREATE VIEW "HR"."EMP_NAME" ("FIRST_NAME", "LAST_NAME")(prmEMP_ID)
    AS
    SELECT FIRST_NAME, LAST_NAME FROM EMPLOYEES WHERE EMPLOYEE_ID IN (:prmEMP_ID);

    Blais wrote:
    How can I pass a parameter [bind variable or substitution variable] to a view in Oracle?
    Some will tell me that this is not necessary, that I can only pass the parameter when I query the view, but I found some case where this cause performance issue. In long view where I use subquery factoring [WITH], it's necessary to pass the parameter many time through different subqueries and not only to the resulting view.Yes, there can be performance issues. Views are a form of dynamic SQL and it is hard to predict how they will perform later.
    You can't pass parameters to a view. They are not functions. The mechanism to put the values in is what you mentioned, passing the parameter when you query the view.
    In other database (SQL Server, Access), we can pass parameters through query. I can't find how to do that in Oracle. Can some one tell me what is the approach suggest by Oracle on that subject? This functionality is not supported.
    What I can do:
    CREATE VIEW "HR"."EMP_NAME" ("FIRST_NAME", "LAST_NAME")
    AS
    SELECT FIRST_NAME, LAST_NAME FROM EMPLOYEES;
    What I want to do:
    CREATE VIEW "HR"."EMP_NAME" ("FIRST_NAME", "LAST_NAME")(prmEMP_ID)
    AS
    SELECT FIRST_NAME, LAST_NAME FROM EMPLOYEES WHERE EMPLOYEE_ID IN (:prmEMP_ID);Include the bind value when you use the view in a SELECT. The value will be applied to the view at run-time, somthing like
    CREATE  VIEW "HR"."EMP_NAME_VW" ("FIRST_NAME", "LAST_NAME","EMPLOYEE_ID")(prmEMP_ID)
    AS  SELECT FIRST_NAME, LAST_NAME FROM EMPLOYEES;
    select *
      from emp_name_vw
      WHERE EMPLOYEE_ID IN (:prmEMP_ID);To use EMPLOYEE_ID I added it to your list of columns in the view so it can be referenced in the WHERE clause. If you don't want to see that value don't select it from the view.

  • [Oracle JDBC Driver]Invalid parameter binding(s).

    Hi there
    I am using the OracleCachedRowSet, and it works fine until I tries to update a resultset with a null value. When I call rs.acceptChanges(connection); it results in the following exception.
    Please help if anyone has found a workaround to this problem.
    java.sql.SQLException: [BEA][Oracle JDBC Driver]Invalid parameter binding(s).
    at weblogic.jdbc.base.BaseExceptions.createException(Unknown Source)
    at weblogic.jdbc.base.BaseExceptions.getException(Unknown Source)
    at weblogic.jdbc.base.BaseParameters.getParameter(Unknown Source)
    at weblogic.jdbc.base.BasePreparedStatement.setObjectInternal(Unknown Source)
    at weblogic.jdbc.base.BasePreparedStatement.setObject(Unknown Source)
    at weblogic.jdbc.wrapper.PreparedStatement.setObject(PreparedStatement.java:268)
    at oracle.jdbc.rowset.OracleCachedRowSetWriter.updateRow(OracleCachedRowSetWriter.java:429)
    at oracle.jdbc.rowset.OracleCachedRowSetWriter.writeData(OracleCachedRowSetWriter.java:534)
    at oracle.jdbc.rowset.OracleCachedRowSet.acceptChanges(OracleCachedRowSet.java:2926)
    at eurostat.Items.updateRS(Items.java:192)
    at eurostat.DBConnectionBean.updateRS(DBConnectionBean.java:94)
    at jsp_servlet.__mainpage._jspService(MainPage.jsp:248)
    at weblogic.servlet.jsp.JspBase.service(JspBase.java:33)
    at weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run(ServletStubImpl.java:1006)
    at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:419)
    at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:28)
    at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:27)
    at com.bea.wlw.netui.pageflow.PageFlowJspFilter.doFilter(PageFlowJspFilter.java:246)
    at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:27)
    at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:6724)
    at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
    at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:121)
    at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServletContext.java:3764)
    at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.java:2644)
    at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:219)
    at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:178)

    Hi Avi
    Thanks for the suggestion, but I don't thint that is the problem. In other forums I have found people describing the same problem(both with Oracle and Sun's implementation of CachedRowSet). See this link for an example http://bugs.mysql.com/bug.php?id=9831. So I figured that those other people needed to have a solution to the problem, but I can't find it.
    /Thomas

  • SAP Cloud For Customer : Add Extension Fields under the Parameter Binding For Mashups

    Hi Experts,
    I have requirements for the mashups, I have created the extension field in cloud for customer "Registered Product" TI screen i want to add that newly created extension fields under the Mashup Parameter Binding List.
    1) Is it possible ? If yes then How it is?
    2) Any Standard process or we go for the SDK to enhance the standard screen port binding?
    For more information refer the below screen.
    Awaiting for your reply or suggestion....
    Many Thanks,
    Mithun

    I have done the below changes on the custom BO.
    Step 1 . In the Event Handler i have change as per the previous reply.
    Step 2. Assign that Event to Import OnFire.
    I am getting this error when open the Account Screen and go to that Embed Tab.
    "Object [object Object] has no method 'getRawValue'".
    Kindly check the above steps are correct or any step missing.
    Many Thanks,
    Mithun

  • OWB embeded process flow - parameter binding problem

    I've installed and Oracle 10g Database, after the database installation I added the Oracle Workflow server software. To complete the installation I ran the wfca.
    Later I get to define a process flow in OWB (cheesy) and the process flow seems to be working well (I've done all the registrations necesary also ), but when I am trying to do the parameter binding is not working. I do get the window prompt for the parameter and I enter the date parameter ( I tried different formats like 'YYYY/MM/DD' 'dd-mon-yyyy'), but after I check the runtime in the web browser the parameter is not pass to next process. I tried many things for the last week but I cannot get it to pass the parameter from one process to another.
    Any ideas,
    HELP !!!!!

    did u manage to resolve this issue? we are facing the same problem.

  • [OCI] Parameter Binding, repeated Statements with differing values

    Hello
    I am working on an application written in C which sends about 50 different SQL Statements to an Oracle Database using OCI. These Statements are executed repeatedly with different values.
    In order to improve performance I would like to know what possibilities I have.
    Whats the benefit of the following "techniques" ?
    - Parameter Binding
    - Statement Caching
    What else could I look into?
    with friendly greetings.

    It doesn't take zero-time of course, and it does level-off after a while, but array-bind/define or pre-fetching can make a significant impact on performance:
    truncated table: 0.907 / 0.918
    insert_point_stru_1stmt_1commit: x100,000: 0.141 / 0.144Above I truncate the table to get repeatable numbers; deleting all rows from a previous run leaves a large free list (I guess...), and performance of this little contrived benchmark degrades non-negligeably otherwise. This is a single array-bind insert statement.
    fetched 100,000 rows. (0 errors)
    select_first_n_points: x100,000@0: 7.594 / 7.608
    fetched 100,000 rows. (0 errors)
    select_first_n_points: x100,000@1: 4.000 / 4.004
    fetched 100,000 rows. (0 errors)
    select_first_n_points: x100,000@10: 0.906 / 0.910
    fetched 100,000 rows. (0 errors)
    select_first_n_points: x100,000@100: 0.297 / 0.288
    fetched 100,000 rows. (0 errors)
    select_first_n_points: x100,000@1,000: 0.204 / 0.204
    fetched 100,000 rows. (0 errors)
    select_first_n_points: x100,000@10,000: 0.265 / 0.268
    fetched 100,000 rows. (0 errors)Above I do a regular "scalar" define, but turn pre-fetching on (default is one row, but I tested with pre-fetching completly off too). @N means pre-fetch N rows.
    select_points_array: x100,000@10: 0.969 / 0.967
    fetched 100,000 rows. (0 errors)
    select_points_array: x100,000@100: 0.250 / 0.251
    fetched 100,000 rows. (0 errors)
    select_points_array: x100,000@1,000: 0.156 / 0.167
    fetched 100,000 rows. (0 errors)
    select_points_array: x100,000@10,000: 0.156 / 0.157
    fetched 100,000 rows. (0 errors)Above I use array-defines instead of pre-fetch.
    select_points_struct: x100,000@10: 0.938 / 0.935
    fetched 100,000 rows. (0 errors)
    select_points_struct: x100,000@100: 0.219 / 0.217
    fetched 100,000 rows. (0 errors)
    select_points_struct: x100,000@1,000: 0.140 / 0.140
    fetched 100,000 rows. (0 errors)
    select_points_struct: x100,000@1,000: 0.140 / 0.140Above I use array-of-struct defines instead of pre-fetch or array-bind. Performance is just a little better, probably because of better memory "locality" with structures.
    The table is simple:
    create table point_tab(
    id number,
    x binary_float,
    y binary_float,
    z binary_float
    So each row is 22 + 4 + 4 + 4 = 34 bytes. There are no constraints or indexes of course to make it as fast as possible (this is 11g on XP win32, server and client on the same machine, single user, IPC protocol, so it doesn't get much better than this, and is not realistic of true client-server multi-user conditions).
    There aren't enough data point to confirm or not your prediction that the advantage of array-bind level-off at the packet size threshold, but what you write makes sense to me.
    So I went back and tried more sizes. 8K divided by 34 bytes is 240 rows, so I selected 250 rows as the "middle", and bracketed it with 2 upper and lower values which "double" up or down the number of rows:
    truncated table: 0.953 / 0.960
    insert_point_stru_1stmt_1commit: x100,000: 0.219 / 0.220
    fetched 100,000 rows. (0 errors)
    select_first_n_points: x100,000@67: 0.329 / 0.320
    fetched 100,000 rows. (0 errors)
    select_first_n_points: x100,000@125: 0.297 / 0.296
    fetched 100,000 rows. (0 errors)
    select_first_n_points: x100,000@250: 0.250 / 0.237
    fetched 100,000 rows. (0 errors)
    select_first_n_points: x100,000@500: 0.218 / 0.210
    fetched 100,000 rows. (0 errors)
    select_first_n_points: x100,000@1,000: 0.187 / 0.195
    fetched 99,964 rows. (0 errors)
    select_points_array: x99,964@67: 0.297 / 0.294
    fetched 100,000 rows. (0 errors)
    select_points_array: x100,000@125: 0.235 / 0.236
    fetched 100,000 rows. (0 errors)
    select_points_array: x100,000@250: 0.203 / 0.206
    fetched 100,000 rows. (0 errors)
    select_points_array: x100,000@500: 0.188 / 0.179
    fetched 100,000 rows. (0 errors)
    select_points_array: x100,000@1,000: 0.156 / 0.165
    fetched 99,964 rows. (0 errors)
    select_points_struct: x99,964@67: 0.250 / 0.254
    fetched 100,000 rows. (0 errors)
    select_points_struct: x100,000@125: 0.203 / 0.207
    fetched 100,000 rows. (0 errors)
    select_points_struct: x100,000@250: 0.172 / 0.168
    fetched 100,000 rows. (0 errors)
    select_points_struct: x100,000@500: 0.157 / 0.152
    fetched 100,000 rows. (0 errors)
    select_points_struct: x100,000@1,000: 0.125 / 0.129As you can see, it still gets faster at 1,000, which is about 32K. I don't know the packet size of course, but 32K sounds big for a packet.
    truncated table: 2.937 / 2.945
    insert_point_stru_1stmt_1commit: x100,000: 0.328 / 0.324
    fetched 100,000 rows. (0 errors)
    select_first_n_points: x100,000@1,000: 0.250 / 0.250
    fetched 100,000 rows. (0 errors)
    select_first_n_points: x100,000@2,000: 0.266 / 0.262
    fetched 100,000 rows. (0 errors)
    select_first_n_points: x100,000@3,000: 0.250 / 0.254
    fetched 100,000 rows. (0 errors)
    select_first_n_points: x100,000@4,000: 0.266 / 0.273
    fetched 100,000 rows. (0 errors)
    select_first_n_points: x100,000@5,000: 0.281 / 0.278
    fetched 100,000 rows. (0 errors)
    select_points_array: x100,000@1,000: 0.172 / 0.165
    fetched 100,000 rows. (0 errors)
    select_points_array: x100,000@2,000: 0.157 / 0.159
    fetched 99,000 rows. (0 errors)
    select_points_array: x99,000@3,000: 0.156 / 0.157
    fetched 100,000 rows. (0 errors)
    select_points_array: x100,000@4,000: 0.141 / 0.155
    fetched 100,000 rows. (0 errors)
    select_points_array: x100,000@5,000: 0.157 / 0.164
    fetched 100,000 rows. (0 errors)
    select_points_struct: x100,000@1,000: 0.125 / 0.129
    fetched 100,000 rows. (0 errors)
    select_points_struct: x100,000@2,000: 0.125 / 0.123
    fetched 99,000 rows. (0 errors)
    select_points_struct: x99,000@3,000: 0.125 / 0.120
    fetched 100,000 rows. (0 errors)
    select_points_struct: x100,000@4,000: 0.125 / 0.121
    fetched 100,000 rows. (0 errors)
    select_points_struct: x100,000@5,000: 0.125 / 0.122Above 32K, there doesn't seem to be much benefit (at least in this config. My colleague on linux64 is consistently faster in benchmarks, even connecting to the same servers, when we have the same exact machine). So 32K may indeed be a threshold of sort.
    In all, I hope I've shown there is value in array-binds (or defines), or even simple pre-fetching (but the latter helps in selects only). I don't think one can very often take advantage of it, and I have no clue how it compares to direct-path calls, but value there is still IMHO. --DD                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Named parameter binding

    ODP.Net document said :
    The position of an OracleParameter added into the
    OracleParameterCollection is the binding position in the SQL statement.Position is 0-based and is used only for positional binding.
    If named binding is
    used, the position of an OracleParameter in the
    OracleParameterCollection is ignored.
    Then,how can I use named parameter binding ?

    Look up the BindByName property of the Oracle Command. It defaults to false (bind params by position). Set it to true for bind by name.

  • Name Parameter Binding

    Is there any sample code showing how to do named parameter binding using ODBC? I have stored procedures with 100+ parameters and default values assigned to most of the parameters and I want to be able to only bind to the variables that I need to pass. I have it working with MS SQL but with oracle it in not binding to the correct parameter
    Thanks

    I am tring to do Named "Parameter Binding", I am using using straight ODBC from vc++ with the latest driver 9205. I have also tried the DataDirect drivers and using ADO from VB6.
    The same code has worked fine with SQL Server but with oracle it always ingores the SQL_DESC_NAME setting in the SQLSetDescField statement and sets the first two parameters, not the 2nd and 3rd param.
    Thanks,
    Bill
    -- The Stored Procedure
    CREATE OR REPLACE PROCEDURE testme (param1 varchar2 :='Default1' , param2 varchar2 := 'Default2', param3 varchar2 := 'Default3') AS
    BEGIN
    INSERT INTO param_test(param_1, param_2, param_3, col_id) VALUES (param1, param2, param3, test_seq.nextval);
    END;
    C++ Source code
    // Prepare the procedure invocation statement.
    retcode = SQLPrepare(hstmt, (SQLCHAR*)"{call testme(?, ?)}", SQL_NTS);
    if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
    // Populate record 1 of ipd.
    strcpy((char*)szQuote, "test2");
    SQLBindParameter(hstmt, 1, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_VARCHAR, 30, 0, szQuote, 0, &cbValue);
    // Get ipd handle and set the SQL_DESC_NAMED and SQL_DESC_UNNAMED fields
    // for record #1.
    //retcode = SQLAllocHandle(SQL_HANDLE_DESC, hdbc, &hIpd);
    retcode = SQLGetStmtAttr(hstmt, SQL_ATTR_IMP_PARAM_DESC, &hIpd1, 0, 0);
    retcode = SQLSetDescField(hIpd1, 1, SQL_DESC_NAME, "param2", SQL_NTS);
    retcode = SQLSetDescField(hIpd1, 1, SQL_DESC_UNNAMED, SQL_NAMED, 0);
    // Populate record 1 of ipd.
    strcpy((char*)szQuote2, "test3");
    SQLBindParameter(hstmt, 2, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_VARCHAR, 30, 0, szQuote2, 0, &cbValue);
    // Get ipd handle and set the SQL_DESC_NAMED and SQL_DESC_UNNAMED fields
    // for record #2.
    //retcode = SQLAllocHandle(SQL_HANDLE_DESC, hdbc, &hIpd);
    retcode = SQLGetStmtAttr(hstmt, SQL_ATTR_IMP_PARAM_DESC, &hIpd2, 0, 0);
    retcode = SQLSetDescField(hIpd2, 2, SQL_DESC_NAME, "param3", SQL_NTS);
    retcode = SQLSetDescField(hIpd2, 2, SQL_DESC_UNNAMED, SQL_NAMED, 0);
    // Assuming that szQuote has been appropriately initialized,
    // execute.
    retcode = SQLExecute(hstmt);
    if (!SQL_SUCCEEDED(retcode))
    ExplainErrors(hstmt);
    }

  • Help with Invalid Parameter Binding issue

    let me prefix this with the fact that I'm about as ignorant as can be when it comes to oracle so speak slowly and hopefully I'll catch the low hanging fruit.
    I've inherited a project that someone else wrote and I'm trying to make the code base work, but I am getting 2 error messages and don't really know where to start to fix it.
    My project is using ActiveReports (yea I hate it too) to call a function into a 10g database. It is returning an error saying Invalid Identifier. When I try to run the function in visual studio I get an invalid parameter binding error message and it says parameter name "" (empty quotes, so who knows).
    here's what I have:
    the type definition:
    TYPE type_A AS OBJECT (date_a VARCHAR2(25), start_date VARCHAR2(25), end_date VARCHAR2(25), items_total INT, items_with_x INT, items_without_x INT, items_with_x_percent DECIMAL(7,6), items_without_x_percent DECIMAL(7,6))
    the type table:
    TYPE type_A_table AS TABLE OF type_A
    the function that is erroring:
    <em>FUNCTION func_A (start_date_str IN VARCHAR2, end_date_str IN VARCHAR2) RETURN type_A_table PIPELINED
    IS
    PRAGMA AUTONOMOUS_TRANSACTION;
        start_date_filter TIMESTAMP := TO_DATE(start_date_str,'MM/dd/yyyy HH:MI:ss AM');
        end_date_filter TIMESTAMP := TO_DATE(end_date_str,'MM/dd/yyyy HH:MI:ss AM');
        items_total INT;
        items_with_x INT;
        items_without_x INT;
        items_with_x_percent DECIMAL(7,6);
        items_without_x_percent DECIMAL(7,6);
        temp type_A;
    BEGIN
        SELECT COUNT(*) INTO items_total FROM atable WHERE (create_date BETWEEN start_date_filter AND end_date_filter);
        SELECT COUNT(*) INTO items_with_x FROM atable WHERE conditionx=1 AND (create_date BETWEEN start_date_filter AND end_date_filter);
        SELECT COUNT(*) INTO items_without_x FROM atable WHERE conditionx=0 AND (create_date BETWEEN start_date_filter AND end_date_filter);
        items_with_x_percent := 0.00;
        items_without_x_percent := 0.00;
        IF items_total > 0 THEN
            items_with_x_percent := (items_with_x*1.00)/(items_total*1.00);
            items_without_x_percent := (items_without_x*1.00)/(items_total*1.00);
        END IF;
        temp := type_A(
            TO_CHAR(CURRENT_DATE,'MM/dd/yyyy HH:MI:ss AM'),
            start_date_str,
            end_date_str,
            items_total,
            items_with_x,
            items_without_x,
            items_with_x_percent,
            items_without_x_percent
        PIPE ROW(temp);
        RETURN;
    END;</em>
    I've changed some of the details here from the original so there may be some syntax errors but hopefully you get the gist of the situation.
    any help would be appreciated.
    Thanks

    activereports is a report generator for .net
    as for why it's written the way it is, I have no idea. Like I said, I didn't write it, I'm only trying to get it to work. There is far too much of it (and I'm far under-skilled) to go back and re-write everything the way it should be.
    this function is pretty simple, it takes a start & end date as a string as parameters to the function. it converts those to timestamps and query's an existing table with data for the number of times condition X is true or false with in that date range. This is what the report being generated reports on.
    This one was short and simple which is why I posted it. Others are far more complex and do loop, but for the sake of simplicity I posted this one. I get the same error with all the rest and I figure if I can get one working, the rest probably suffer from the same issue so fixing the rest should be fairly straight forward.
    as for priv's the user is granted all priv's (that are available when you create a new user in 10g XE's web admin interface), and it won't let me grant/remove priv's from the visual studio addin for myself.

  • Process Flow Parameter Binding.

    The docs on using process flow parameters are a bit sparse, so I wonder if anyone else has some input.
    We kick off our ETL processes by an external enterprise scheduling tool due to several remote dependencies. This tool provides us with an audit id that we want to tag all of our current rows loaded with. Now, creating input parameters on the mappings is easy, but the docs seem to indicate that a parameter passed into a process flow can only be bound to one location. Given that our process includes a few hundred mappings, this would require the input parameter be input several hunderd times with each instance bound to a single mapping. That is not a maintainable option. Similarly, any documentation on passing OUT parameters from mappings to subsequent mappings seems entirely absent, so I'm not sure if I can "daisy chain" passing this parameter along.
    Which, at this point, leaves me with passing in the variable to the process flow, having the first step be a SQL call that saves this ID to a table, and then having each mapping query this table for the audit ID in a pre-mapping procedure to use to tag the rows. The Process Flow will also have to have a closing SQL script to clear the audit id out of the table.
    Is this my best option? Or does anyone have a better idea?
    Thanks,
    Mike

    In 9.2, parameters were added by way of the property sheet for the Start activity.
    In 10.2 what you do is, in the Explorer portion (the top section) of the palette you select the "Start" activity. If you then look at the top bar of the Explorer portion of the palette you will note that the leftmost icon (a green plus sign over a folder) is enabled. This is the Create button which, when pressed, will create an input parameter to the process flow. This paramter may then be used as a bind variable by other activities in the process flow.
    Cheers,
    Mike

  • PreparedStatement parameter binding

    Hello,
    I am new to JDBC and java technology. I have experience with SQL, PL/SQL and I am quite shocked, that binding parameters using PreparedStatement class is based on parameter index instead of the parameter name.
    It is quite common in PL/SQL to use paramter name to bind a value to it.
    E.g. if I use query "select * from foo where id = :id and name = :name" I can bind parameters using dbms_sql.bind_variable(query, "id", 5) dbms_sql.bind_variable(query, "name", "london").
    However, in java I jave to bind using parameter index e.g query.setInt(1, 5), query.setString(2, new String("london")). Now the problems are
    - what if the sql programmer changes code "select * from foo where id = ? and name = ?" to "select * from foo where name = ? and id = ?"
    - think of a quite more complicated query, e.g. query with size of few kB - there can be a parameter repeated many times (id, date range etc) so I need to bind this parameter many times, instead of simple one bind by name
    - think of a dynamicaly generated query, where it is seriously complicated to follow the parameter indexes (sql block repeating, dynamicaly generated where clausules etc) and again binding by name is much more easier than indexed binding
    So my question is: Do you know of any class that supports binding by name ? Is there any workaround how to solve above mentioned issues ?
    And finally, what is the reason to use parameters by index instead of naming, which is I belive more obvious in database programming ?
    I am looking forward to your answers.
    Kindest regards,
    Kamil Poturnaj
    Mgr. Kamil Poturnaj, MicroStep-MIS
    Ilkovicova 3, 841 04 Bratislava, Slovakia

    - what if the sql programmer changes code "select *
    from foo where id = ? and name = ?" to "select * from
    foo where name = ? and id = ?"Tell him "please stop doing that" :-)
    He could also add a third parameter, "address = ?" which would also break it (even if the "?" were spelled ":address").
    The SQL statement and the code that binds / extracts values need to be modified in sync.
    - think of a quite more complicated query, e.g. query
    with size of few kB - there can be a parameter
    repeated many times (id, date range etc) so I need to
    bind this parameter many times, instead of simple one
    bind by nameThough I'm no great fan of vendor-specific 70-style languages, I'd recommend writing a PL/SQL procedure if a query gets very big.
    So my question is: Do you know of any class that
    supports binding by name ? Is there any workaround how
    to solve above mentioned issues ?I don't know of such a package; anyone...?
    It should be a nice programming exercise to write one. Something like:
        BindStatement stmt = new BindStatement("select a, :id from foo where id = :id and name = :name");
        stmt.set("name", "John");
        stmt.set("id", 1234);BindStatement would need to locate each occurrence of ":X" and create an SQL string with them replaced with "?"s. It would also need to store the positions where each ":X" occurred, so that when set("id",...) is called, it could do set(1,...); set(2,...); for the underlying statement.
    Occurrences of ":X" within strings need to be considered; the easy way is to replace there too.
    Unless I'm missing some gotcha, shouldn't take more than a couple of hours to write.
    And finally, what is the reason to use parameters by
    index instead of naming, which is I belive more
    obvious in database programming ?I can only speak from my experience: sql statements within Java code tend to be simple, and the "?" syntax is quite adequate there. Complex statements, if needed, are hidden in PL/SQL. Large systems use beans and automatically generated sql glue. This seems to be rarely a problem.

  • Parameter Binding By Name

    How do I bind parameter by name instead of by position? The only relevant property I found was OracleCommand.BindByName, which doesn't seem to work as expected. Another propert OracleParameter.BindByPos is in the documentation but not seem to be in the assembly.
    Thanks
    Bob
    Here is the code snippet for test -
              static void Main(string[] args) {
                   OracleConnection conn3 = new OracleConnection
                        ("user id=daf; password=daf; Data Source=mbobn;");
                   try {
                        conn3.Open();
                        OracleCommand cmd3 = new OracleCommand (
    @"create or replace procedure bind_by_name (p_param_1 varchar2, p_param_2 out number) as begin p_param_2 := to_number(p_param_1); end;", conn3);
                        cmd3.ExecuteNonQuery();
                        cmd3.CommandText = "bind_by_name";
                        cmd3.CommandType = CommandType.StoredProcedure;
                        cmd3.BindByName = true;
                        OracleParameter parm;
                        parm = new OracleParameter
                             ("p_param_1", OracleDbType.Varchar2, 20);
                        parm.Direction = ParameterDirection.Input;
                        parm.Value = Convert.ToInt32(args[0]);
                        cmd3.Parameters.Add (parm);
                        parm = new OracleParameter
                             ("p_param_2", OracleDbType.Int32);
                        parm.Direction = ParameterDirection.Output;
                        cmd3.Parameters.Add (parm);
                        OracleDataAdapter da = new OracleDataAdapter(cmd3);
                        cmd3.BindByName = true;
                        DataSet ds = new DataSet();
                        da.Fill (ds, "tst");
                        conn3.Close();
                        Console.WriteLine (ds.GetXml());
                        Console.WriteLine ("p_param_1=" + cmd3.Parameters["p_param_1"].Value.ToString());
                        Console.WriteLine ("p_param_2=" + cmd3.Parameters["p_param_2"].Value.ToString());
                   } catch (Exception e) { Console.WriteLine ("Failed to " + e.Message); }
                   finally { if (conn3.State == ConnectionState.Open) conn3.Close(); }

    Prefixing a colon(:) led to the following exception -
    Unhandled Exception: Oracle.DataAccess.Client.OracleException ORA-01036: illegal
    variable name/number at Oracle.DataAccess.Client.OracleException.HandleError
    Helper(Int32 errCode, OracleConnection conn, IntPtr opsErrCtx, IntPtr opsSqlCtx,
    Object src, String procedure, String[] args)
    at Oracle.DataAccess.Client.OracleException.HandleError(Int32 errCode, Oracle
    Connection conn, String procedure, IntPtr opsErrCtx, IntPtr opsSqlCtx, Object sr
    c, String[] args)
    at Oracle.DataAccess.Client.OracleCommand.ExecuteReader(Boolean requery, Bool
    ean fillRequest, CommandBehavior behavior)
    at Oracle.DataAccess.Client.OracleDataAdapter.Fill(DataSet dataSet, Int32 sta
    rtRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior
    behavior)
    at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, String srcTable)
    at ConsoleApplication1.ParamBindByName.Main(String[] args) in c:\_dev\btst\da
    taprovidertest\consoleapp\parambindbyname.cs:line 39

  • Parameter Binding for BLOB field

    I would like to find out how I can bind a BLOB field as one of the parameters to an INSERT statement to be passed to an ExecuteSQL call?
    I was trying to use the Add function for BLOB field of the OParameterCollection object, but was having problem instantiating the BLOB object itself - getting object not opened error!?!
    Would appreciate any advice!
    Thanks,
    John.

    Hi Karuna,
    Breakpoint's answer is a bit misleading - there's no need for the parameter ID to appear in SE11. All you need is logic on your screen to utilize the parameter ID. You have two options for that: Either use the field settings in the screen painter (i.e. check the SET field and GET field checkboxes, at least Get field would be required - just seeing the parameter ID is not sufficient) or add some coding to your PBO coding to retrieve upon startup of the screen the value via GET PARAMETER statement (requiring also possibly a SET PARAMETER in the PAI for the field if you want to set it).
    Most likely the first approach is what you want. The second is more flexible, but also needs more care to avoid unexpected behavior...
    Cheers, harald

Maybe you are looking for